使用初始金额创建paypal定期付款

时间:2014-06-17 16:16:18

标签: c# .net paypal

尝试使用PayPal创建定期付款,我需要收取会员资格的初始付款,然后每年都会重复付款。

我到目前为止所遵循的交互式指南如下所示,虽然它们让您知道该怎么做,但他们缺少某些参数来完成我需要它做的事情。

var homepage = UmbracoContext.Current.ContentCache.GetAtRoot().SingleOrDefault(x => x.DocumentTypeAlias == "Homepage");
var paymentDetail = new PaymentDetailsType();
paymentDetail.PaymentAction = (PaymentActionCodeType)EnumUtils.GetValue("Sale", typeof(PaymentActionCodeType));
paymentDetail.ItemTotal = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType)), "30.00");
paymentDetail.OrderTotal = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType)), "30.00");
paymentDetail.OrderTotal.value = "30.00";

var paymentDetails = new List<PaymentDetailsType> { paymentDetail };

//Get default PayPal server settings from our hompage node
var paypalurl = homepage.GetPropertyValue("payPalReturnURL").ToString();
var paypalcancelurl = homepage.GetPropertyValue("payPalCancelURL").ToString();

var ecDetails = new SetExpressCheckoutRequestDetailsType
{
    ReturnURL = paypalurl,
    CancelURL = paypalcancelurl,
    PaymentDetails = paymentDetails
};

var billingCodeType = (BillingCodeType)EnumUtils.GetValue("RecurringPayments", typeof(BillingCodeType));
var baType = new BillingAgreementDetailsType(billingCodeType)
{
    BillingAgreementDescription = "FLA Associate Membership - Recurring - £30.00",
};
ecDetails.BillingAgreementDetails.Add(baType);

var request = new SetExpressCheckoutRequestType
{
    Version = "104.0",
    SetExpressCheckoutRequestDetails = ecDetails
};

var wrapper = new SetExpressCheckoutReq { SetExpressCheckoutRequest = request };
var sdkConfig = new Dictionary<string, string>
{
    {"mode", homepage.GetPropertyValue("payPalMode").ToString()},
    {"account1.apiUsername", homepage.GetPropertyValue("payPalAPIUsername").ToString()},
    {"account1.apiPassword", homepage.GetPropertyValue("payPalAPIPassword").ToString()},
    {"account1.apiSignature", homepage.GetPropertyValue("payPalAPISignature").ToString()}
};
var service = new PayPalAPIInterfaceServiceService(sdkConfig);
var setEcResponse = service.SetExpressCheckout(wrapper);

var token = setEcResponse.Token;

if (!string.IsNullOrEmpty(token))
{
    // add user details to session
    Session["FLACurrentuser"] = model;
    var tokenurl = homepage.GetPropertyValue("payPalTokenRedirect").ToString();
    return Redirect(tokenurl + token);
}
else
{
    return Redirect("/register/error.aspx");
}

这会显示此屏幕,因为您在此处看不到任何项目详细信息以进行初始付款:

当我接受并继续并发送到成功页面时,我在此处使用此代码创建定期付款:

var success = Request.QueryString["success"];
var token = Request.QueryString["token"];

if (!string.IsNullOrEmpty(success) && !string.IsNullOrEmpty(token))
{
    var model = Session["FLACurrentuser"] as RegisterAssociateViewModel;
    var homepage = UmbracoContext.Current.ContentCache.GetAtRoot().SingleOrDefault(x => x.DocumentTypeAlias == "Homepage");

    var createRpProfileRequest = new CreateRecurringPaymentsProfileRequestType();
    var createRpProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType();
    createRpProfileRequestDetails.Token = token;
    createRpProfileRequest.CreateRecurringPaymentsProfileRequestDetails = createRpProfileRequestDetails;

    var profileDetails = new RecurringPaymentsProfileDetailsType();
    profileDetails.BillingStartDate = DateTime.Now.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");


    int frequency = 1;
    var paymentAmount = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType)), "30.00");
    var period = (BillingPeriodType)EnumUtils.GetValue("Year", typeof(BillingPeriodType));
    var paymentPeriod = new BillingPeriodDetailsType(period, frequency, paymentAmount);
    //paymentPeriod.TaxAmount = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType)), "30.00");

    var scheduleDetails = new ScheduleDetailsType();
    scheduleDetails.Description = "FLA Associate Membership - Recurring - £30.00";
    scheduleDetails.PaymentPeriod = paymentPeriod;

    var activationDetails = new ActivationDetailsType();
    activationDetails.InitialAmount = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType)), "30.00");

    scheduleDetails.ActivationDetails = activationDetails;

    createRpProfileRequestDetails.RecurringPaymentsProfileDetails = profileDetails;
    createRpProfileRequestDetails.ScheduleDetails = scheduleDetails;


    var createRpProfileReq = new CreateRecurringPaymentsProfileReq();
    createRpProfileReq.CreateRecurringPaymentsProfileRequest = createRpProfileRequest;


    var sdkConfig = new Dictionary<string, string>();
    sdkConfig.Add("mode", homepage.GetPropertyValue("payPalMode").ToString());
    sdkConfig.Add("account1.apiUsername", homepage.GetPropertyValue("payPalAPIUsername").ToString());
    sdkConfig.Add("account1.apiPassword", homepage.GetPropertyValue("payPalAPIPassword").ToString());
    sdkConfig.Add("account1.apiSignature", homepage.GetPropertyValue("payPalAPISignature").ToString());
    var service = new PayPalAPIInterfaceServiceService(sdkConfig);
    var createRpProfileResponse = service.CreateRecurringPaymentsProfile(createRpProfileReq);

这会使用初始付款创建定期付款资料,但我发送的金额为0,金额为总计?

这是一个截图:

0 个答案:

没有答案