I need to implement a system in which users will have a trial period in their subscription and after that period the user should resume their subscription, I have achieved the same but when a user needs to be deleted the subscription has to be terminated for that when i researched I got an API to cancel a subscription via
https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEG1P/cancel
where I-BW452GLLEG1P in the above is the subscription id, but I don't get a subscription id when I create a subscription via the method suggested on the reference page
https://developer.paypal.com/docs/business/subscriptions/customize/trial-period/
please share your thoughts if you encountered similar issues thanks
The page you reference is to create a plan. Plans are then used to create subscriptions.
To create a subscription using a plan, you can use an API call or a JS button. The JS button is generally best since you need a buyer to approve the subscription anyway for it to be useful.
The documentation for creating a button is at https://developer.paypal.com/docs/business/subscriptions/integrate/#3-create-payment-button
Here is the relevant HTML/JS from there.
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID&vault=true&intent=subscription">
</script> // Add your client_id
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'YOUR_PLAN_ID' // Creates the subscription
});
},
onApprove: function(data, actions) {
alert('You have successfully created subscription ' + data.subscriptionID); // Optional message given to subscriber
}
}).render('#paypal-button-container'); // Renders the PayPal button
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.