为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
手掌心 2023-07-01 15:23:08
我第一次尝试使用 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 侦听器应更新您的数据库以将订单标记为已付款。

您的感谢页面可以从数据库中读取。

这些是异步操作。

查看完整回答
反对 回复 2023-07-01
  • 1 回答
  • 0 关注
  • 68 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信