【问题标题】:Paypal Braintree Subscription Payments贝宝 Braintree 订阅付款
【发布时间】:2018-05-07 01:56:14
【问题描述】:

我在任何地方都找不到如何通过 Braintree 为 paypal 订阅做 javascript 代码。这是我目前拥有的代码,至少可以让我进入单笔交易金额的结账部分。但我想知道如何实现每月重复发生的金额。让我们说每月 1.99,直到它被取消。我错过了什么?

Java 代码

@Path("/braintree")
public class TestBraintree {
    private static BraintreeGateway gateway = new BraintreeGateway(
            Environment.SANDBOX,
            "myMerchantId",
            "myPublicKey",
            "myPrivateKey"
    );

    @GET
    @Path("/client_token")
    public String getMsg() {
        return gateway.clientToken().generate();
    }

    @POST
    @Consumes("application/json")
    @Path("/checkout")
    public String getCheckoutMessage(String json) {
//        String nonceFromTheClient = request .queryParams("payment_method_nonce");
        System.out.println();
        return "";
    }
}

HTML 代码

<head>
    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
    <script src="https://js.braintreegateway.com/web/3.11.0/js/client.min.js"></script>
    <script src="https://js.braintreegateway.com/web/3.11.0/js/paypal-checkout.min.js"></script>
</head>
<body>
     <div id="paypal-button-container"></div>
       var client_token = document.getElementById('clientId').value;
                <script>
                    paypal.Button.render({
                        braintree: braintree,
                        client: {
                            production: client_token,
                            sandbox: client_token,
                        },
                        env: 'sandbox', // Or 'sandbox'
                        commit: true, // This will add the transaction amount to the PayPal button

                        payment: function (data, actions) {
                            return actions.braintree.create({
                                flow: 'checkout', // Required
                                amount: 10.00, // Required
                                currency: 'USD', // Required
                                enableShippingAddress: true,
                                shippingAddressEditable: false,
                                shippingAddressOverride: {
                                    recipientName: 'Scruff McGruff',
                                    line1: '1234 Main St.',
                                    line2: 'Unit 1',
                                    city: 'Chicago',
                                    countryCode: 'US',
                                    postalCode: '60652',
                                    state: 'IL',
                                    phone: '123.456.7890'
                                }
                            });
                        },

                        onAuthorize: function (payload) {
                            // Submit `payload.nonce` to your server.
                        },
                    }, '#paypal-button-container');
                </script>
</body>

【问题讨论】:

    标签: javascript java paypal braintree


    【解决方案1】:

    您似乎正在使用带有 PayPal 的 Checkout,它旨在用于一次性付款。如果您想存储客户的付款信息以创建订阅,则需要使用PayPal vaulted payment flow

    // Set up PayPal with the checkout.js library
    paypal.Button.render({
      env: 'production', // or 'sandbox'
    
      payment: function () {
        return paypalCheckoutInstance.createPayment({
          flow: 'vault',
          billingAgreementDescription: 'Your agreement description',
          enableShippingAddress: true,
          shippingAddressEditable: false,
          shippingAddressOverride: {
            recipientName: 'Scruff McGruff',
            line1: '1234 Main St.',
            line2: 'Unit 1',
            city: 'Chicago',
            countryCode: 'US',
            postalCode: '60652',
            state: 'IL',
            phone: '123.456.7890'
          }
        });
      },
    
      onAuthorize: function (data, actions) {
        return paypalCheckoutInstance.tokenizePayment(data)
          .then(function (payload) {
            // Submit `payload.nonce` to your server.
          });
      }
    

    您的客户完成结帐后,您可以将生成的payload.nonce 提交到您的服务器并在customer create call 中使用它。然后,您可以使用 subscription create call 在新保管的 PayPal 付款方式上设置定期订阅。

    【讨论】:

    • 奇怪....所以你不需要价格吗?你只是说嘿这是你和供应商之间的协议吗?然后提供商可以按月发送?
    • @Justin 是的,使用保管支付流程时不需要金额。完整的选项列表是available here。您可以在plan中指定订阅价格。
    • 谢谢!这很有帮助,同时又超级简单,不知道我是怎么错过的。我想我只是对它如何在我的脑海中发挥作用有了这个想法,我无法忽略它。我给了+50 :)。谢谢!
    猜你喜欢
    • 2014-04-09
    • 2015-07-23
    • 2016-06-24
    • 2011-09-15
    • 2012-03-04
    • 2020-11-16
    • 1970-01-01
    • 2013-03-22
    相关资源
    最近更新 更多