6

I need to use PHP to count the number of active subscriptions in my PayPal account (people subscribed to my service, not the counts of services I'm subscribed to).

Does anyone know how to do this or can point me in the right direction?

I can't find any documentation that allows you to see a list of your active subscriptions via the API, but I'm assuming that PayPal has this option and I'm just missing it...

Chase
  • 139
  • 1
  • 8
  • It may be "List billing plans" in the paypal developer api guide: https://developer.paypal.com/docs/api/payments.billing-plans/v1/ – IncredibleHat Aug 12 '18 at 15:40
  • Hmm it looks like that may be it, PayPal makes it confusing because they have so many different names like Subscriptions, Billing Plans, Recurring Payments, Billing Agreements, etc. I'll post an update back here shortly about if that works or not. – Chase Aug 12 '18 at 15:44
  • 3
    Exactly :( ... and not only that, SOME of those are 'depreciated' ... making it even more confusing! I dread when I have to dig into the paypal api, or when things change... we've wasted so many man hours with paypal integrations lol. – IncredibleHat Aug 12 '18 at 15:45
  • Well it looks like billing-plans isn't what shows subscriptions :/ Any other ideas? – Chase Aug 12 '18 at 18:25

4 Answers4

5

This option cannot be found because it's apparently not available:

https://github.com/paypal/PayPal-REST-API-issues/issues/5

Chase
  • 139
  • 1
  • 8
4

Apparently you cannot get a list of subscriptions regardless the status for the time being, as you can see here https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions there is no such feature available so let's hope Paypal adds it in the future.

However if you are storing the subscription ids in a database then you can loop them and foreach subscription id you can get the details of the subscription https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get and check its status and finally display only the ones with an active status.

giannisrig
  • 61
  • 4
  • 3
    Absolute garbage. How much turnover does PayPal have per year? And yet they don't have simple full CRUD operations for each of their entities... – fullStackChris Feb 11 '22 at 07:37
1
https://www.paypal.com/billing/api/orchestrator/subscriptions?data=%7B%22total_required%22%3Atrue%2C%22sort_order%22%3A%22desc%22%2C%22page_size%22%3A%2220%22%2C%22page%22%3A%221%22%2C%22plan_ids%22%3A%22P-123456789ABCDE%22%2C%22statuses%22%3A%22ACTIVE%22%2C%22tab%22%3A%22all%22%7D

Just pass a query string like:

{"plan_ids":"P-123456789ABCDE","statuses":"ACTIVE"}

You can GET this, and specify a page size. It seems the max is 20, but you can change the page number too.

Change the plan_ids parameter that I have as "P-123456789ABCDE" to your plan ID and you'll get a JSON response. I'm sure this isn't advertised, but I found it digging through the PayPal site.

Amila Senadheera
  • 12,229
  • 15
  • 27
  • 43
Mark
  • 11
  • 1
  • 1
    Is this the same auth scheme as the normal API URLs that live at `https://api-m.sandbox.paypal.com` and `https://api-m.paypal.com`? I'm getting `NEEDS_LOGIN` errors, even with a valid token... – fullStackChris Feb 11 '22 at 09:00
0

There doesn't appear to be a direct way to list all of your subscriptions, but you can use the Transaction Search API to retrieve a list of your transactions (one month at a time, max 500 results per page) and grab the paypal_reference_id of each transaction object, which will be a valid subscription ID if the paypal_reference_id_type is "SUB".

Here's an example of the GET URL, which requires an Oauth token:

https://api-m.sandbox.paypal.com/v1/reporting/transactions?start_date=2022-07-01T00:00:00-0700&end_date=2022-07-31T23:59:59-0700&fields=all&page_size=500&page=1

Here's a simplified example of the response data:

{
    "transaction_details":
    [
        "transaction_info":
        {
            "paypal_reference_id": "I-ABCDEFGHIJKL",
            "paypal_reference_id_type": "SUB",
        }
    ]

}

Once you've retrieved all of your subscription IDs, you can use the Subscriptions API to retrieve their details (such as its status) via an authenticated GET request:

https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-ABCDEFGHIJKL

Here's a simplified example of the response data:

{
    "status": "ACTIVE",
}
Pikamander2
  • 7,332
  • 3
  • 48
  • 69