我正在尝试在我的服务器上使用 PHP 实现 PayPal IPN。我在 GitHub 上找到了来自 Paypal 的代码.我的理解是,我将 PaypalIPN.php
和我的 example_usage.php
版本放在服务器上,并指定我的 example_usage.php
版本的 url到 Paypal 。
example_usage.php 看起来像这样:
<?php require('PaypalIPN.php');
use PaypalIPN;
$ipn = new PayPalIPN();
// Use the sandbox endpoint during testing.
$ipn->useSandbox();
$verified = $ipn->verifyIPN();
if ($verified) {
/*
* Process IPN
* A list of variables is available here:
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
*/
***** This is where I should get the value of custom and store it in DB or whatever *****
** getPOSTdata() used here **
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");
我将通过以下方式将自定义变量发送到 paypal:
<a id="a-submit" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&custom=customdata&hosted_button_id=someID">Pay with PayPal</a>
Paypal 应该在自定义变量下返回它。我怎样才能访问它?小子问题。真的是这样吗?它看起来非常简单,我担心我遗漏了什么。
编辑:我使用以下函数编辑了 PaypalIPN.php
:
private $postData = "";
public function getPOSTdata(){
return $postData;
}
**IN verifyIPN()**
$raw_post_data = file_get_contents('php://input');
$postData=$raw_post_data;
我是这样使用的:
$lastname = $ipn->getPOSTdata();
我面临的问题是 $lastname
是一个空字符串。这不可能是真的,因为我知道 Paypal 一定给我寄了东西。我做错了什么?
最佳答案
您需要添加一个方法来访问 PaypalPN.php 中的 $myPost 数组
PaypalIPN.php 第 6 - 8 行
private $use_sandbox = false;
private $use_local_certs = true;
更改为以下内容:
private $use_sandbox = false;
public $pubMyPost;
private $use_local_certs = true;
再往下...
PaypalIPN.php 第 75 - 79 行:
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
}
// Build the body of the verification post request, adding the _notify-validate command.
更改为:
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
}
this.pubMyPost = $myPost; // set the public var
// Build the body of the verification post request, adding the _notify-validate command.
然后在 example_usage.php 里面
$ipn->useSandbox();
$verified = $ipn->verifyIPN();
if ($verified) {
// Now you can access all the public var containing your key=value pairs from the post.
$myPost = $ipn->pubMyPost;
}
关于php - 使用 PayPal 即时付款通知时使用 PHP 获取自定义变量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40490222/