billing-plans REST API newb

dmayo2
Contributor
Contributor

I've been searching the forums here, and over on stackoverflow, etc. to no avail. (plus there are not many posts/answers that are newer than 2+ years)

 

My goal is to offer a monthly subscription. Just one type. Many users subscribing to the same subscription, getting the same digital service.

 

If I understand the docs correctly, the steps are (https://developer.paypal.com/docs/integration/direct/billing-plans-and-agreements/#integration-steps...😞

1). Create a Billing Plan (name, how often charged, how much, trial period, currency type, etc). This is is just done once with a PUT. The response is an ID that refers to the subscription plan.

2). Then you use that ID with a PATCH to activate the plan.

3). Each new subscriber needs to See to the plan, which the REST is a POST with the plan_id, who the payer/subscriber is, etc.

4). Then this new subscriber needs to Approve and Subscribe to the plan, (and to be charged on the monthly recurring schedule for agreed upon amount, etc).

5). Finally, me/site/code needs to Execute the agreement with a POST.

 

So, in developer.paypal.com I've set up an REST API app under My Apps & Credentials.

The result gave me a Sandbox account email, Client ID, and Secret.

 

I'm working in Postman app on macOS (even the paypal docs suggest using cURL or Postman).  And there are two steps to set up Postman to accomplish Step 1 above (Create a Billing Plan).

 

1A. I set up a POST to `https://api.sandbox.paypal.com/v1/oauth2/token` per the directions (https://developer.paypal.com/docs/api/overview/#authentication-and-authorization)

  • Authorization tab: Type=Basic Auth; Username=Sandbox ClientID; Password=Sandbox Secret
  • Headers tab (key:value): Authorization:[auto-filled]; Content-Type:application/x-www-form-urlencoded

In Postman I then click Send, and I get a return from paypal in JSON format (as expected):

{
    "scope": "https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://uri.paypal.com/services/disputes/read-buyer https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/services/disputes/update-seller https://api.paypal.com/v1/vault/credit-card/.*",
    "nonce": "2018-04-03T22:22:18ZA3Jt70sbf_eWkN50mEkC5P0PnPMDpWVW...[redacted]",
    "access_token": "A21AAFlMnW5pVgD_YLzfdZgrz9lD-Ymln13jXGkiUBmSMTT5TGvETt65hxHKw9E3VMUzfg9j.....[redacted]",
    "token_type": "Bearer",
    "app_id": "APP-80W....[redacted]",
    "expires_in": 32400
}

1B. Now I use this JSON response in another Postman tab with a POST going to: https://api.sandbox.paypal.com/v1/payments/billing-plans per the directions (https://developer.paypal.com/docs/api/payments.billing-plans#billing-plans)

  • Authorization tab: Type: Bearer Token
  • Token: The JSON response from above 1A.

and on the Headers tab (key:value):

  • Authorization: Bearer{...} [temporary header created by Postman from the Authorization tab]
  • Content-Type: application/json

and in the body my Billing Plan that will generate a unique_id to use for reference when subscribers signup for my digital service.

{
    "name": "Basic Monthly Subscription",
    "description": "Monthly subscription fee for services",
    "type": "INFINITE",
    "payment_definitions": [
        {
            "name": "Trial payment",
            "type": "TRIAL",
            "frequency_interval": "1",
            "frequency": "MONTH",
            "cycles": 1,
            "amount": {
                "currency": "USD",
                "value": "0"
            }
        },
        {
            "name": "Monthly payment",
            "type": "INFINITE",
            "frequency": "MONTH",
            "frequency_interval": "2",
            "amount": {
                "currency": "USD",
                "value": "2"
            },
            "cycles": "0"
        }
    ],
    "merchant_preferences": {
        "setup_fee": {
            "value": "0",
            "currency": "USD"
        },
        "return_url": "https://example.com/profile/success",
        "cancel_url": "https://example.com/profile/cancel",
        "auto_bill_amount": "YES",
        "initial_fail_amount_action": "CONTINUE",
        "max_fail_attempts": "0"
    }
}

ISSUE

I can't get any response from paypal. No error, no nothin'. The only thing I can see is that in the oauth2 response, there is a SCOPE key with the values:

"scope": "https://uri.paypal.com/services/disputes/read-seller 
https://uri.paypal.com/services/subscriptions
https://api.paypal.com/v1/payments/.*
https://uri.paypal.com/services/disputes/read-buyer
https://api.paypal.com/v1/vault/credit-card
https://uri.paypal.com/services/applications/webhooks
openid
https://uri.paypal.com/services/disputes/update-seller
https://api.paypal.com/v1/vault/credit-card/.*
",

 I would like to make sure that I'm getting the correct SCOPE. In this list I do not see a URI for the sandbox. Would this cause a no response from paypal?

Also, the third URI is https://api.paypal.com/v1/payments/.*

Not sure on the format here, but not sure why that dot is there with the star/wildcard. Shouldn't it be .../payments/* ? (regardless I believe because it's not a SANDBOX URI.

 

Any ideas or help? Thanks.

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

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