stripe / stripe-react-native

React Native library for Stripe.
https://stripe.dev/stripe-react-native
MIT License
1.29k stars 263 forks source link

Error Code Canceled: Leave app on standby after sometime like 10-15 min. click on pay after some process it return canceled error. #1687

Open IrzamTariq opened 4 months ago

IrzamTariq commented 4 months ago

Hi. Normally google and apple pay work fine. but sometime when I call handlePayment it doesn't open the apple or google pay modal and return error.message The payment has been canceled. Mostly in apple pay.

one scenario that I figure out is that If I leave app open in standby condition for 10-15 min and then call the handlePayment Method it return "canceled" error code. and if I again click on pay button and call the handlePayment then it will work fine.

const handlePayment = async () => { const clientSecret = await api.getClientSecret({ amount: newTotalVal, venueId: venueId, });

  if (!clientSecret) {
    console.error('Failed to retrieve client secret');
    toastEvent('Failed to initiate payment');
    return;
  }

  let obj = {};
  if (Platform.OS === 'ios') {
    obj = {
      applePay: {
        cartItems: [
          {
            label: 'Platerate Order Charges',
            amount: total_price.toString(),
            paymentType: PlatformPay.PaymentType.Immediate,
          },
        ],
        merchantCountryCode: 'US',
        currencyCode: 'USD',
        requiredShippingAddressFields: [PlatformPay.ContactField.PostalAddress],
        requiredBillingContactFields: [PlatformPay.ContactField.PhoneNumber],
      },
    };
  } else if (Platform.OS === 'android') {
    obj = {
      googlePay: {
        merchantName: 'Platerate',
        merchantCountryCode: 'US',
        currencyCode: 'USD',
        billingAddressConfig: {
          format: PlatformPay.BillingAddressFormat.Full,
          isRequired: true,
        },
      },
    };
  }

  console.log('clientSecret>>>>obj', JSON.stringify(obj));
  const {error, paymentIntent} = await confirmPlatformPayPayment(
    clientSecret,
    obj,
  );

  if (error) {
    setLoader(false);
    console.log(
      `Something went wrong. You were not charged. ${
        error.localizedMessage
      } ${JSON.stringify(error)}`,
    );
    toastEvent(
      `Something went wrong. You were not charged. ${
        error.localizedMessage
      } ${JSON.stringify(error)}`,
    );
  } else {
    onSuccessfulPayment({paymentIntent});
    toastEvent('Payment Successful');
  }

}

rafaelmhp commented 3 weeks ago

Any news on this issue? I've been having the same problem.