Search code examples
pythonpaypalpaypal-sandbox

Paypal give me a Required scope missing error when creating billing plan


I'm now putting a paypal subscription button on my site using python paypal-sdk

To subscribe payment, I'm following these steps.

  1. create billing plan
  2. activate it
  3. create billing agreement
  4. execute it.

But creating billing plan has been failed and sent me REQUIRED SCOPE MISSING error. I copied billing plan arguments from paypal official dev site. So I don't think I missed something on request.

Here is my code to create billing plan

billing_plan = paypalrestsdk.BillingPlan({
  "name": "T-Shirt of the Month Club Plan",
  "description": "Monthly plan for getting the t-shirt of the month.",
  "type": "fixed",
  "payment_definitions": [
    {
      "name": "Trial Plan",
      "type": "TRIAL",
      "frequency_interval": "1",
      "frequency": "MONTH",
      "cycles": "1",
      "amount": {
        "currency": "USD",
        "value": "9.99"
      },
      "charge_models": [
        {
          "type": "TAX",
          "amount": {
            "currency": "USD",
            "value": "1.65"
          }
        },
        {
          "type": "SHIPPING",
          "amount": {
            "currency": "USD",
            "value": "9.99"
          }
        }
      ]
    },
    {
      "name": "Standard Plan",
      "type": "REGULAR",
      "frequency_interval": "1",
      "frequency": "MONTH",
      "cycles": "11",
      "amount": {
        "currency": "USD",
        "value": "19.99"
      },
      "charge_models": [
        {
          "type": "TAX",
          "amount": {
            "currency": "USD",
            "value": "2.47"
          }
        },
        {
          "type": "SHIPPING",
          "amount": {
            "currency": "USD",
            "value": "9.99"
          }
        }
      ]
    }
  ],
  "merchant_preferences": {
    "setup_fee": {
        "currency": "USD",
        "value": "1"
    },
    "cancel_url": "http://www.cancel.com",
    "return_url": "http://www.return.com",
    "max_fail_attempts": "0",
    "auto_bill_amount": "YES",
    "initial_fail_amount_action": "CONTINUE"
  }
})
if billing_plan.create():
  return billing_plan.id

and here is my configuration for paypal

PAYPAL_CONF = {
  'mode': 'sandbox',
  'client_id': CLIENT_ID_IN_SANDBOX_ACCOUNT,
  'client_secret': SECRET_IN_SANDBOX_ACCOUNT,
}

paypalrestsdk.configure(settings.PAYPAL_CONF)

and error message

ForbiddenAccess: Failed. Response status: 403. Response message: Forbidden. Error message: {"name":"REQUIRED_SCOPE_MISSING","message":"Access token does not have required scope","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#REQUIRED_SCOPE_MISSING","debug_id":"bf845229ca125"}

I've searched a few of articles, but no luck.

EDIT: I've tried about app settings, but the problem is different.


Solution

  • My co-worker solved this for me. Actually I'm using default sandbox facilitator app which paypal created for me. You can access those app like this. (*it doesn't show apps on Dashboard)

    sandbox > accounts > account-facilitator > profile > API credentials tab > apps

    But It wasn't working. So he made a new app using Dashboard > My Apps & credencials > create app(sandbox) and replaced client id and secret of new one.

    It works like magic.

    ps. When I was struggling with it, I found @tamak's comment. "gave me a really weird feeling about using paypal at all to be honest." in https://stackoverflow.com/a/26393932/4476298

    SO TRUE.