Using the Subscriptions API

Robotuner
Contributor
Contributor

I am attemting to use the paypal subscription api. But am not sure I understand how everything is wired up.

Under my paypal account, I selected Pay & Get Paid/Subscriptions and created a product. There is a subscription plan and product id for it.
MyProduct
Product Id: Guid <== assume it is:  F1AF6C22953D4208AC9194C54395C558

When I navigate to the developer dashboard/My Apps & Credentials,
I have created a SandBox App
      MySubsubscriptionAPP

Selecting the MySubscriptionAPP brings me to a page where I am presented with
Sandbox Account : emailaccountId
ClientId: <ClientId>
Secret: <ClientSecret>

I then proceed to https://developer.paypal.com/docs/api/overview/
Where I use Postman to retrieve an access token.  

   I am able to retrieve an access_token so now I'm trying to become familiar with the API.

It is here that everything stops working.
On the same page,  in the subscription API section, I am attempting to retrieve the plan that I created using Postman:
get https://api-m.sandbox.paypal.com/v1/billing/plans
body is:
{
"product_id" : "F1AF6C22953D4208AC9194C54395C558",
"plan_ids": 3,
"page_size": 10,
"page": 1,
"total_required": true
}

The result is:
{
    "plans": [],
    "links": [
      {
         "href": "https://api.sandbox.paypal.com/v1/billing/plans?page_size=10&page=1",
         "rel": "self",
         "method": "GET",
         "encType": "application/json"
      }
    ]
}

It is not returning my Subscription Plan.

At this point, I am thinking that I need to create a sandbox subscription so I attempt to create a subscription:
post https://api-m.sandbox.paypal.com/v1/billing/plans
the body is using a different guid for the product Id.
{
"product_id": "22C4AD7B18864C9E8DEF391269444741",
"name": "My Product Subscription",
"status": "Active",
"description": "Fixed price yearly subscription",
"plan_id": "F1AF6C22953D4208AC9194C54395C558",
"billing_cycles": [
{
"frequency": {
"interval_unit": "DAY",
"interval_count": 15
},
"tenure_type": "TRIAL",
"sequence": 1,
"total_cycles": 1,
"pricing_scheme": {
"fixed_price": {
"value": "0",
"currency_code": "USD"
}
}
},
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 2,
"total_cycles": 36,
"pricing_scheme": {
"fixed_price": {
"value": "250",
"currency_code": "USD"
}
}
}
],
"payment_preferences": {
"auto_bill_outstanding": true,
"setup_fee": {
"value": "0",
"currency_code": "USD"
},
"setup_fee_failure_action": "CONTINUE",
"payment_failure_threshold": 3
},
"taxes": {
"percentage": "0",
"inclusive": false
}
}

The result is:
{
"name": "INVALID_REQUEST",
"message": "Request is not well-formed, syntactically incorrect, or violates schema.",
"debug_id": "738311a82933f",
"details": [
{
"field": "/plan_id",
"value": "F1AF6C22953D4208AC9194C54395C558",
"location": "body",
"issue": "INVALID_PARAMETER_SYNTAX",
"description": "The value of a field does not conform to the expected format."
}
],
"links": [
{
"href": "https://developer.paypal.com/docs/api/v1/billing/subscriptions#INVALID_REQUEST",
"rel": "information_link",
"method": "GET"
}
]
}

It seems that I am not understanding something. My questions are two fold.
1. Should I be able to get the plan I created in my paypal account in the sandbox?
2. If I want to create a sandbox Subscription plan, what do I use for the plan_id and product_id?

 

My end goal is to allow a user to subscribe to the Paypal subscription plan, and have my application query the subscription database with the users account id to determine if the subscription is active.

 

 

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

MTS-Aaron
PayPal Employee
PayPal Employee

Hi @Robotuner 

 

Okay, so choose which one of those merchant sandbox accounts you want to use. Make sure that the "Rest App" that you created coincides with that Sandbox account that you're choosing to use. Each app is linked to one of those sandbox accounts. Select the "..." and View/Edit Account. From there, you'll see the email and the password for that account. Take that and login to Sandbox.PayPal.com. Once you've done that, go to "Pay & Get Paid" and select "Subscriptions". From there, you can create a plan and create a product to link to that plan.

 

I hope that helps clarify where I was referring to with the Subscriptions dashboard.

-Aaron

View solution in original post

Login to Me Too
5 REPLIES 5

MTS-Aaron
PayPal Employee
PayPal Employee

Hi @Robotuner 

 

So, it looks like you may be getting your Plan ID and your Product ID mixed up. You can view your plan ID by looking at your "Plans" in the subscriptions section of the sandbox account. To view a product (and its ID), you can go into that plan and then select the name of the product. From there you'll see a Product ID which can be used.

 

Plan IDs should always start with "P-" followed by a succession of characters. I think this might be why you got the "Invalid Syntax" on that last request. For the first request, reference this documentation. Make sure you've got your Product ID right, then try something barebones like this: GET to https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=PROD-XXCD1234QWER65782&

 

I hope that helps!

-Aaron

Login to Me Too

Robotuner
Contributor
Contributor

Hi Aaron:

I must be looking at the wrong place.
If I go to my Dashboard, then select SANDBOX/Accounts, I am moved to the
Sandbox test accounts Page.

 

There are currently two personal accounts and one business account. They are all marked DEFAULT.

None of the accounts are selectable. They all have a ... under the Manage accounts column, but that only allows me to edit or duplicate the account or view notifications.

 

Aside from that, there are no "Plans" in the subscription section of the sandbox account, there is also no subscription section of the sandbox account.

 

Where should I be looking?

Login to Me Too
Solved

MTS-Aaron
PayPal Employee
PayPal Employee

Hi @Robotuner 

 

Okay, so choose which one of those merchant sandbox accounts you want to use. Make sure that the "Rest App" that you created coincides with that Sandbox account that you're choosing to use. Each app is linked to one of those sandbox accounts. Select the "..." and View/Edit Account. From there, you'll see the email and the password for that account. Take that and login to Sandbox.PayPal.com. Once you've done that, go to "Pay & Get Paid" and select "Subscriptions". From there, you can create a plan and create a product to link to that plan.

 

I hope that helps clarify where I was referring to with the Subscriptions dashboard.

-Aaron

Login to Me Too

Robotuner
Contributor
Contributor

Aaron:

 

Thanks.  I did not link the test app that I created to the correct sandbox account.  I am now able to get the detailed plan info from Postman.   I will not move on the the subscriptions.

Login to Me Too

diptigajjar
Contributor
Contributor

How did you resolved it? I'm facing the same issue. I have created the product, plan, and subscription via postman api in sandbox account but that is not showing up on sandbox dashboard. 

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.