Paypal Braintree订阅付款 [英] Paypal Braintree Subscription Payments

查看:124
本文介绍了Paypal Braintree订阅付款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I cannot find anywhere how to do the javascript code for paypal subscription via braintree. Here is the code that I currently have that at least gets me to the checkout part for a single transaction amount. But I want to know how to implement a monthly reoccurring amount. lets say 1.99 a month until it is canceled. What am I missing?

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>


推荐答案

看起来你正在使用Checkout和PayPal,用于一次性付款。如果您要存储客户的付款信息以创建订阅,则需要使用 PayPal存储支付流程

It looks like you're using Checkout with PayPal, which is intended for one-time payments. If you want to store a customer's payment information for the purpose of creating a subscription, you'll need to use the 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 到您的服务器并在客户创建电话。然后,您可以使用订阅创建电话

Once your customer completes the checkout, you can submit the resulting payload.nonce to your server and use it in a customer create call. You can then set up a recurring subscription on the newly vaulted PayPal payment method using a subscription create call.

这篇关于Paypal Braintree订阅付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆