Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用PayPal SDK和.NET创建订阅付款_C#_Asp.net_Asp.net Mvc_Paypal_Asp.net Mvc 5 - Fatal编程技术网

C# 使用PayPal SDK和.NET创建订阅付款

C# 使用PayPal SDK和.NET创建订阅付款,c#,asp.net,asp.net-mvc,paypal,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc,Paypal,Asp.net Mvc 5,我在以下网站上找到了此代码: https://devtools-paypal.com/guide/recurring_payment_ec/dotnet?interactive=ON&env=sandbox 代码如下: SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType(); ecDetails.ReturnURL = "https://devtools-pa

我在以下网站上找到了此代码:

https://devtools-paypal.com/guide/recurring_payment_ec/dotnet?interactive=ON&env=sandbox
代码如下:

SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();
ecDetails.ReturnURL = "https://devtools-paypal.com/guide/recurring_payment_ec/dotnet?success=true";
ecDetails.CancelURL = "https://devtools-paypal.com/guide/recurring_payment_ec/dotnet?cancel=true";
ecDetails.PaymentDetails = paymentDetails;

BillingCodeType billingCodeType = (BillingCodeType)EnumUtils.GetValue("RecurringPayments", typeof(BillingCodeType));
BillingAgreementDetailsType baType = new BillingAgreementDetailsType(billingCodeType);
baType.BillingAgreementDescription = "recurringbilling";
ecDetails.BillingAgreementDetails.Add(baType);

SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();
request.Version = "104.0";
request.SetExpressCheckoutRequestDetails = ecDetails;

SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();
wrapper.SetExpressCheckoutRequest = request;
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
sdkConfig.Add("account1.apiUsername", "jb-us-seller_api1.paypal.com");
sdkConfig.Add("account1.apiPassword", "WX4WTU3S8MY44S7F");
sdkConfig.Add("account1.apiSignature", "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy");
PayPalAPIInterfaceServiceService service = new  PayPalAPIInterfaceServiceService(sdkConfig); 
SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper);
这会将用户带到paypal网站,确认账单协议,然后将用户返回到我的网站

然后,要创建与使用SetExpressCheckout调用创建的计费协议关联的定期付款配置文件,请使用SetExpressCheckout API响应中获得的令牌和SetExpressCheckout API请求中使用的billingAgreementDescription进行CreateRecurringPaymentsProfile API调用

代码如下所示:

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4SD42613U5111594L
 CreateRecurringPaymentsProfileRequestType createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
CreateRecurringPaymentsProfileRequestDetailsType createRPProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType();
createRPProfileRequestDetails.Token = "EC-4SD42613U5111594L";
createRPProfileRequest.CreateRecurringPaymentsProfileRequestDetails = createRPProfileRequestDetails;

RecurringPaymentsProfileDetailsType profileDetails = new RecurringPaymentsProfileDetailsType("2016-010-31T00:00:00:000Z");
profileDetails.RecurringPaymentsProfileDetails = profileDetails;

int frequency = 10;
BasicAmountType paymentAmount = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("USD", typeof(CurrencyCodeType)), "1.0");
BillingPeriodType period = (BillingPeriodType)EnumUtils.GetValue("Day", typeof(BillingPeriodType));
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(period, frequency, paymentAmount);

ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();
scheduleDetails.Description = "recurringbilling";
scheduleDetails.PaymentPeriod = paymentPeriod;
profileDetails.ScheduleDetails = scheduleDetails;

CreateRecurringPaymentsProfileReq createRPProfileReq = new CreateRecurringPaymentsProfileReq();
createRPProfileReq.CreateRecurringPaymentsProfileRequest = createRPProfileRequest;

Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
sdkConfig.Add("account1.apiUsername", "jb-us-seller_api1.paypal.com");
sdkConfig.Add("account1.apiPassword", "WX4WTU3S8MY44S7F");
sdkConfig.Add("account1.apiSignature", "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy");
PayPalAPIInterfaceServiceService service = new  PayPalAPIInterfaceServiceService(sdkConfig); 
CreateRecurringPaymentsProfileResponseType createRPProfileResponse = service.CreateRecurringPaymentsProfile(createRPProfileReq);
完成后,我将hte ProfileID参数存储到数据库中,以便将来处理订阅

我这里的问题是:我如何管理每月/每年的订阅(取决于用户决定每月或每年付费的方式)

我想到了两种情况:

  • 如果用户通过paypal取消计费协议怎么办?我是否应该在每个用户登录时检查订阅状态

  • PayPal端的计费可能是自动完成的,或者我是否必须每1个月/1年创建一个付款请求,以便向使用我网站上的高级服务的用户收费

  • 这对我来说仍然是非常困惑的,因为自从我开始编写代码以来,我第一次遇到这种问题

    有人能帮我吗

    PROFILEID=I-0H1CDRF2NEWB&PROFILESTATUS=ActiveProfile&TIMESTAMP=2016-10-31T15:56:13Z&CORRELATIONID=a5fcc91e86a24&ACK=Success&VERSION=104.0&BUILD=24616352