Error using PayPal subscription with Multiple Subscription buttons

24 Views Asked by At

Using sandbox code given in PayPal document 'Multiple Subscription buttons' I got many errors, the first being: Failed to load resource: the server responded with a status of 404 () related to https://www.sandbox.paypal.com/v1/billing/subscriptions.

I checked that al info regarding client ID and plan IDs were accurate, but the problem persists.

This is the code for my checkout:

<script
  src="https://www.paypal.com/sdk/js?client-id=ID">
</script>

<div class="row">
  <div class="col-sm-3">
    <p>
      PLAN 1<br />$70 {% translate 'per year' %}
    </p>
    <div id="paypal-button-container-P-XXX"></div>

  <script>
    paypal.Buttons({
      createSubscription: function (data, actions) {
        return actions.subscription.create({
          'plan_id': 'P-XXX' // Replace with your plan ID
        }).then(function (response) {
          // Subscription created successfully
          console.log('Subscription created:', response);
          // Handle any further actions like redirecting user or updating UI
        }).catch(function (error) {
          // Subscription creation failed
          console.error('Subscription creation failed:', error);
          // Handle error, display message to user, etc.
        });
      },
      onApprove: function (data, actions) {
        alert('You have successfully subscribed to ' + data.subscriptionID); // Optional message given to subscriber
      }
    }).render('#paypal-button-container-P-XXX'); // Renders the PayPal button. Replace with your plan ID
  </script>

  <div class="col-sm-3">
    <p>
      PLAN 2<br />$7 {% translate 'per month' %}
    </p>
    <div id="paypal-button-container-P-YYY"></div> <!-- Replace with your plan ID -->
  </div>

  <script>
    paypal.Buttons({
      createSubscription: function (data, actions) {
        return actions.subscription.create({
          'plan_id': 'P-YYY' // Replace with your plan ID
        }).then(function (response) {
          // Subscription created successfully
          console.log('Subscription created:', response);
          // Handle any further actions like redirecting user or updating UI
        }).catch(function (error) {
          // Subscription creation failed
          console.error('Subscription creation failed:', error);
          // Handle error, display message to user, etc.
        });
      },
      onApprove: function (data, actions) {
        alert('You have successfully subscribed to ' + data.subscriptionID); // Optional message given to subscriber
      }
    }).render('#paypal-button-container-P-YYY'); // Replace with your plan ID
  </script>
</div>
1

There are 1 best solutions below

0
Preston PHX On

Impossible to be of specific help with how little information there is in the question, but general advice:

  • Obtain buttons from a single sandbox (or live) account, via https://www.sandbox.paypal.com/billing/plans . Do not mix buttons from different accounts/apps on the same page.
  • Only load the JS SDK once per page, before the first button. Remove additional <script src="https://www.paypal.com/sdk/js?.....</script> elements from all but before the first button. As an extra check, when removing them verify that the client-id= value was the same for all. (It should be the same, or that button is problematic and you should generate a new one and replace it)