From f740dec75167e7f7c74fa8b70ab176c72c4f45de Mon Sep 17 00:00:00 2001 From: Batanayi Matuku Date: Mon, 8 Jul 2024 21:32:56 +0200 Subject: [PATCH] fix: paypal redirect to only happen once --- src/payment/checkout/Checkout.jsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/payment/checkout/Checkout.jsx b/src/payment/checkout/Checkout.jsx index e06604b9a..04f63c32a 100644 --- a/src/payment/checkout/Checkout.jsx +++ b/src/payment/checkout/Checkout.jsx @@ -26,17 +26,24 @@ import { PayPalButton } from '../payment-methods/paypal'; import { ORDER_TYPES } from '../data/constants'; class Checkout extends React.Component { + constructor(props) { + super(props); + this.state = { + hasRedirectedToPaypal: false, + }; + } + componentDidMount() { this.props.fetchClientSecret(); - this.handleRedirectToPaypal(); } handleRedirectToPaypal = () => { const { loading, isBasketProcessing, isPaypalRedirect } = this.props; + const { hasRedirectedToPaypal } = this.state; const submissionDisabled = loading || isBasketProcessing; - if (!submissionDisabled && isPaypalRedirect) { - // auto submit to paypal since the paypal redirect flag is set in the incoming request + if (!submissionDisabled && isPaypalRedirect && !hasRedirectedToPaypal) { + this.setState({ hasRedirectedToPaypal: true }); this.handleSubmitPayPal(); } }; @@ -172,6 +179,8 @@ class Checkout extends React.Component { const isBulkOrder = orderType === ORDER_TYPES.BULK_ENROLLMENT; const isQuantityUpdating = isBasketProcessing && loaded; + this.handleRedirectToPaypal(); + // Stripe element config // TODO: Move these to a better home const options = {