Stripe 0.19.0 presentApplePay() & confirmApplePayPayment() fails - no longer supported must update to sdk 48 for Stripe 0.23.3

Expo SDK Version: 47
Platforms: iOS
React Native: 0.70.5

I’m having issues using useApplePay, presentApplePay and confirmApplePayPayment.

I’m using "@stripe/stripe-react-native": "0.19.0", however the latest is 0.25.0. I’ve tried both versions of the SDK/

My code, using Stripe SDK 0.19.0:

  • the Apple pay dialogue opens
  • after face authorization or passcode, the payment begins processing.
  • processing never completed, "Payment The payment has been canceled" appears in BugSnag
  • no JS error or detailed error message from presentApplePay()
  • No errors in Stripe’s logs
  • createPaymentSecret() is the api request to Stripe’s servers for a payment secret. This appears on Stripe’s logs.
const { confirmApplePayPayment, presentApplePay } = useApplePay();
const handlePress = async () => {
  const {
    data: { response },
  } = await createPaymentSecret({
    amount: Number(amount) * 100, // bc this is in cents not dollars
  });
  const clientSecret = response;
  const { paymentMethod, error } = await presentApplePay({
    currency: 'usd',
    country: 'US',
    cartItems: [{ paymentType: 'Immediate', label: applePayLabel, amount }],
  });

// The request fails here without details of what the issue is

  if (!error) {
    const { error: confirmApplePayError } = await confirmApplePayPayment(
      clientSecret,
    );
    if (confirmApplePayError) {
      Bugsnag.notify(confirmApplePayError.message);
    } else {
      console.log('Success', 'The payment was confirmed successfully!');
    }
  } else {
    Bugsnag.notify(`Present Apple Pay Error: ${error}`);
  }
};

“Latest” Stripe SDK 0.25.0 using confirmPlatformPayPayment():

References:

Results:

  • Apple pay dialogue does not appear
  • No errors. Nothing happens
const { confirmPlatformPayPayment } = usePlatformPay();

const handlePress = async () => {
  const {
    data: { response },
  } = await createPaymentSecret({
    amount: Number(amount) * 100,
  });
  const clientSecret = response;
  const { paymentIntent, error } = await confirmPlatformPayPayment(
    clientSecret,
    {
      applePay: {
        merchantCountryCode: 'US',
        currencyCode: 'usd',
        cartItems: [
          {
            paymentType: PlatformPay.PaymentType.Immediate,
            label: applePayLabel,
            amount,
          },
        ],
      },
    },
  );
  if (!error) {
    console.log('Success', 'The payment was confirmed successfully!');
  } else {
    Bugsnag.notify(`Present Apple Pay Error: ${error}`);
  }
};

Appears that Expo with Stripe, is not working as expected. Since Stripe’s API seems to have deprecated, does that make Expo’s implementation obsolete? If so, what alternative solutions are there to collecting Apple Pay payments?

Solution:
You need to upgrade to Expo SDK 48, which uses Stripe 0.23.3. Stripe in Expo is no longer supported below that version.

This is the snippet that should help you implement this in production.

const { confirmPlatformPayPayment } = usePlatformPay();

const handlePress = useCallback(async () => {
  const {
    data: { response },
  } = await createPaymentSecret({ // [an api request for the secret](https://stripe.com/docs/apple-pay?platform=react-native#handle-payment)
    variables: {
      amount: Number(amount) * 100, // it's in pennies
    },
  });
  const clientSecret = response;
  const { paymentIntent, error } = await confirmPlatformPayPayment(
    clientSecret,
    {
      applePay: {
        merchantCountryCode: 'US',
        currencyCode: 'usd',
        cartItems: [
          {
            paymentType: PlatformPay.PaymentType.Immediate,
            label: applePayLabel,
            amount,
          },
        ],
      },
    },
  );
  if (!error) {
    console.log('Success', 'The payment was confirmed successfully!');
  } else {
    Bugsnag.notify(`Apple Pay Error: ${error}`);
  }
}, [confirmPlatformPayPayment]);

More information can be found in this Github issue.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.