paypal / paypal-js

Loading wrapper and TypeScript types for the PayPal JS SDK
Apache License 2.0
229 stars 78 forks source link

[Bug] Bug report #559

Open grzkracol opened 3 weeks ago

grzkracol commented 3 weeks ago

Library used

@paypal/react-paypal-js, ver 8.1.3

🐞 Describe the Bug

In Mozilla Firefox(130.0) onClick event is raised after Paypal Popup window is opened.

πŸ”¬ Minimal Reproduction

Here's the example code we use in our system to render paypal buttons.

<PayPalScriptProvider
                    options={{
                        clientId: response.ClientId,
                        currency: response.Currency,
                    }}
                >
                    <PayPalButtons
                        style={{
                            layout: 'horizontal',
                            color: 'black',
                            height: 48,
                            shape: 'rect',
                            tagline: false,
                        }}
                        onApprove={(data, actions) =>
                            onApprove(
                                data,
                                actions,
                                response.PaymentProviderId
                            )
                        }
                        createOrder={() =>
                            createOrder(response.PaypalOrderId)
                        }
                        onClick={(data, actions) => {
                            if (window.validateAcceptTermsCheckbox()) {
                                return actions.resolve(data);
                            }
                            return actions.reject();
                        }}
                    />
                </PayPalScriptProvider>

This code works perfectly fine for Chrome and Edge browsers. But runs incorrectly for Firefox.

πŸ˜• Actual Behavior

Paypal modal window is opened, then (because window.validateAcceptTermsCheckbox() resolves to false) the popup is closed. That looks unprofessional.

πŸ€” Expected Behavior

onClick is fired before the popup is opened. So the code has a real chance to run some validation and decide whether to open the modal or not.

🌍 Environment

βž• Additional Context

Add any other context about the problem here.