Skip to content

Commit

Permalink
fix: paypal redirect to only happen once
Browse files Browse the repository at this point in the history
  • Loading branch information
bdizha committed Jul 8, 2024
1 parent 3a8fcbe commit f740dec
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/payment/checkout/Checkout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit f740dec

Please sign in to comment.