使用ipn url自适应链式支付附加信息

时间:2014-10-14 19:17:45

标签: php paypal paypal-ipn payment paypal-adaptive-payments

我已经阅读了几篇关于IPN和链式支付的帖子,我很难理解它,因为这对我来说都是新的。但我的情况很简单,这就是我想要实现的目标。

买方支付卖方(卖方)卖方向我支付佣金。这一切都有效。但我需要验证后端工作。

我用变量

指定我的ipn监听器
$ipnurl = "http://example.com/ipnlistener.php?adid=$adid

因为adid是我后端所有内容的关键。

在我的API中,我使用NVP并定义这样的调用。请记住,除了IPN之外,它都有效。

$request_parameters = array (
   "actionType" => "PAY",
   "ipnNotificationUrl" => "$ipnurl",
   "clientDetails.applicationID" => "$ppappid",
   "clientDetails.ipAddress" => "127.0.0.1",
   "feesPayer" => "PRIMARYRECEIVER",
   "memo" => "$adtitle",
   "receiverList.receiver(0).amount" => "$r1amount",
   "receiverList.receiver(0).email" => "$r1email",
   "receiverList.receiver(0).primary" => "true",
   "receiverList.receiver(1).amount" => "$r2amount",
   "receiverList.receiver(1).email" => "$r2email",
   "receiverList.receiver(1).primary" => "false",
   "requestEnvelope.errorLanguage" => "en_US",
   "requestEnvelope.detailLevel" => "ReturnAll",
   "currencyCode" => "USD",
   "returnUrl" => $adpage,
   "cancelUrl" => $adpage
);

出于简单的测试目的,我将以下内容作为我的ipnlistener的一部分,以便我可以看到它的内容。

foreach ($_POST as $key => $value)  {
        if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1){
                $value = urlencode(stripslashes($value));
        } else {
                $value = urlencode($value);
        }
        $req .= "&$key=$value";
}

$result = print_r($_POST, true);
file_put_contents('/tmp/ipnlistener.txt', $result);

使用上面的scnario,日志文件包含以下内容:

Array
(
    [transaction] => Array
        (
            [0] => NONE
            [1] => Completed
        )

    [log_default_shipping_address_in_transaction] => false
    [action_type] => PAY
    [ipn_notification_url] => http://www.example.com/ipnlistener.php
    [charset] => windows-1252
    [transaction_type] => Adaptive Payment PAY
    [notify_version] => UNVERSIONED
    [cancel_url] => http://www.example.com/showad.php?adid=20
    [verify_sign] => ********
    [sender_email] => ******
    [fees_payer] => PRIMARYRECEIVER
    [return_url] => http://www.example.com/showad.php?adid=20
    [memo] => Leica M Lens CLOSE UP to Sony NEX
    [reverse_all_parallel_payments_on_error] => false
    [pay_key] => *******
    [status] => COMPLETED
    [payment_request_date] => Tue Oct 14 11:10:18 PDT 2014
)

正如您所看到的,它看起来像是一个特定于应用的IPN。我需要真实的数据来完成交易。

如果我在网站上删除ipnurl并重新调整ipn通知,我会得到我的期望但是我没有那么急需的adid。

看起来像这样

Array
(
    [transaction_subject] =>
    [payment_date] => 07:40:38 Oct 14, 2014 PDT
    [txn_type] => web_accept
    [last_name] => ***
    [residence_country] => US
    [item_name] =>
    [payment_gross] => 0.03
    [mc_currency] => USD
    [business] => ***
    [payment_type] => instant
    [protection_eligibility] => Ineligible
    [verify_sign] => ***
    [payer_status] => unverified
    [tax] => 0.00
    [payer_email] => ***
    [txn_id] => ***
    [quantity] => 0
    [receiver_email] => ***
    [first_name] => Jorge
    [payer_id] => ***
    [receiver_id] => ***
    [memo] => Leica M Lens CLOSE UP to Sony NEX
    [item_number] =>
    [payer_business_name] => ZeissImages
    [payment_status] => Completed
    [payment_fee] => 0.03
    [mc_fee] => 0.03
    [mc_gross] => 0.03
    [custom] =>
    [charset] => windows-1252
    [notify_version] => 3.8
    [ipn_track_id] => ***
)

问题是如何使用我添加的cutom参数获取事务IPN?

由于

1 个答案:

答案 0 :(得分:0)

在本地数据库中保存一条记录,其中包含您需要的数据以及您正在进行的事务的PayKey。然后,当应用程序特定的IPN命中时,您可以使用该PayKey将数据从数据库中拉回来。