Luehang / react-paypal-button-v2

An easy and simple to use React button component to implement PayPal Checkout with Smart Payment Buttons V2 (Version 2).
https://luehangs.site/lue_hang/projects/react-paypal-button-v2
MIT License
273 stars 81 forks source link

[QUESTION] #59

Open cjohnweb opened 4 years ago

cjohnweb commented 4 years ago

Ask your Question Hi there, I'm trying to implement the react-paypal-button-v2 for paypal sandbox subscription. I think I've done it correctly and I've read all the docs I could find, I don't understand why I'm getting POST https://www.sandbox.paypal.com/v1/billing/subscriptions 404 (Not Found) shortly after clicking any of the paypal buttons that are rendered.

I may be wrong on this, but that notice This PayPal Checkout integration uses the PayPal JavaScript SDK. Starting at the beginning of February 2019, all new users must use PayPal's version 2 integration as version 1 is now depreciated. PayPal Checkout would not also include Subscriptions would it?

Here is my button, I've only changed the options object and of course I added my sandbox plan id.

I must be missing something.

Thanks for taking a look at this.

<PayPalButton
  options={{ vault: true, clientId: "sb", currency: "USD" }}
  createSubscription={(data, actions) => {
    return actions.subscription.create({
      plan_id: 'blah blah blah'
    });
  }}
  onApprove={(data, actions) => {
    // Capture the funds from the transaction
    return actions.subscription.get().then(function (details) {
      // Show a success message to your buyer
      alert("Subscription completed");

      // OPTIONAL: Call your server to save the subscription
      return fetch("/paypal-subscription-complete", {
        method: "post",
        body: JSON.stringify({
          orderID: data.orderID,
          subscriptionID: data.subscriptionID
        })
      });
    });
  }}
/>

Tags 404 paypal smart button sandbox api subscriptions

cjohnweb commented 4 years ago

Also found this https://www.paypal-community.com/t5/Sandbox-Environment/POST-https-www-sandbox-paypal-com-v1-billing-subscriptions-404/m-p/2067748

cjohnweb commented 4 years ago

Dug into the error more and found this:

{"name":"AUTHENTICATION_FAILURE","message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.","links":[{"href":"https://developer.paypal.com/docs/api/overview/#error","rel":"information_link"}]}

Am I supposed to provide an authentication token somewhere?