我正在尝试使用PayPal API退款。 但我得到以下错误。
public function paypal_refund() {
// Set request-specific fields.
$transactionID = urlencode('2MH09332752606614');
$refundType = urlencode('Full'); // or 'Partial'
$amount; // required if Partial.
$memo; // required if Partial.
$currencyID = urlencode('USD'); // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
// Add request-specific fields to the request string.
$nvpStr = "&TRANSACTIONID=$transactionID&REFUNDTYPE=$refundType&CURRENCYCODE=$currencyID";
if (isset($memo)) {
$nvpStr .= "&NOTE=$memo";
}
if (strcasecmp($refundType, 'Partial') == 0) {
if (!isset($amount)) {
exit('Partial Refund Amount is not specified.');
} else {
$nvpStr = $nvpStr . "&AMT=$amount";
}
if (!isset($memo)) {
exit('Partial Refund Memo is not specified.');
}
}
// Execute the API operation; see the PPHttpPost function above.
$env = 'sandbox';
$httpParsedResponseAr = $this->PPHttpPost('RefundTransaction', $nvpStr);
pr($httpParsedResponseAr);
if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
exit('Refund Completed Successfully: ' . print_r($httpParsedResponseAr, true));
} else {
exit('RefundTransaction failed: ' . print_r($httpParsedResponseAr, true));
}
}
/**
* 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
*/
public function PPHttpPost($methodName_, $nvpStr_) {
// Set up your API credentials, PayPal end point, and API version.
$API_UserName = urlencode('myusername');
$API_Password = urlencode('mypassword');
$API_Signature = urlencode('mysignature');
$API_Endpoint = "https://api-3t.paypal.com/nvp";
$environment = 'sandbox';
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;
}
错误:
Array
(
[TIMESTAMP] => 2015%2d10%2d29T10%3a18%3a16Z
[CORRELATIONID] => e2b916cdb99d6
[ACK] => Failure
[VERSION] => 51%2e0
[BUILD] => 18308778
[L_ERRORCODE0] => 10004
[L_SHORTMESSAGE0] => Transaction%20refused%20because%20of%20an%20invalid%20argument%2e%20See%20additional%20error%20messages%20for%20details%2e
[L_LONGMESSAGE0] => The%20transaction%20id%20is%20not%20valid
[L_SEVERITYCODE0] => Error
)
RefundTransaction failed: Array ( [TIMESTAMP] => 2015%2d10%2d29T10%3a18%3a16Z [CORRELATIONID] => e2b916cdb99d6 [ACK] => Failure [VERSION] => 51%2e0 [BUILD] => 18308778 [L_ERRORCODE0] => 10004 [L_SHORTMESSAGE0] => Transaction%20refused%20because%20of%20an%20invalid%20argument%2e%20See%20additional%20error%20messages%20for%20details%2e [L_LONGMESSAGE0] => The%20transaction%20id%20is%20not%20valid [L_SEVERITYCODE0] => Error )
答案 0 :(得分:0)
2MH09332752606614不是PayPal交易ID。请参阅帐户历史记录页面中的https://en.support.wordpress.com/paypal-transaction-id/,登录sandbox.paypal.com以获取有效的交易ID。