PayPal .net REST API - 包含额外一次性付款的定期计费协议
PayPal .net REST API - Recurring billing agreements with additional one time payments
我是通过 .Net 接触 PayPal 的 REST API 的新手,但我遇到了以下问题:
我可以设置定期计费协议,一切正常。
我可以设置一个简单的付款方式,效果很好。
但是如何将两者合二为一呢?
一旦您将付款添加到结算协议(或相反),您就会得到一个无效令牌。
理想情况下,我们只想将用户定向到 paypal 一次以进行身份验证。设置新的计费协议并同时进行一次管理费用支付。
有任何想法吗?
如果有帮助,这是我的代码:
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();
听起来您希望 setup_fee
在 merchant_preferences
中可用,可以直接在 billing plan, or through override_merchant_preferences
on the billing agreement 中设置。 setup_fee
是在执行结算协议时处理的一次性付款。
抱歉,关于 .net 的任何细节,我无法帮助您。我所有的 PayPal 工作都通过 php.
我是通过 .Net 接触 PayPal 的 REST API 的新手,但我遇到了以下问题: 我可以设置定期计费协议,一切正常。 我可以设置一个简单的付款方式,效果很好。
但是如何将两者合二为一呢? 一旦您将付款添加到结算协议(或相反),您就会得到一个无效令牌。
理想情况下,我们只想将用户定向到 paypal 一次以进行身份验证。设置新的计费协议并同时进行一次管理费用支付。 有任何想法吗?
如果有帮助,这是我的代码:
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();
听起来您希望 setup_fee
在 merchant_preferences
中可用,可以直接在 billing plan, or through override_merchant_preferences
on the billing agreement 中设置。 setup_fee
是在执行结算协议时处理的一次性付款。
抱歉,关于 .net 的任何细节,我无法帮助您。我所有的 PayPal 工作都通过 php.