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

initPaymentSheet error #461

Closed
katiachumakova opened this issue Jul 26, 2021 · 3 comments
Closed

initPaymentSheet error #461

katiachumakova opened this issue Jul 26, 2021 · 3 comments
Labels
need triage question Further information is requested

Comments

@katiachumakova
Copy link

Describe the bug
When using initPaymentSheet it always returns an error:

{code: "Failed", localizedMessage: "There was an unexpected error -- try again in a few seconds", message: "There was an unexpected error -- try again in a few seconds", declineCode: null, type: null, …}

Also getting the same error on presentPaymentSheet (if I use confirmPayment: false the Payment Sheet doesn't open at all, if I don't use it then it opens and closes automatically with the same error).

Using iOS, I haven't tested this on Android.

Versions

  • "react-native": "0.64.2"
  • "@stripe/stripe-react-native": "0.1.5"
@thorsten-stripe
Copy link
Contributor

Can you please double check that you're setting the correct parameters, e.g. could be this: #290 (comment)

If that doesn't resolve it, please provide your code.

@thorsten-stripe thorsten-stripe added need triage question Further information is requested labels Jul 27, 2021
@thorsten-stripe
Copy link
Contributor

Closing due to inactivity. Feel free to reopen with the above requested information.

@katiachumakova
Copy link
Author

katiachumakova commented Aug 31, 2021

Sorry for the late reply. Noup, didn't resolve it. My code is literally the example.

Server:

exports.paymentSheet = functions.https.onRequest(
  async (req, res) => {
  const customer = await stripe.customers.create();
  const ephemeralKey = await stripe.ephemeralKeys.create(
    {customer: customer.id},
    {apiVersion: '2020-08-27'}
  );
  const paymentIntent = await stripe.paymentIntents.create({
    amount: 1099,
    currency: 'usd',
    customer: customer.id,
  });
  res.json({
    paymentIntent: paymentIntent.client_secret,
    ephemeralKey: ephemeralKey.secret,
    customer: customer.id
  });
});

Client:

  const fetchPaymentSheetParams = async () => {
    const response = await fetch(`${API_URL}/paymentSheet`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
    });
    const {paymentIntent, ephemeralKey, customer} = await response.json();

    return {
      paymentIntent,
      ephemeralKey,
      customer,
    };
  };

  const initializePaymentSheet = async () => {
    const {paymentIntent, ephemeralKey, customer} =
      await fetchPaymentSheetParams();

    const {error, paymentOption} = await initPaymentSheet({
      customerId: customer,
      customerEphemeralKeySecret: ephemeralKey,
      paymentIntentClientSecret: paymentIntent,
      customFlow: true,
      merchantDisplayName: 'Example Inc.',
      style: 'alwaysDark',
    });

    setLoading(false);
    if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    }
    // updateButtons(paymentOption);
  };


  useEffect(() => {
    initializePaymentSheet();
  }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need triage question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants