![](/img/trans.png)
[英]PayPal: Express Checkout. Set up a one-time payment and recurring payment in single transaction
[英]Paypal Recurring Payment Transaction Error: 11502 : Token is invalid
我是paypal的新手,我需要為我的客戶實現訂閱(定期付款)。我正在使用paypal沙箱進行實施。 我遵循paypal堅持創建定期付款資料的方式。 從SetExpressCheckout,GetExpressCheckOut和DoExpressCheckOut獲得“成功”確認。 我嘗試使用DoExpressCheckOutpayment響應中的令牌創建循環付款配置文件,但來自CreateRecurrinpayment配置文件的響應返回失敗,說明了ivnalid中的toke。 我試着通過設置快速結賬請求設置“BILLINGAGREEMENTDESCRIPTION和BILLINGTYPE = RecurringPayments”,但同樣的錯誤仍然存在。
請在下面找到我用於實施定期存款的代碼。
SetEXpressCheckout
{
NameValueCollection values = new NameValueCollection();
values["METHOD"] = "SetExpressCheckout";
values["RETURNURL"] = PayPalSettings.ReturnUrl;
values["CANCELURL"] = PayPalSettings.CancelUrl;
values["PAYMENTACTION"] = "Sale";
values["CURRENCYCODE"] = "USD";
values["BUTTONSOURCE"] = "PP-ECWizard";
values["USER"] = PayPalSettings.Username;
values["PWD"] = PayPalSettings.Password;
values["SIGNATURE"] = PayPalSettings.Signature;
values["SUBJECT"] = "";
values["L_NAME0"] = "MyName";
values["L_AMT0"] = "20.00";
values["VERSION"] = "2.3";
values["AMT"] = PayPalSettings.OrderAmount;
values["L_BILLINGTYPE0"] = "RecurringPayments";
values["L_BILLINGAGREEMENTDESCRIPTION0"] = "Test subscription";
values = Submit(values);
string ack = values["ACK"].ToLower();
if (ack == "success" || ack == "successwithwarning")
{
return new PayPalRedirect
{
Token = values["TOKEN"],
Url = String.Format("https://{0}/cgi-bin/webscr?cmd=_express-checkout&token={1}",
PayPalSettings.CgiDomain, values["TOKEN"])
};
}
else
{
throw new Exception(values["L_LONGMESSAGE0"]);
}
}
提交
private static NameValueCollection Submit(NameValueCollection values)
{
string data = String.Join("&", values.Cast<string>()
.Select(key => String.Format("{0}={1}", key, HttpUtility.UrlEncode(values[key]))));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
String.Format("https://{0}/nvp", PayPalSettings.ApiDomain));
request.Method = "POST";
request.ContentLength = data.Length;
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(data);
}
using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))
{
return HttpUtility.ParseQueryString(reader.ReadToEnd());
}
}
GetExpressCheckout
public ActionResult Success(string token)
{
GetExpressCheckout getExpressCheckout = new GetExpressCheckout();
GetExpressCheckoutDetailsResponseType getExpressCheckoutResponse = getExpressCheckout.ECGetExpressCheckoutCode(token);
if (getExpressCheckoutResponse.Ack == AckCodeType.Success)
{
ExpressCheckout expressCheckout = new ExpressCheckout();
DoExpressCheckoutPaymentResponseType doExpressCheckoutResponse = expressCheckout.DoExpressCheckoutPayment
(
token,
getExpressCheckoutResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID,
PayPalSettings.OrderAmount,
PaymentActionCodeType.Sale,
CurrencyCodeType.USD
);
if (doExpressCheckoutResponse.Ack == AckCodeType.Success)
{
CreateRecurringPaymentsProfile createRecurringPaymentsProfile = new CreateRecurringPaymentsProfile();
CreateRecurringPaymentsProfileResponseType recurringPaymentProfileResponse = createRecurringPaymentsProfile.CreateRecurringPaymentsProfileCode(
doExpressCheckoutResponse.DoExpressCheckoutPaymentResponseDetails.Token,
doExpressCheckoutResponse.Timestamp,
PayPalSettings.OrderAmount,
1,
BillingPeriodType.Month,
CurrencyCodeType.USD
);
if (recurringPaymentProfileResponse.Ack == AckCodeType.Success)
{
}
CreateReEcurringPaymentsProfile
public CreateRecurringPaymentsProfileResponseType CreateRecurringPaymentsProfileCode(string token, DateTime date, string amount, int BF, BillingPeriodType BP, CurrencyCodeType currencyCodeType)
{
CallerServices caller = new CallerServices();
IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
// Set up your API credentials, PayPal end point, and API version.
profile.APIUsername = PayPalSettings.Username;
profile.APIPassword = PayPalSettings.Password;
profile.APISignature = PayPalSettings.Signature;
profile.Environment="sandbox";
caller.APIProfile = profile;
// Create the request object.
CreateRecurringPaymentsProfileRequestType pp_request=new CreateRecurringPaymentsProfileRequestType();
pp_request.Version="51.0";
// Add request-specific fields to the request.
pp_request.CreateRecurringPaymentsProfileRequestDetails= new CreateRecurringPaymentsProfileRequestDetailsType();
pp_request.CreateRecurringPaymentsProfileRequestDetails.Token=token;
pp_request.CreateRecurringPaymentsProfileRequestDetails.RecurringPaymentsProfileDetails=new RecurringPaymentsProfileDetailsType();
pp_request.CreateRecurringPaymentsProfileRequestDetails.RecurringPaymentsProfileDetails.BillingStartDate=date;
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails=new ScheduleDetailsType();
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod=new BillingPeriodDetailsType();
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.Amount=new BasicAmountType();
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.Amount.Value =amount ;
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.Amount.currencyID= currencyCodeType;//Enum for currency code is CurrencyCodeType.USD
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.BillingFrequency=BF;
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.BillingPeriod=BP;////Enum for BillingPeriod is BillingPeriodType.Day
//pp_request.Version = "51.0";
pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.Description = "Test subscription";
//pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.Description
// Execute the API operation and obtain the response.
CreateRecurringPaymentsProfileResponseType pp_response=new CreateRecurringPaymentsProfileResponseType();
pp_response= (CreateRecurringPaymentsProfileResponseType) caller.Call("CreateRecurringPaymentsProfile", pp_request);
return pp_response;
}
任何幫助將不勝感激。
提前致謝
Sujth,正確的版本是51.0滿足您的需求。 快樂的編碼!
在SetExpressCheckout調用中,將VERSION
設置為更新的內容,例如97.0
。 版本2.3中不存在L_BILLINGTYPE0
和L_BILLINGAGREEMENTDESCRIPTION
,因此API無法識別它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.