[英]PayPal Recurring Payments for Installment Donations
我想在我的.NET網站上開始捐贈活動,要求人們同意向我的組織捐贈200.00美元。 由於有些人可能沒有預先支付所有的錢,我想讓他們現在可以選擇捐贈50美元或更多,然后將剩余的金額分攤到每月1-3次之間。
我是否需要為每種可能的方案設置定期付款按鈕,然后使用一些腳本來確定我應該將用戶引導到哪個PayPal表單按鈕? 或者有更靈活的方式嗎?
我認為你必須制定一個計費方案。 以下代碼段來自PayPal SDK 。 我根據您的需要對其進行了一些修改,但您仍需要對其進行自定義。
var plan = new Plan
{
name = "Donation Split Payment",
description = "Monthly plan for the less fortunate.",
type = "fixed",
// Define the merchant preferences.
// More Information: https://developer.paypal.com/webapps/developer/docs/api/#merchantpreferences-object
merchant_preferences = new MerchantPreferences()
{
setup_fee = GetCurrency("0"),
return_url = httpContext.Request.Url.ToString(),
cancel_url = httpContext.Request.Url.ToString() + "?cancel",
auto_bill_amount = "YES",
initial_fail_amount_action = "CONTINUE",
max_fail_attempts = "0"
},
payment_definitions = new List<PaymentDefinition>
{
// Define a trial plan that will only charge $50 for the first
// month. After that, the standard plan will take over for the
// remaining 4 months.
new PaymentDefinition()
{
name = "First Payment",
type = "REGULAR",
frequency = "MONTH",
frequency_interval = "1",
amount = GetCurrency("50.00"),
cycles = "1",
charge_models = new List<ChargeModel>
{
new ChargeModel()
{
type = "TAX",
amount = GetCurrency("9.99")
}
}
},
// Define the standard payment plan. It will represent a monthly
// plan for $50 USD that charges once month for 3 months.
new PaymentDefinition
{
name = "Other payment",
type = "REGULAR",
frequency = "MONTH",
frequency_interval = "1",
amount = GetCurrency("50.00"),
// > NOTE: For `IFNINITE` type plans, `cycles` should be 0 for a `REGULAR` `PaymentDefinition` object.
cycles = "3",
charge_models = new List<ChargeModel>
{
new ChargeModel
{
type = "TAX",
amount = GetCurrency("9.99")
}
}
}
}
};
我不熟悉“PayPal-Button”本身,但我想,這只是一些參數的變化。 最有可能在URL本身。 (GET請求)
因此,您可以在網站上放置帶有選項的下拉列表,將付款分成n個相等的部分,然后使用此按鈕重定向到相應的PayPal-URL,而不是創建多個按鈕。
我不知道你的堆棧,但使用MVC(Razor)和一些Javascript,它似乎沒有太大的努力。
因此,要么在頁面上使用JS來重定向,只需單擊按鈕,或者在服務器端進行評估后返回重定向。
如果PayPal使用POST,那么您可以使用Form,在其中使用Form 外部的其他INPUT的某些事件更改INPUT的值。 這需要JavaScript。
所以在Select-Click-Event上:設置input-element的值,“PayPal-button”用於POST請求。 像下面這樣的東西。
<script>
function SetValue(){
buttonValue.value = selector.value;
}
</script>
<SELECT id="selector" onClick="SetValue()">
... options
</SELECT>
<Form ...>
<input id="buttonValue" ... />
<button...>Send</button>
</Form>
檢查此工作流程https://developer.paypal.com/docs/subscriptions/
https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription
我沒有完整的代碼,之前稱之為計費協議。 Paypal .net sdk已經兩年了。 https://github.com/paypal/PayPal-NET-SDK/blob/develop/Samples/Source/BillingAgreementCreateAndExecute.aspx.cs在paypal網站上提到了這一點。 帳單協議API棄用通知:不推薦使用/ v1 / billing-agreements端點。 請改用/ v1 / billing / subscriptions端點。 有關詳細信息,請參閱訂閱集成。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.