以下是我用于定期付款的代码。 但它提供错误消息无效令牌,即使我在$ _session中收到$令牌[' TOKEN'];
$nvpstr=@$nvpstr="&TOKEN=".urlencode($_SESSION['TOKEN']);
$nvpstr.="&EMAIL=".$email;
$nvpstr.="&PROFILESTARTDATE=".$StartDateGMT;
$nvpstr.="&DESC=".urlencode("Pay $".$_SESSION['Payment_Amount']);
$nvpstr.="&BILLINGPERIOD=Month";
$nvpstr.="&BILLINGFREQUENCY=1";
$nvpstr.="&AMT=".$_SESSION['Payment_Amount'];
$nvpstr.="&CURRENCYCODE=USD";
$nvpstr.="&IPADDRESS=" . $_SERVER['REMOTE_ADDR'];
function hash_call('CreateRecurringPaymentsProfile', $nvpStr)
{
//declaring of global variables
/*global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
global $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
global $gv_ApiErrorURL;
global $sBNCode;*/
$PROXY_HOST = '127.0.0.1';
$PROXY_PORT = '808';
$API_UserName = API_USERNAME;
$API_Password = API_PASSWORD;
$API_Signature = API_SIGNATURE;
$sBNCode = "PP-ECWizard";
if (PAYPAL_ENVIRONMENT=="sandbox") {
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
} else {
$API_Endpoint = "https://api-3t.paypal.com/nvp";
$PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
}
$USE_PROXY = false;
$version = "113";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
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);
if ($USE_PROXY)
curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST . ":" . $PROXY_PORT);
//NVPRequest for submitting to server
$nvpreq = "METHOD=".urlencode($methodName)."&VERSION=".urlencode($version)."&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName)."&SIGNATURE=".urlencode($API_Signature).$nvpStr."&BUTTONSOURCE=".urlencode($sBNCode);
//setting the nvpreq as POST FIELD to curl
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
//getting response from server
$response = curl_exec($ch);
//converting NVPResponse to an Associative Array
$nvpResArray = deformatNVP($response);
$nvpReqArray = deformatNVP($nvpreq);
$_SESSION['nvpReqArray'] = $nvpReqArray;
if (curl_errno($ch)) {
// moving to display page to display curl errors
$_SESSION['curl_error_no'] = curl_errno($ch);
$_SESSION['curl_error_msg'] = curl_error($ch);
//Execute the Error handling module to display errors.
} else {
//closing the curl
curl_close($ch);
}
return $nvpResArray;
}
非常感谢您的帮助。
function CallShortcutExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $package_name, $package_desc)
{
//------------------------------------------------------
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
$nvpstr = "&PAYMENTREQUEST_0_AMT=" . $paymentAmount;
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
$nvpstr = $nvpstr . "&BILLINGAGREEMENTDESCRIPTION=" . urlencode("Pay $". $paymentAmount);
$nvpstr = $nvpstr . "&BILLINGTYPE=RecurringPayments";
$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_AMT0=" . $paymentAmount;
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NAME0=" . $package_desc;
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_DESC0=" . $package_name;
$_SESSION["currencyCodeType"] = $currencyCodeType;
$_SESSION["PaymentType"] = $paymentType;
//'-------------------------------------------------------------------------------
//' Make the API call to PayPal
//' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
//' If an error occured, show the resulting errors
//'-------------------
$resArray = hash_call("SetExpressCheckout", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
$token = urldecode($resArray["TOKEN"]);
$_SESSION['TOKEN'] = $token;
}
return $resArray;
}
上面的代码现在工作正常,但我不知道在哪里提到notify_url。 所以我的IPN paypal无效。我启用了IPN表单。我必须提到notify_url,因为我们提到了cancel_url,returnurl。