gpt4 book ai didi

.net - PayPal .net REST API - 包含额外一次性付款的定期计费协议(protocol)

转载 作者:太空宇宙 更新时间:2023-11-03 15:55:19 25 4
gpt4 key购买 nike

我是通过 .Net 接触 PayPal 的 REST API 的新手,但我遇到了以下问题:我可以设置定期计费协议(protocol),一切正常。我可以设置简单的付款方式,效果很好。

但是如何将两者合二为一呢?一旦您将付款添加到计费协议(protocol)(或相反),您就会得到一个无效 token 。

理想情况下,我们只想将用户定向到 paypal 一次以进行身份​​验证。设置新的计费协议(protocol)并同时进行一次管理费用支付。有任何想法吗?

如果有帮助,这是我的代码:

public string CreateOrder(MarketingFramework mf, HttpContext httpContext, User user, int packageid)
{

Group topgroup = user.RootGroup;

//get the package
var package = mf.Core.GetById<Package>(packageid);
var admincharge =
mf.Core.GetAll<SystemSettings>()
.FirstOrDefault(s => s.Name == "Admin Charge" && s.Type == user.ProfileType)
.Value;
var cancelUrl = ConfigurationManager.AppSettings["Domain"] + "/Basket/Cancel.aspx";
var confirmationUrl = ConfigurationManager.AppSettings["Domain"] + "/Basket/Confirm.aspx";


//set the new purchase history date, if you had a package before and its not free, take that date and move it on a month
//the date is set on the group everytime the IPN gateway makes a payment, therefore should always only be one month behind
var newdate = DateTime.Now;
if (topgroup.CurrentPackage.Package.Cost != 0) newdate = topgroup.CurrentPackage.DateAdded.AddMonths(1);

//Authenticate with paypal
var apiContext = Configuration.GetAPIContext();

//cancel any current recurring packages
if (topgroup.CurrentPackage.PaymentStatus == "Active Profile")
{
var plan = Plan.Get(apiContext, topgroup.CurrentPackage.ProfileId);
plan.Delete(apiContext);
}

//if the package costs money eg: you not coming from a free account, an admin charge will apply
//there is different prices for corporate or public in the settings table
if (topgroup.CurrentPackage.Package.Cost != 0)
{
//calc the upgrade cost
var totalamount = package.Cost - user.RootGroup.CurrentPackage.Package.Cost;
if (totalamount < 0) totalamount = 0;

var guid = Convert.ToString((new Random()).Next(100000));

var itemList = new ItemList()
{
items = new List<Item>()
{
new Item()
{
name = "Administration charge",
currency = "GBP",
price = admincharge,
quantity = "1",
description = "Administration charge for upgrading package",
sku = package.Id.ToString()
} ,
new Item()
{
name = "Upgrade charge",
description = "Difference in price when upgrading to a new package",
currency = "GBP",
price = totalamount.ToString(),
quantity = "1",
sku = package.Id.ToString()
}
}
};



var payer = new Payer() { payment_method = "paypal" };
var redirUrls = new RedirectUrls()
{
cancel_url = cancelUrl,
return_url = confirmationUrl
};

var details = new Details()
{
tax = "0",
shipping = "0",
subtotal = (Convert.ToDecimal(totalamount) + Convert.ToDecimal(admincharge)).ToString()
};

var amount = new Amount()
{
currency = "GBP",
total = details.subtotal,
details = details
};

var transactionList = new List<Transaction>();

transactionList.Add(new Transaction()
{
description = "Proofanything transaction",
invoice_number = "1", //TODO need to setup invoice numbering
amount = amount,
item_list = itemList
});

var payment = new Payment()
{
intent = "sale",
payer = payer,
transactions = transactionList,
redirect_urls = redirUrls
};

////setup the recurring payment
var recurring = new Plan
{
name = "Payment plan",
description = "Proofanything monthly package plan",
type = "INFINITE",
// Define the merchant preferences.
// More Information: https://developer.paypal.com/webapps/developer/docs/api/#merchantpreferences-object
merchant_preferences = new MerchantPreferences()
{
setup_fee = GetCurrency(admincharge),
return_url = confirmationUrl,
cancel_url = cancelUrl,
auto_bill_amount = "YES",
initial_fail_amount_action = "CONTINUE",
max_fail_attempts = "0"
},
payment_definitions = new List<PaymentDefinition>
{
new PaymentDefinition()
{
name = package.Name,
type = "REGULAR",
frequency = "MONTH",
frequency_interval = "1",
amount = GetCurrency(package.Cost.ToString()),
cycles = "0"
},

}
};


////create the payments and plan
var createdPlan = recurring.Create(apiContext);
var createdPayment = payment.Create(apiContext);


//redirect to paypal for approval
return createdPayment.GetApprovalUrl();

最佳答案

听起来您希望merchant_preferences 中提供setup_fee,可以直接在billing plan 上设置,或通过 billing agreement 上的 override_merchant_preferences . setup_fee 是在执行计费协议(protocol)时处理的一次性付款。

抱歉,我无法帮助您解决任何有关 .net 的具体问题。我所有的 PayPal 工作都是通过 php 完成的。

关于.net - PayPal .net REST API - 包含额外一次性付款的定期计费协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29343345/

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