我为Wordpress开发了一个功能丰富的购物车插件(是另一个,但我的后端有完整功能的簿记,与前面的PayPal付款标准集成; - )> 我应该在此前言 - 以免任何人推断我要求他们帮助赚取薪水 - 我的目标是看到它 - 我的宝贝 - 社区自由发展可用并广泛接受;一份不起眼的礼物给99%(或47%取决于你的观点 ;-)。我打算在年底前把它放在gitHub上,但是在过渡期间,我正在努力进行最后一点PayPal集成。我需要一点帮助。
我已阅读here和there,可以将 PayPal refundTransaction API 与付款标准帐户结合使用。推断出API访问需要使用Business帐户时,我已使用Payments Standard为沙盒中的Business帐户建立了API凭据,但似乎无法让它在我的开发服务器上运行。
我对API的体验一般是有限的,与php CUL大致相同,但我把问题缩小到(至少)三件事之一:
如果不可能...... (或没有SSL CERT 那么可能),谢谢让我沉溺于此 - < em>代表那些可能在以后找到这种话语的人 - 花一点时间消除它的神话。
否则......代码......我的最大努力只会返回以下错误;
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
和违规代码(源自示例代码here)
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 :(得分:2)
最后!我知道了。找到了答案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