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

[FEATURE REQUEST] Support createSubscription Function #42

Closed lucashu1 closed 4 years ago

lucashu1 commented 4 years ago

Is your feature request related to a problem? Please describe. PayPal's checkout buttons support a createSubscription function for recurring payments. Currently, the PayPalButton component in this repo does not support the createSubscription function. It only supports createOrder, for one-time payments.

Describe the solution you'd like Allow the PayPalButton component to take in a createSubscription prop that then gets passed into PayPal's button component. The user should be able to pass in createSubscription or createOrder as a prop to the button component, but not both.

Describe alternatives you've considered

  1. I tried passing in createSubscription (instead of createOrder) as a prop to this repo's PayPalButton component. This didn't work, because the PayPalButton component does not accept createSubscription as a prop.
  2. I tried using the regular createOrder function, but calling actions.subscription.create() instead of actions.order.create(). This didn't work, because the action object that gets passed into createOrder does not support the actions.subscription.create() function.

Additional context See more information about the createSubscription function here: https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription.

You should be able to pass in createSubscription like so:

  createSubscription: function(data, actions) {
    return actions.subscription.create({
      'plan_id': 'P-2UF78835G6983425GLSM44MA'
    });
  },

  onApprove: function(data, actions) {
    alert('You have successfully created subscription ' + data.subscriptionID);
  }
lucashu1 commented 4 years ago

I'm happy to put in a PR for this if you'd like, @Luehang!

Luehang commented 4 years ago

Hi,

There has been an update for that recently.

Type in the following to the command line to update the package.

$ npm install react-paypal-button-v2@2.6.0 --save

or

$ yarn add react-paypal-button-v2@2.6.0

And follow the section for Subscription Example.