Tag Archives: paypal rest api

JSON for Creating Paypal Subscription Plan

Hope this save some time for someone.

The concept is for each products there will be one or more subscription plan. End users will be presented with the Subscription plans. And they will buy the subscription.

The subscription plans can be created from both Paypal Dashboard and using REST API. Here is the REST API method.

Request URL
https://api-m.paypal.com/v1/billing/plans/

Method
Post

Header
Authorization:  Bearer A3xxxxxxxxxxr-LXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXcOFiuF7__PXXXXXXXXXXXXX_YuJNIHYHGTJG
PayPal-Request-Id: TEST-REQ-ID-12345       —-  This is optional. Passing this will make consequent requests work on same initial Request. Better to omit it.

BODY

{
  "product_id": "PRODCUCT ID OF CORRESPONDING PRODUCT",
  "name": "THE NAME of Subscription Plan GOES HERE",
  "description": "THE DESCRIPTION Subscription Plan GOES HERE",
  "billing_cycles": [
    {
      "frequency": {
        "interval_unit": "MONTH",
        "interval_count": 1
      },
      "tenure_type": "REGULAR",
      "sequence": 1,    //sequence is important when there are trials. Trials will be 1 and regular packages can be 2 onwards.
      "total_cycles": 0,  // 0 means unlimited
      "pricing_scheme": {
        "fixed_price": {
          "value": "1.99",
          "currency_code": "USD"
        }
      }
    }
  ],
  "payment_preferences": {
    "auto_bill_outstanding": true,
    "setup_fee": {
      "value": "0",
      "currency_code": "USD"
    },
    "setup_fee_failure_action": "CONTINUE",
    "payment_failure_threshold": 1
  },
  "taxes": {
    "percentage": "0",
    "inclusive": false
  }
}

Return

This will return the auto-generated Plan-ID. The plan id will be needed for integration in frontend.
The Plan-ID can also be found from the Paypal Dashboard's subscription section.

 

How to get Token with Paypal Rest API

How to create products with Paypal Rest API

Paypal REST API create products

Request URL
https://api-m.paypal.com/v1/catalogs/products

Method: Post

Header
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  // xxxxxxxxxxxxxxxx  is base64 encoded Client ID:Secret  // base64_encode(client_id_string:client_secret_string) – note the colon in between
PayPal-Request-Id:TEST-REQ-ID-12345       —-  This is optional. Passing this will make consequent requests work on same initial Request. Better to omit it.

Body

{
  "id": "YOUR OWN PRODUCT ID",
  "name": "NAME",
  "status": "ACTIVE",
  "description": "DESCRIPTION GOES HERE",
  "type":"DIGITAL", //SUITABLE TYPE
  "category":"SOFTWARE",  //SUITABLE CATEGORY
  "home_url":"YOUR WEBSITE PAGE - WHERE DETAILS OF PRODUCT IS THERE"
}

Return
The call will return the same details on success

Paypal REST API get token

Request URL
https://api-m.paypal.com/v1/oauth2/token

Method
Post

Headers
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  // xxxxxxxxxxxxxxxx  is base64 encoded Client ID:Secret  // base64_encode(client_id_string:client_secret_string) – note the colon in between

Body
grant_type:client_credentials

Return

{

"scope": "https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/payment/authcapture openid https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/applications/webhooks",
"access_token": "AYYYYYYYYYYWmTopNAjV__Yuk_6AP9RZWQpzxxxxxxxxxxxxxx1ifvHLHrE6RW_Zqjbieo3jcZr9999999999999999lyDA",
"token_type": "Bearer",
"app_id": "APP-XYXYXYXYXYXYCCCC",
"expires_in": 32400,
"nonce": "2021-06-18T16:42:YUKJUKJHTGTYJKHGRRFHFHFGFGBFBG-spy-N9iguUHTJbTgVjht"

}