2012-11-05 100 views
2

我已經開發了一個功能豐富的Wordpress購物車插件(是另一個,但我的後臺全功能簿記集成了前面的PayPal付款標準 ;-)
我應該在此序言 - 以免任何人推斷我要求他們幫助賺取工資 - 我的目標是看到它 - 我的寶貝 - 社區發達,免費提供並廣泛接受;向99%(或47%,取決於你的觀點 ;-)的謙卑禮物。我打算在年底之前將它放在gitHub上,但在此期間,我正在爲PayPal集成的最後一點掙扎。我需要一點幫助。PayPal refundTransfer API與支付標準的商業帳戶

我讀過herethere,其可以利用本貝寶refundTransaction API付款標準帳戶。在推斷API訪問需要商業帳戶後,我使用Payments Standard爲沙箱中的商戶帳戶建立了API憑證,但似乎無法讓它在我的開發服務器上運行。

我與一般的API的經驗固然有限,大約用PHP CUL一樣,但我已經將問題範圍縮小到(至少)的三兩件事之一:

  1. 有問題與我的代碼(根本不可能
  2. 的SSL證書是必需的(真的嗎?)或...
  3. 這是完全可能的!

如果無法...或不可能沒有一個SSL證書)好,謝謝的放縱我這個遠 - 代表那些誰以後可能會發現這種話語 - 花點時間消除它的神話。

否則...代碼...我的最大努力只返回以下錯誤;

Error: RefundTransaction failed: Array 
(
    [TIMESTAMP] => 2012/11/03 18:09:52 
    [CORRELATIONID] => 9718ec23550ae 
    [ACK] => Failure 
    [VERSION] => 51.0 
    [BUILD] => 4181146 
    [L_ERRORCODE0] => 10002 
    [L_SHORTMESSAGE0] => Security error 
    [L_LONGMESSAGE0] => Security header is not valid 
    [L_SEVERITYCODE0] => Error 
) 

給出的API請求字符串

METHOD=RefundTransaction&VERSION=51.0&PWD=my_pwd&USER=my_uname_biz_api1.domain.com&SIGNATURE=my_sig&PAYERID=3YK31605PA817942B&REFUNDTYPE=Full&CURRENCYCODE=USD&INVOICEID=1238rfd1246 

和違規代碼

function PPHttpPost($methodName_, $nvpStr_) 
{ global $store_options; 
    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp"; 
    foreach($store_options->ppl_sdbx_api as $cred =>$val) $$cred = urlencode($val); 
    if(isset($store_options->paypal_live) && $store_options->paypal_live ==='true') 
    { $API_Endpoint = "https://api-3t.paypal.com/nvp"; 
     foreach($store_options->paypal_api as $cred =>$val) $$cred = urlencode($val); 
    } 
    $version = urlencode('51.0'); 
    // Set the request. 
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$PWD&USER=$USER&SIGNATURE=$SIGNATURE$nvpStr_"; 
// die("Error: $nvpreq"); 
    // Set the curl parameters. 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    // Set the request as a POST FIELD for curl. 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); 
    // not in example script but present in working ipn.php 
     //curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length:" . strlen($nvpreq))); 
    // also not in example script but present in working ipn.php 
     //curl_setopt($ch, CURLOPT_HEADER , 0); 
    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); 
    // not in example script but present in working ipn.php 
     curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
    // Get response from the server. 
    $httpResponse = curl_exec($ch); 
    if(!$httpResponse) 
    { die("Error: $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)) { 
     die("Error: Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint."); 
    } 
    return $httpParsedResponseAr; 
} 
+0

這裏是通過PHP API包退的文章。 http://www.kvcodes.com/2016/05/paypal-refund-transaction/ – Kvvaradha

回答

2

最後(從樣本代碼here導出)!我知道了。找到答案here。 首先,是有可能,沒有SSL,因而不需要...... 原來我只是需要重新排序的API請求

USER=zzzzzz_api1.xxxxxx 
    PWD= xxxxxxxxxxxxxxxxxxxxxxx 
    SIGNATURE=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
    METHOD=RefundTransaction 
    VERSION=59.0 
    TRANSACTIONID=1234567890 
    PAYERID=1234567890 
    REFUNDTYPE=Partial 
    AMT=0.01 
相關問題