Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onRedirect function is called twice #24

Closed
Kingswhale opened this issue Apr 27, 2021 · 2 comments
Closed

onRedirect function is called twice #24

Kingswhale opened this issue Apr 27, 2021 · 2 comments

Comments

@Kingswhale
Copy link

Kingswhale commented Apr 27, 2021

Kindly help me with this

<PayWithFlutterwave
onRedirect={this.onsuccess}
options={{
tx_ref: Date.parse(new Date()).toString(),
authorization: PUBLICKEY_FLUTTER,
customer: {
email: email.toString(),
phonenumber: phoneNumber.toString(),
name: userName.toString(),
},
amount: parseFloat(amount),
currency: 'NGN',
payment_options: 'card',
}} />

@thecodecafe
Copy link
Collaborator

Hello @Kingswhale, so sorry you're experiencing this, but I've been unable to reproduce from my end. Here's a trick you apply for now to resolve this on your end.
Debounce the redirect handler so that it only fires once, see the example below.

class YourComponent extends React.Component {
  ...
  redirectTimeout;
  ...
  onSuccess = (result) => {
    // clear timer
    clearTimeout(this.redirectTimeout);
    // set timer to handle result in 100ms
    this.redirectTimeout = setTimeoute(() => {
      // do something with the result
    }, 100);
  };
  ...
  render() {
    ...
    return (
      ...
      <PayWithFlutterwave
        onRedirect={this.onSuccess}
        options={{
        tx_ref: Date.parse(new Date()).toString(),
        authorization: PUBLICKEY_FLUTTER,
        customer: {
          email: email,
          phonenumber: phoneNumber,
          name: userName,
        },
        amount: amount,
        currency: 'NGN',
        payment_options: 'card',
        }}
      />
      ...
    );
  }
}

Please try this out and let me know if it solves your problem.
Thanks.

@thecodecafe
Copy link
Collaborator

This will be closed, please feel free to reopen if the proposed solution above does not suffice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants