php - 使用 PayPal 即时付款通知时使用 PHP 获取自定义变量的值

标签 php paypal

我正在尝试在我的服务器上使用 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/

相关文章:

通过静默 url 进行的 Paypal 定期订阅给出无效响应?

php - 我有一个 iframe,我需要 Google 对其内容进行索引。这可能吗?

php - 几乎两个相同的代码但只有一个输出

php - SimpleXML 使用 xpath 获取元素内容

java - 使用 JAVA (libGdx) 的 HttpRequest 并使用 PHP 进行处理

javascript - 代码点火器 : how to convert Database results into JSON

paypal - 从 developer.sandbox.com 模拟 recurring_payment_skipped 的 IPN

paypal - 支付网关 |本地资金转账至银行

php - 带联系表 7 的 Paypal

node.js - 返回 url 不适用于 PayPal 和 NodeJS