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 Code
@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 Code
<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>