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

[BUG] onSuccess cancels onApprove #78

Open shwao opened 4 years ago

shwao commented 4 years ago

I discovered that if you specifiy onSuccess, onApprove will not be called. At least this is what is happening for me. I found this part in the code that i dont fully understand. https://github.com/Luehang/react-paypal-button-v2/blob/d819579f77723d2a361476e41e231708a6b8c01c/src/index.tsx#L198 But i think without this ternary:

onApprove={
   onSuccess
     ? (data: any, actions: any) => this.onApprove(data, actions)
     : (data: any, actions: any) => onApprove(data, actions)
}

It would work:

onApprove={ (data: any, actions: any) => onApprove(data, actions) }
danlupascu commented 4 years ago

It's an issue, but you don't need the onSuccess function if you provide the onApprove function. Just do whatever you want to do inside the onApprove function.

Anyway, it's a bug and it should be fixed or mentioned in README.md because it's confusing.

tsafs commented 3 years ago

Yes, it should be mentioned in the README.md, especially for beginners implementing paypal the first time. I stumbled over this as well.