我第一次嘗試使用 PayPal IPN,但我很難讓它端到端地工作。如果 IPN 響應得到驗證,感謝頁面應顯示視頻。如果未經過驗證(例如,如果有人嘗試直接進入感謝頁面,而不是通過成功的 PayPal 交易),則應顯示一條錯誤消息。在檢查 PayPal 時,我已設法在 IPN 歷史記錄中返回“已發送”狀態,但我的感謝頁面(包含 IPN 驗證器)顯示錯誤 500。錯誤日志表明沒有發布數據發送到該頁面,盡管 PayPal 正在注冊,但它還是成功的。<?php namespace Listener;require('PaypalIPN.php');use PaypalIPN;$ipn = new PaypalIPN();$ipn->useSandbox();$verified = $ipn->verifyIPN();if ($verified) { echo ("My video will go here");}header("HTTP/1.1 200 OK"); ?>PaypalIPN.php 看起來像這樣:<?phpclass PaypalIPN{/** @var bool Indicates if the sandbox endpoint is used. */private $use_sandbox = false;/** @var bool Indicates if the local certificates are used. */private $use_local_certs = true;/** Production Postback URL */const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';/** Sandbox Postback URL */const SANDBOX_VERIFY_URI = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';/** Response from PayPal indicating validation was successful */const VALID = 'VERIFIED';/** Response from PayPal indicating validation failed */const INVALID = 'INVALID';/** * Sets the IPN verification to sandbox mode (for use when testing, * should not be enabled in production). * @return void */public function useSandbox(){ $this->use_sandbox = true;}/** * Sets curl to use php curl's built in certs (may be required in some * environments). * @return void */public function usePHPCerts(){ $this->use_local_certs = false;}/** * Determine endpoint to post the verification data to. * * @return string */public function getPaypalUri(){ if ($this->use_sandbox) { return self::SANDBOX_VERIFY_URI; } else { return self::VERIFY_URI; }}/** * Verification Function * Sends the incoming post data back to PayPal using the cURL library. * * @return bool * @throws Exception */public function verifyIPN(){ if ( ! count($_POST)) { throw new Exception("Missing POST Data"); }
1 回答

桃花長相依
TA貢獻1860條經驗 獲得超8個贊
您所做的事情誤解了 IPN 的工作方式。
IPN 是從 PayPal 直接發送到您的服務器,不會、不能也不應該以任何方式直接涉及客戶的網絡瀏覽器或感謝頁面。
您的 IPN 偵聽器應更新您的數據庫以將訂單標記為已付款。
您的感謝頁面可以從數據庫中讀取。
這些是異步操作。
- 1 回答
- 0 關注
- 111 瀏覽
添加回答
舉報
0/150
提交
取消