如果 PayPal IPN 返回已验证,如何添加视频

我第一次尝试使用 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 看起来像这样:


<?php


class 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");

    }



手掌心
浏览 70回答 1
1回答

桃花长相依

您所做的事情误解了 IPN 的工作方式。IPN 是从 PayPal 直接发送到您的服务器,不会、不能也不应该以任何方式直接涉及客户的网络浏览器或感谢页面。您的 IPN 侦听器应更新您的数据库以将订单标记为已付款。您的感谢页面可以从数据库中读取。这些是异步操作。
打开App,查看更多内容
随时随地看视频慕课网APP