2010-04-11 10 views
1

這是一個關於Paypal Mass Pay IPN的問題。我的平臺是PHP & mySQL需要使用PayPal Mass Pay API通過IPN捕獲並存儲接收者的詳細信息

在Paypal的支持網站上,我發現IPN僅用於付款。我需要一個類似的公共支付的IPN,但無法找到它。還嘗試嘗試使用現有的Mass Pay NVP代碼,但這也不起作用。

我想要做的是,對於所有收款人已通過大衆支付成功發送付款,我想記錄他們的電子郵件,金額和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' => "[email protected]", 
          '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)); 
} 

?> 

在上面的代碼,如何和我在哪裏添加代碼,以捕捉上面我所要求的領域?任何代碼表明解決方案是高度讚賞。

非常感謝。

回答

0

我比較熟悉,經常性付款,但我認爲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

+0

@Christopher:謝謝你的迴應。我嘗試了你的代碼,但是當我檢查我的數據庫表中的值時,我看到:receiver_email_1作爲電子郵件響應。關於如何檢索相同值的任何想法? – Devner 2010-04-11 10:42:38

0

通常有兩種方式來獲得這些數據的價值,一個是看從呼叫您對直接masspay的反應,另一個是爲您的賬戶設置IPN。

你不得不安裝全球IPN,我不能找到一種方法,在IPN發送聽網址作爲此調用的變量。

HTH -FT

相關問題