PayPal捐赠SDK-预填充金额和频率

发布于 2025-01-19 04:47:21 字数 1303 浏览 1 评论 0原文

我正在构建一个应用程序,其中包括自定义捐赠表单,用户可以在其中选择:

  • 频率:每月,单次
  • 金额: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

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜你已久 2025-01-26 04:47:21

通过 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 and currency_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 base plan_id) adding a plan object that contains a billing_cycles object with the amount/frequency you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文