Home > database >  RESOURCE_NOT_FOUND while creating Subscription Api response in PayPal in JavaScript
RESOURCE_NOT_FOUND while creating Subscription Api response in PayPal in JavaScript

Time:07-20

I am using PayPal payment integration in my code.

I have created a product and plan in PayPal account and I want to use PayPal monthly/yearly subscription buttons.

I copied code from PayPal developer site and put in my code but it is not working.

error

Below is my code

    <script>
  paypal.Buttons({
      style: {
          shape: 'rect',
          color: 'gold',
          layout: 'vertical',
          label: 'subscribe'
      },
      createSubscription: function(data, actions) {
        return actions.subscription.create({
          /* Creates the subscription */
          plan_id: 'P-XXXX7066V2124102XXXXXX'
        });
      },
      onApprove: function(data, actions) {
        alert(data.subscriptionID); // You can add optional success message for the subscriber here
      }
  }).render('#paypal-button-container-P-7L763248U6625362UMLLHPYQ'); // Renders the PayPal button
</script>

Thanks in advance.

CodePudding user response:

The most likely explanation for a RESOURCE_NOT_FOUND error is if your plan_id does not correspond to (was not created under/using) the client id the SDK is loaded with.

In particular, from the error it's evident you're using a client id from the sandbox environment. This means that you need to be able to find that plan id by logging into the sandbox environment using the sandbox business account that corresponds to the sandbox mode app with the client_id you are using.

If the plan_id cannot be found within that client_id's sandbox account, and especially if you are mixing a plan_id from the live environment with a sandbox client_id (the two environments are completely separate), RESOURCE_NOT_FOUND is the expected error.


If that isn't enough to resolve your issue, your question needs to be specific about which exact plan_id and client id you are using, to test their correspondence.

  • Related