贝宝布伦特里订阅付款
Paypal Braintree Subscription Payments
我找不到任何地方如何通过 braintree 为贝宝订阅做 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>
您似乎使用的是通过 PayPal 结账,这是为了一次性付款。如果您想存储客户的付款信息以创建订阅,则需要使用 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. You can then set up a recurring subscription on the newly vaulted PayPal payment method using a subscription create call.
中使用它
我找不到任何地方如何通过 braintree 为贝宝订阅做 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>
您似乎使用的是通过 PayPal 结账,这是为了一次性付款。如果您想存储客户的付款信息以创建订阅,则需要使用 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. You can then set up a recurring subscription on the newly vaulted PayPal payment method using a subscription create call.