Reputation: 1502
I was able to create a subscription button with the code below:
<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?client-id=client_id&vault=true" data-sdk-integration-source="button-factory"></script>
<script>
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'subscribe'
},
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'P-xxxx'
});
},
onApprove: function(data, actions) {
alert('You have successfully created subscription ' + data.subscriptionID);
console.log(data);
}
}).render('#paypal-button-container');
</script>
I was able to test it and it worked fine once I figured out that to test it you have to create a sandbox app at https://developer.paypal.com/developer/applications/ and use that for the client_id and then login with the sandbox facilitator account at https://www.sandbox.paypal.com and create a sandbox paypal subscription button by going to Pay & Get Paid > Subscriptions > Subscription Plans or https://www.paypal.com/billing/plans and "Create Plan" and use that for the plan_id.
After I tested the subscription button by purchasing it with the sandbox buyer account I was then able to check the status of the subscription online at https://www.sandbox.paypal.com/billing/subscriptions using the sandbox facilitator account.
But I do not see a way to check the status of a subscription using the subscription ID and the JavaScript SDK. How do you do that?
Upvotes: 0
Views: 1001
Reputation: 30359
The JavaScript SDK is for the web approval, not for things like checking the status.
For this you use the Subscriptions API. Here's the overview documentation: https://developer.paypal.com/docs/subscriptions/
In particular you want to get the details of a subscription: https://developer.paypal.com/docs/subscriptions/full-integration/subscription-management/#show-subscription-details
curl -v -X GET https://api.sandbox.paypal.com/v1/billing/subscriptions/I-######### \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Access-Token>"
Since you'll be using server code for such a check anyway, you may be interested in a server implementation which is more robust, since you are immediately informed on the server side of when a subscription becomes active.
Upvotes: 1