나는 지난 5 시간 동안이 물건에 대한 정보를 검색해 왔으며 작동하지 않는 많은 것을 발견했다. 성공적으로 setExpressCheckout API를 사용하여 세부 정보를 얻고 정상적인 주문을 청구 할 수 있었지만 반복 결제 프로필을 만들려면 항상 잘못된 토큰 오류가 발생합니다. 나는 그것이 틀린 토큰이 아니라는 것을 안다. 그러나 나는 무엇을 해야할지 모른다.PayPal API CreateRecurringPaymentsProfile 작동하지 않음
저는 현재 setExpressCheckout 및 createRecurringPaymentsProfile에 대해 PayPal의 샘플 코드를 사용하고 있습니다.
PayPal의 코드가 매우 간단합니다.
<?
$environment = 'sandbox'; // or 'beta-sandbox' or 'live'
$ROOT_URL = 'http://example.com/paypal/';
/**
* 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;
$API_UserName = urlencode('email');
$API_Password = urlencode('pass');
$API_Signature = urlencode('sig');
$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');
// setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// turning 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);
// NVPRequest for submitting to server
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// setting the nvpreq as POST FIELD to curl
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// getting response from server
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the RefundTransaction 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;
}
$paymentAmount = urlencode(34.00);
if(!isset($_REQUEST['token'])){
// Set request-specific fields.
$currencyID = urlencode('USD'); // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
$paymentType = urlencode('Authorization'); // or 'Sale' or 'Order'
$returnURL = urlencode($ROOT_URL.'/buy.php?return=1');
$cancelURL = urlencode($ROOT_URL.'/buy.php?cancel=1');
// Add request-specific fields to the request string.
$nvpStr = "&Amt=$paymentAmount&ReturnUrl=$returnURL&CANCELURL=$cancelURL&PAYMENTACTION=$paymentType&CURRENCYCODE=$currencyID";
// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('SetExpressCheckout', $nvpStr);
print_r($httpParsedResponseAr);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
// Redirect to paypal.com.
$token = urldecode($httpParsedResponseAr["TOKEN"]);
$payPalURL = "https://www.paypal.com/webscr&cmd=_express-checkout&token=$token";
if("sandbox" === $environment || "beta-sandbox" === $environment) {
$payPalURL = "https://www.$environment.paypal.com/webscr&cmd=_express-checkout&token=$token";
}
//header("Location: $payPalURL");
echo '<a href="'.$payPalURL.'">PayPal</a>';
exit;
} else {
exit('SetExpressCheckout failed: ' . print_r($httpParsedResponseAr, true));
}
}else{
$token = urlencode($_REQUEST['token']);
//Now create recurring profile
?>
<h1>Yes!</h1>
<?
$currencyID = urlencode("USD"); // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
$startDate = urlencode("2012-9-6T0:0:0");
$billingPeriod = urlencode("Month"); // or "Day", "Week", "SemiMonth", "Year"
$billingFreq = urlencode("4"); // combination of this and billingPeriod must be at most a year
$nvpStr="&TOKEN=$token&AMT=$paymentAmount&CURRENCYCODE=$currencyID&PROFILESTARTDATE=$startDate";
$nvpStr .= "&BILLINGPERIOD=$billingPeriod&BILLINGFREQUENCY=$billingFreq";
$httpParsedResponseAr = PPHttpPost('CreateRecurringPaymentsProfile', $nvpStr);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
exit('CreateRecurringPaymentsProfile Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else {
exit('CreateRecurringPaymentsProfile failed: ' . print_r($httpParsedResponseAr, true));
}
}
?>
분명히 이메일, 패스 및 시그널이 잘못되었습니다. 내 스크립트의 이름은 example.com/paypal/buy.php입니다. 명확하지 않은 경우 ...
업데이트 : 마침내 나는 뭔가를 발견했습니다. 나는 아직 코드를 작성하지 못했지만, 적어도 완료되었습니다. https://www.x.com/developers/paypal/forums/nvp/createrecurringpaymentsprofile-invalid-token-0
내가 추가하고자하는 한 가지 : GetExpressCheckoutDetails 이전에 사용자를 https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token= 또는 https://www.paypal.com/cgi-http : //www.sandbox.paypal.com/webscr?cmd=_express-checkout&token= 페이지로 리디렉션해야합니다. bin/webscr? cmd = _express-checkout & token = 그가 agrrement를 받아들이도록하십시오. – Oleg