【问题标题】:Need to capture and store receiver's details via IPN by using Paypal Mass Pay API需要使用 Paypal Mass Pay API 通过 IPN 捕获和存储收款人的详细信息
【发布时间】:2011-02-06 14:55:31
【问题描述】:

这是一个关于 Paypal Mass Pay IPN 的问题。我的平台是PHP & mySQL

在整个 Paypal 支持网站上,我都找到了仅用于付款的 IPN。我需要一个类似线路的 IPN 用于 Mass Pay,但找不到。还尝试使用现有的 Mass Pay NVP 代码进行试验,但这也不起作用。

我想要做的是,对于通过 Mass Pay 成功发送付款的所有收件人,我想在我自己的数据库表中记录他们的电子邮件、金额和 unique_id。如果可能的话,我也想捕获付款状态,无论是成功还是失败,在此基础上,我都需要做一些内部处理。

现有代码批量支付代码如下:

<?php

$environment = 'sandbox';   // or 'beta-sandbox' or 'live'

/**
 * Send HTTP POST Request
 *
 * @param   string  The API method name
 * @param   string  The POST Message fields in &name=value pair format
 * @return  array   Parsed HTTP Response body
 */
function PPHttpPost($methodName_, $nvpStr_) {
    global $environment;

    // Set up your API credentials, PayPal end point, and API version.
    $API_UserName = urlencode('my_api_username');
    $API_Password = urlencode('my_api_password');
    $API_Signature = urlencode('my_api_signature');

    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {
        $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
    }
    $version = urlencode('51.0');

    // Set the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    // Turn off the server and peer verification (TrustManager Concept).
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);

    // Set the API operation, version, and API signature in the request.
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

    // Set the request as a POST FIELD for curl.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    // Get response from the server.
    $httpResponse = curl_exec($ch);

    if(!$httpResponse) {
        exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
    }

    // Extract the response details.
    $httpResponseAr = explode("&", $httpResponse);

    $httpParsedResponseAr = array();
    foreach ($httpResponseAr as $i => $value) {
        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {
            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
        }
    }

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
    }

    return $httpParsedResponseAr;
}

// Set request-specific fields.
$emailSubject =urlencode('example_email_subject');
$receiverType = urlencode('EmailAddress');
$currency = urlencode('USD');                           // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// Add request-specific fields to the request string.
$nvpStr="&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency";

$receiversArray = array();

for($i = 0; $i < 3; $i++) {
    $receiverData = array(  'receiverEmail' => "user$i@paypal.com",
                            'amount' => "example_amount",
                            'uniqueID' => "example_unique_id",
                            'note' => "example_note");
    $receiversArray[$i] = $receiverData;
}

foreach($receiversArray as $i => $receiverData) {
    $receiverEmail = urlencode($receiverData['receiverEmail']);
    $amount = urlencode($receiverData['amount']);
    $uniqueID = urlencode($receiverData['uniqueID']);
    $note = urlencode($receiverData['note']);
    $nvpStr .= "&L_EMAIL$i=$receiverEmail&L_Amt$i=$amount&L_UNIQUEID$i=$uniqueID&L_NOTE$i=$note";
}

// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('MassPay', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    exit('MassPay Completed Successfully: '.print_r($httpParsedResponseAr, true));


} else  {
    exit('MassPay failed: ' . print_r($httpParsedResponseAr, true));
}

?>

在上面的代码中,我如何以及在哪里添加代码来捕获我上面请求的字段?任何指示解决方案的代码都非常感谢。

非常感谢。

【问题讨论】:

    标签: php mysql paypal paypal-nvp


    【解决方案1】:

    我更熟悉定期付款,但我认为 IPN 响应会发回您正在寻找的价值。只需将它们从发回的数组中捕获,将它们放入一些变量中,然后保存到数据库中。

    $email   = $httpParsedResponseAr["receiver_email"];  
    $amount  = $httpParsedResponseAr["mc_currency_x"];
    

    这里是批量支付变量的值
    https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables

    【讨论】:

    • @Christopher:感谢您的回复。我尝试了您的代码,但是当我检查数据库表的值时,我看到:receiver_email_1 作为电子邮件回复。关于如何检索相同值的任何想法?
    【解决方案2】:

    获取这些数据一般有两种方式,一种是直接查看你拨打masspay的电话的回复,另一种是为你的账户设置IPN。

    您必须设置全局 IPN,我找不到将 IPN 侦听 URL 作为此调用中的变量发送的方法。

    HTH -FT

    【讨论】:

      猜你喜欢
      • 2013-11-04
      • 2014-12-08
      • 2023-04-06
      • 2015-07-22
      • 2021-09-08
      • 2014-07-03
      • 2020-10-16
      • 2019-12-15
      • 2015-02-27
      相关资源
      最近更新 更多