gpt4 book ai didi

c# - 使用 CreateRecurringPaymentsProfile API 时如何指定 PayPal 买家帐户?

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:41 24 4
gpt4 key购买 nike

注意:这篇文章中提到的所有代码都在沙箱中,而不是在实时环境中。

我将 CreateRecurringPaymentsProfile API 与 .Net SDK 结合使用,为订阅创建定期付款配置文件。虽然我可以使用下面的代码片段在买家使用信用卡时创建定期配置文件,但是当买家使用 PayPal 帐户时我不能这样做。我在 Merchant Net SDK 中找不到任何属性来指定买家拥有 PayPal 帐户。

问题:如何使用 Merchant SDK 使用 CreateRecurringPaymentsProfile API 为 PayPal 买家帐户而不是信用卡创建订阅配置文件?

CreateRecurringPaymentsProfile API 与使用 Merchant Net SDK 的信用卡

CreateRecurringPaymentsProfileReq createRecurringPaymentsProfile = new CreateRecurringPaymentsProfileReq();
CreateRecurringPaymentsProfileRequestType createRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType();

RecurringPaymentsProfileDetailsType recurringPaymentsProfileDetails
= new RecurringPaymentsProfileDetailsType("2016-06-02T16:55:19+00:00");


BasicAmountType billingAmount = new BasicAmountType(CurrencyCodeType.USD, "3.00");


BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(BillingPeriodType.DAY, Convert.ToInt32("5"), billingAmount);


ScheduleDetailsType scheduleDetails = new ScheduleDetailsType("description", paymentPeriod);


CreateRecurringPaymentsProfileRequestDetailsType createRecurringPaymentsProfileRequestDetails
= new CreateRecurringPaymentsProfileRequestDetailsType(recurringPaymentsProfileDetails, scheduleDetails);

CreditCardDetailsType creditCard = new CreditCardDetailsType();
creditCard.CreditCardType = CreditCardTypeType.VISA;
creditCard.CreditCardNumber = "5261193281604310";
creditCard.CVV2 = "235";
creditCard.ExpMonth = Convert.ToInt32("12");
creditCard.ExpYear = Convert.ToInt32("2016");
createRecurringPaymentsProfileRequestDetails.CreditCard = creditCard;

createRecurringPaymentsProfileRequest.CreateRecurringPaymentsProfileRequestDetails = createRecurringPaymentsProfileRequestDetails;
createRecurringPaymentsProfile.CreateRecurringPaymentsProfileRequest = createRecurringPaymentsProfileRequest;

PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();

responseCreateRecurringPaymentsProfileResponseType
= service.CreateRecurringPaymentsProfile(createRecurringPaymentsProfile);

最佳答案

答案是不能在 CreateRecurringPaymentsProfile API 中将付款人指定为 PayPal 账户持有人。但是,此 API 仍可用于为 PayPal 帐户持有人创建订阅,如下所述。

要使用 CreateRecurringPaymentsProfile API 通过现有的 PayPal 帐户而不是信用卡创建订阅,需要遵循一个多步骤过程。 第一步是调用 SetExpressCheckout 将 BillingAgreementDetailsType 指定为 RecurringPayments,然后重定向到此 URL (https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express -checkout) 传递 token 以响应 SetExpressCheckout API。

  • 此重定向会将用户带到 PayPal 登录页面,用户在该页面上登录并接受或取消订阅请求。
  • 如果用户接受,则用户将被重定向到 SetExpressCheckout API 调用的 ReturnURL 中指定的页面
  • 如果用户不接受订阅,则用户将被重定向到在 SetExpressChecout API 调用中指定的 CancelURL

第二步是在 SetExpressCheckout API 调用中指定的 ReturnURL 页面中调用 CreateRecurringPaymentsProfile 并将在步骤 1 之后收到的 token 传递给它(从传递给 ReturnUrl 的查询字符串参数中获取)在第 1 步)。当您将 token 传递给此 API 时,您不应指定任何信用卡详细信息。此步骤将导致从在第 1 步中接受订阅的用户的 PayPal 帐户支付订阅费用。

调用 SetExpressCheckout 并将用户重定向到 PayPal 的代码

 protected void btnSubmit_Click(object sender, EventArgs e) {
string token = null;
SetExpressCheckoutResponseType response = SetExpressCheckoutAPIOperation();
if (response.Token == null) {
txtLog.Text = "There was some issue with calling SetExpressCheckout API. Please review the failure message that should also be printed in this textbox.";
} else {
token = response.Token;
Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + Server.UrlEncode(token));
}
}

public SetExpressCheckoutResponseType SetExpressCheckoutAPIOperation() {
// Create the SetExpressCheckoutResponseType object
SetExpressCheckoutResponseType responseSetExpressCheckoutResponseType = new SetExpressCheckoutResponseType();

try {
SetExpressCheckoutRequestDetailsType setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();

BillingAgreementDetailsType baType = new BillingAgreementDetailsType(BillingCodeType.RECURRINGPAYMENTS);
baType.BillingAgreementDescription = "Gold Carrier";
billingAgreementDescription = baType.BillingAgreementDescription;
setExpressCheckoutRequestDetails.BillingAgreementDetails.Add(baType);

// URL to which the buyer's browser is returned after choosing to pay
// with PayPal.
setExpressCheckoutRequestDetails.ReturnURL = "http://www.myexample.com/completed.aspx";

// URL to which the buyer is returned if the buyer does not approve the
// use of PayPal to pay you.
setExpressCheckoutRequestDetails.CancelURL = "http://www.myexample.com/canceled.aspx";

SetExpressCheckoutReq setExpressCheckout = new SetExpressCheckoutReq();
SetExpressCheckoutRequestType setExpressCheckoutRequest = new SetExpressCheckoutRequestType(setExpressCheckoutRequestDetails);

setExpressCheckout.SetExpressCheckoutRequest = setExpressCheckoutRequest;

Dictionary < string, string > configurationMap = new Dictionary < string, string > ();

configurationMap.Add("mode", "sandbox");
// Signature Credential
configurationMap.Add("account1.apiUsername", "******");
configurationMap.Add("account1.apiPassword", "*******");
configurationMap.Add("account1.apiSignature", "********");
configurationMap.Add("account1.applicationId", "******");
// Create the service wrapper object to make the API call
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

// # API call
responseSetExpressCheckoutResponseType = service.SetExpressCheckout(setExpressCheckout);
}
// # Exception log
catch (System.Exception ex) {
// Log the exception message

}
return responseSetExpressCheckoutResponseType;
}

ReturnURL 中用于调用 CreateRecurringPaymentProfile API 的代码

protected void Page_Load(object sender, EventArgs e) {
if (!string.IsNullOrWhiteSpace(Request.QueryString["token"])) {
token = Server.UrlDecode(Request.QueryString["token"]);
CreateRecurringPaymentProfile();
}
}

private void CreateRecurringPaymentProfile() {
CreateRecurringPaymentsProfileResponseType responseCreateRecurringPaymentsProfileResponseType = new CreateRecurringPaymentsProfileResponseType();

try {

CreateRecurringPaymentsProfileReq createRecurringPaymentsProfile = new CreateRecurringPaymentsProfileReq();
CreateRecurringPaymentsProfileRequestType createRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType();


RecurringPaymentsProfileDetailsType recurringPaymentsProfileDetails
= new RecurringPaymentsProfileDetailsType(string.Format("{0}{1}", DateTime.UtcNow.ToString("s"), "Z"));

// Billing amount for each billing cycle during this payment period.
BasicAmountType billingAmount = new BasicAmountType(CurrencyCodeType.USD, "3.00");
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(BillingPeriodType.DAY, Convert.ToInt32("5"), billingAmount);
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType(this.billingAgreementDescription, paymentPeriod);
CreateRecurringPaymentsProfileRequestDetailsType createRecurringPaymentsProfileRequestDetails
= new CreateRecurringPaymentsProfileRequestDetailsType(recurringPaymentsProfileDetails, scheduleDetails);


// Either EC token or a credit card number is required.If you include
CreditCardDetailsType creditCard = new CreditCardDetailsType();
if (string.IsNullOrEmpty(token)) {
creditCard.CreditCardType = CreditCardTypeType.VISA;
creditCard.CreditCardNumber = "5261193281604310";
creditCard.CVV2 = "235";
creditCard.ExpMonth = Convert.ToInt32("12");
creditCard.ExpYear = Convert.ToInt32("2016");
createRecurringPaymentsProfileRequestDetails.CreditCard = creditCard;
} else //we are using a PayPal email account i.e. not a credit card but a PayPal account to set up the subscription
{
createRecurringPaymentsProfileRequestDetails.Token = token;
}


createRecurringPaymentsProfileRequest.CreateRecurringPaymentsProfileRequestDetails = createRecurringPaymentsProfileRequestDetails;

createRecurringPaymentsProfile.CreateRecurringPaymentsProfileRequest = createRecurringPaymentsProfileRequest;


Dictionary < string, string > configurationMap = new Dictionary < string, string > ();

configurationMap.Add("mode", "sandbox");
// Signature Credential
configurationMap.Add("account1.apiUsername", "*****");
configurationMap.Add("account1.apiPassword", "*****");
configurationMap.Add("account1.apiSignature", "*****");
configurationMap.Add("account1.applicationId", "*****");

// Create the PayPalAPIInterfaceServiceService service object to make the API call
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
responseCreateRecurringPaymentsProfileResponseType
= service.CreateRecurringPaymentsProfile(createRecurringPaymentsProfile);
}
// # Exception log
catch (System.Exception ex) {
// Log the exception message

}
}

关于c# - 使用 CreateRecurringPaymentsProfile API 时如何指定 PayPal 买家帐户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37603355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com