Manage subscriptions with REST API and handle errors

mpvieira
Contributor
Contributor

Hi,

I'm trying to manage subscriptions using the REST API based on this link https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription. To create and approve the subscription I first create a product and plan server side using the REST API and then give the user the paypal button experience: paypal.Buttons( ... createSubscription ... .render('#paypal-button-container');

 

The user is redirected to the paypal checkout and after approve the subscription, a callback function is called (onApprove) and back to my website.

 

With the returned information from paypal, I update my website with the subscription id and state, in case of an error, how do I obtain the subscription details if my website, somehow isn't able to record the subscription ID?

 

I have the plan informaiton because it is created server side with REST API calls but, I can't find relation between the plan id and the subscriptions. As soon as the user takes control and approves the subscription, if anything fails, I no longer can obtain the subscription state. 

 

Thank you 

Best regards

 

Login to Me Too
3 REPLIES 3

etherkye
Contributor
Contributor

This API command will return the subscription with the plan ID: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get

 

Also webhooks.

 

 

However there's no way to record custom data, so if the smart button fails then there's no way to know which user it was that signed up!

Login to Me Too

mpvieira
Contributor
Contributor

Hi, thank you for your quick reply.

I've tried to use the get method https://api.sandbox.paypal.com/v1/billing/subscriptions/P-56608679GK7201450LXJKKKQ where the id is the plan ID but with no success. Is this link correct?

I've obtained the following responde: 

{
    "name""INVALID_REQUEST",
    "message""Request is not well-formed, syntactically incorrect, or violates schema.",
    "debug_id""e6e630fddf120",
    "details": [
        {
            "field""",
            "value""P-56608679GK7201450LXJKKKQ",
            "location""query",
            "issue""INVALID_PARAMETER_SYNTAX",
            "description""The value of a field does not conform to the expected format."
        }
    ],
    "links": [
        {
            "rel""information_link",
            "method""GET"
        }
    ]
}
Login to Me Too

etherkye
Contributor
Contributor

No you give it the subscription ID to get the details of the subscription. That includes the plan ID.

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.