Javascript Paypal Braintree订阅付款
我在任何地方都找不到如何通过braintree为paypal订阅编写javascript代码。下面是我目前拥有的代码,它至少可以让我进入单笔交易金额的结帐部分。但我想知道如何实现每月重复发生的金额。比方说每月1.99英镑,直到取消为止。我错过了什么 Java代码Javascript Paypal Braintree订阅付款,javascript,java,paypal,braintree,Javascript,Java,Paypal,Braintree,我在任何地方都找不到如何通过braintree为paypal订阅编写javascript代码。下面是我目前拥有的代码,它至少可以让我进入单笔交易金额的结帐部分。但我想知道如何实现每月重复发生的金额。比方说每月1.99英镑,直到取消为止。我错过了什么 Java代码 @Path("/braintree") public class TestBraintree { private static BraintreeGateway gateway = new BraintreeGateway(
@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>
var client_token=document.getElementById('clientId').value;
paypal.Button.render({
braintree:braintree,
客户:{
生产:客户_代币,
沙盒:客户端令牌,
},
env:'沙盒',//或'沙盒'
commit:true,//这将向PayPal按钮添加交易金额
支付:功能(数据、操作){
return actions.braintree.create({
流:“签出”,//必需
金额:10.00,//必需
货币:'美元',//必填项
enableShippingAddress:true,
ShippingAddress:false,
shippingAddressOverride:{
接收方名称:“Scruff McGraff”,
第1行:“主大街1234号”,
第2行:“1号机组”,
城市:'芝加哥',
国家代码:“美国”,
邮政编码:“60652”,
声明:“IL”,
电话:123.456.7890
}
});
},
onAuthorize:功能(有效负载){
//向服务器提交'payload.nonce'。
},
}“#贝宝按钮容器”);
看起来您正在使用PayPal的Checkout,这是一种一次性付款方式。如果要存储客户的付款信息以创建订阅,则需要使用:
客户完成结账后,您可以将结果
payload.nonce
提交到您的服务器,并在服务器中使用它。然后,您可以使用。wird…,在新保险存储的PayPal支付方式上设置定期订阅。。。。所以你不需要价格?你只是说这是你和供应商之间的协议?然后提供商可以每月发送?@Justin yep,使用保险存储支付流时不需要该金额。完整的选项列表如下所示。您可以在中指定订阅的价格。谢谢!这很有帮助,同时也非常简单,我不知道我是怎么错过的。我想我只是在脑子里有了这个想法,我无法超越它。我给出了+50:)。谢谢
// 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.
});
}