Я новичок в API REST PayPal через .Net, но у меня возникла следующая проблема: Я могу настроить повторяющееся соглашение о выставлении счетов, и все работает отлично , Я могу настроить простой платеж, и это работает нормально.PayPal .net 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();
Это может быть ответ, который я искал! Один быстрый вопрос по этому вопросу: если я использую плату за установку и устанавливаю повторяющуюся дату начала следующего месяца, взимается ли плата в следующем месяце и повторяющийся счет в следующем месяце? –
@MarkGeary 'setup_fee' берется немедленно, независимо от того, когда установлена повторяющаяся дата начала. См. [Здесь] (https://github.com/paypal/PayPal-PHP-SDK/issues/180#issuecomment-66811384) для получения дополнительной информации. –
Действительно, как сказал @JasonZ. И, как показывает его ссылка, 'setup_fee' даже является атомарным для выполнения соглашения. Существует опция «merchant_preferences» для 'initial_fail_amount_action', которая принимает' CONTINUE' (по умолчанию) или 'CANCEL'. Я не уверен, что это относится к 'setup_fee' или к первому регулярному платежу, или к обоим, однако. – Red