PayPal捐赠SDK-预填充金额和频率
我正在构建一个应用程序,其中包括自定义捐赠表单,用户可以在其中选择:
- 频率:每月,单次
- 金额:3 个带有值的按钮,输入自定义值
我正在使用 PayPal Donate SDK,无法找到一个传递金额或频率的方式,以便预先填写金额,并根据用户输入选择/取消选择“每月捐赠”复选框。
PayPal 按钮已添加到页面(只是在表单按钮上采用绝对样式),并且 SDK 以模式打开捐赠页面,这是我想要的结果。
这是显示我的按钮的代码:
window.PayPal.Donation.Button({
env: "sandbox",
hosted_button_id: "xxxxxxxxxxxx",
onComplete: function() {
// Redirect to success page, save the PP transaction details, etc.
}
}).render("#paypal-donate-button-container");
使用标准 PayPal.Buttons
API,我可以像这样传入 createOrder
函数,我可以在其中设置金额,例如;
window.PayPal.Buttons({
// ...
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: document.querySelector(".selected-premium").dataset.value
},
reference_id: document.querySelector(".selected-premium").dataset.days + "-days"
}]
});
}
}
有没有办法使用 SDK 传递金额和频率,类似于使用标准支付 API 的方式?如果不是,那么 2022 年有哪些替代方案不依赖于使用不再存在/已弃用方法的文档的 SO 答案?
I am building an application which includes a custom donation form where users can select:
- Frequency: monthly, single
- Amount: 3 x Buttons with values, input for custom value
I am using the PayPal Donate SDK and cannot find a way to pass across the amount or frequency so that the amount is pre-filled and the "make this a monthly donation" checkbox selected/deselected based on the users input.
The PayPal button has been added to the page (just absolute styled over the form button) and the SDK opens the donation page in a modal which is my desired result.
This is the code to display my button:
window.PayPal.Donation.Button({
env: "sandbox",
hosted_button_id: "xxxxxxxxxxxx",
onComplete: function() {
// Redirect to success page, save the PP transaction details, etc.
}
}).render("#paypal-donate-button-container");
With the standard PayPal.Buttons
API, I am able to pass in a createOrder
function like so, where I can set the amount, for example;
window.PayPal.Buttons({
// ...
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: document.querySelector(".selected-premium").dataset.value
},
reference_id: document.querySelector(".selected-premium").dataset.days + "-days"
}]
});
}
}
Is there a way to pass through the amount and frequency using the SDK, similar to how I can do it with the standard payments API? If not, what are the alternatives in 2022 that don't rely on SO answers that use docs that no longer exist/deprecated methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 PayPal 捐赠流程(包括捐赠 SDK)
您可以传递
金额
和currency_code
参数。如果您确实传递了预填金额,则将无法选择定期捐款的选项。您无法预先选择选项以使捐赠在捐赠流程中重复出现。
对于经常性捐赠的情况 - 由于无法预先检查选项以使其在捐赠流程中重复出现,也无法预先填写金额并提供重复性选择 - 您可以做的是在选择重复时使用订阅流程,并将其渲染在单独的 div 容器中,该容器根据您的每月选择与单次选择显示/隐藏。您的帐户的订阅按钮可以在以下位置生成:https://www.paypal.com/billing/plans 。它使用的计划必须有一个特定的金额,但是这个 可以在 JS
createSubscription
函数中覆盖(基于您网站上输入的任何选择或金额)(除了基本plan_id
之外)添加一个plan
对象,其中包含具有所需金额/频率的billing_cycles
对象。With the PayPal Donations flow (this includes the Donate SDK)
You can pass a parameter for the
amount
andcurrency_code
. If you do pass a prefilled amount, an option to make the donation recurring will not be available.You cannot pre select the option to make the donation recurring in the Donations flow.
For the case of recurring donations -- since it's not possible to precheck the option to make them recurring in the Donations flow, nor is it possible to prefill the amount and have that choice of recurrence even be available -- what you could do is instead use a Subscription flow for when a recurrence is selected, and have this render in a separate div container that is shown/hidden based on your monthly vs single selection. A subscribe button for your account can be generated at: https://www.paypal.com/billing/plans . The plan it uses must have a specific amount, but this can be overridden in the JS
createSubscription
function (based on whatever selection or amount was entered on your site) by (in addition to the baseplan_id
) adding aplan
object that contains abilling_cycles
object with the amount/frequency you want.