我第一次嘗試使用 PayPal IPN,但我很難讓它端到端地工作。如果 IPN 響應(yīng)得到驗(yàn)證,感謝頁面應(yīng)顯示視頻。如果未經(jīng)過驗(yàn)證(例如,如果有人嘗試直接進(jìn)入感謝頁面,而不是通過成功的 PayPal 交易),則應(yīng)顯示一條錯(cuò)誤消息。在檢查 PayPal 時(shí),我已設(shè)法在 IPN 歷史記錄中返回“已發(fā)送”狀態(tài),但我的感謝頁面(包含 IPN 驗(yàn)證器)顯示錯(cuò)誤 500。錯(cuò)誤日志表明沒有發(fā)布數(shù)據(jù)發(fā)送到該頁面,盡管 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貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
您所做的事情誤解了 IPN 的工作方式。
IPN 是從 PayPal 直接發(fā)送到您的服務(wù)器,不會、不能也不應(yīng)該以任何方式直接涉及客戶的網(wǎng)絡(luò)瀏覽器或感謝頁面。
您的 IPN 偵聽器應(yīng)更新您的數(shù)據(jù)庫以將訂單標(biāo)記為已付款。
您的感謝頁面可以從數(shù)據(jù)庫中讀取。
這些是異步操作。
- 1 回答
- 0 關(guān)注
- 123 瀏覽
添加回答
舉報(bào)
0/150
提交
取消