Subscription and Plan ID : RESOURCE NOT FOUND

AW73
Contributor
Contributor

Hello

 

I'm using a Sandbox and I created a paypal plan with Paypal PHP SDK and activated it.

 

 

 

// Paypal plan definition
$plan = new Plan();

$plan->setName('A plan title');
$plan->setDescription('The plan description');
$plan->setType('fixed');

// paypal trial
$paymentDefinitionTrial = new PaymentDefinition();
$paymentDefinitionTrial->setName('7 free days');
$paymentDefinitionTrial->setType('TRIAL');
$paymentDefinitionTrial->setFrequency('Day');
$paymentDefinitionTrial->setFrequencyInterval(7);
$paymentDefinitionTrial->setCycles('1');
$paymentDefinitionTrial->setAmount(new Currency(array('value' => 0, 'currency' => 'EUR')));

// Paypal standard payment definition
$paymentDefinition = new PaymentDefinition();
$paymentDefinition->setName('Subscription');
$paymentDefinition->setType('REGULAR');
$paymentDefinition->setFrequency('Month');
$paymentDefinition->setFrequencyInterval('1');
$paymentDefinition->setCycles('12');
$paymentDefinition->setAmount(new Currency(array('value' => 30, 'currency' => 'EUR')));

// Array of the two payment definitions
$paymentDefinitions = array($paymentDefinitionTrial, $paymentDefinition);

// Paypal Merchant Preferences
$merchantPreferences = new MerchantPreferences();
$merchantPreferences->setReturnUrl(setUrlSchemeIfNotExist('<a href="https://mydomain.com/ExecuteAgreement.php?success=true" target="_blank">https://mydomain.com/ExecuteAgreement.php?success=true</a>'));
$merchantPreferences->setCancelUrl(setUrlSchemeIfNotExist('<a href="https://mydomain.com/ExecuteAgreement.php?success=false" target="_blank">https://mydomain.com/ExecuteAgreement.php?success=false</a>'));
$merchantPreferences->setAutoBillAmount('yes');
$merchantPreferences->setInitialFailAmountAction('CONTINUE');
$merchantPreferences->setMaxFailAttempts('0');

// Paypal Plan conf definition
$plan->setPaymentDefinitions($paymentDefinitions);
$plan->setMerchantPreferences($merchantPreferences);

// Plan creation
$request = clone $plan;

try {
  $output = $plan->create($paypalApiContext);
} catch (Exception $ex) {
  throw new WireException('Error from Paypal to create the Plan');
}

 

 

 

When I try to check if this Pla is OK, I used :

 

 

 

try {
      $plan = Plan::get('P-8N611293...11KKMN5MZI', $paypalApiContext);
  } catch (Exception $ex) {
      exit(1);
  }

 

 

And it's OK. The Plan is created and active :

 

paypal-planid.png

 

 

But, when I'm following the Paypal dev doc (https://developer.paypal.com/docs/checkout/integrate/#3-render-the-smart-payment-buttons) to create a subscription with Smart Button method, and I am cliquing on the yellow smart button I have a Javascript Error in the console :

 

 

 

Error: Create Subscription Api response error:

{
    "name": "RESOURCE_NOT_FOUND",
    "message": "The specified resource does not exist.",
    "debug_id": "23912dc1195d",
    "details": [
        {
            "issue": "INVALID_RESOURCE_ID",
            "description": "Requested resource ID was not found."
        }
    ],
    "links": [
        {
            "href": "<a href="https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID" target="_blank">https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID</a>",
            "rel": "information_link",
            "method": "GET"
        }
    ]
}

 

 

 

Here is the Javascript code used :

 

 

 

// paypal.Buttons().render('#paypal-button-container');

    paypal.Buttons({
      createSubscription: function(data, actions) {
        return actions.subscription.create({
          'plan_id': 'P-8N611293...11KKMN5MZI'
        });
      },
      onApprove: function(data, actions) {
        alert('You have successfully created subscription ' + data.subscriptionID);
      }
    }).render('#paypal-button-container');
  

 

 

 

In the paypal developer dashboard I see the API call for this action, but in orange...

 

paypalsandbox.png

 

I don't understand where is the error ! 

 

Thanks in advance for your help.

Login to Me Too
1 REPLY 1

IACM
New Community Member

I had the same problem. Probably you are loading the button script with "client-id=sb" or no client id specified. In order to work with plans you created via API you need to explicitly set "client-id=<client-id-of-your-REST-API-app>" when loading the script. Then the buttons will find your created plan. It took me a while to get that and this is nowhere documented.

 

2019-12-26 15_46_37.png 

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.