#moray-groop
1 messages · Page 1 of 1 (latest)
👋 happy to help
could you please share the request id that was generating this error? https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
Hi, thanks for your time. It seems that the request is a problem in the client library, I don't think it hits your API
Every time I try to create a payment I get "There was an unexpected error -- try again in a few seconds"./
could you please elaborate about this some more?
I've got the CardField element which is validating the card data fine, but when I submit the form and call createPaymentMethod, the response is always "There was an unexpected error"
could you please share a code snippet so I could have an idea how you're implementing?
It's split into two files
you can post both then! Also, is there are more specific error message, for example in the Metro console output, or in the native logs for the simulator? https://reactnative.dev/docs/debugging#accessing-console-logs
Payment.tsx
export const Payment = ({ paymentDetails }) => {
const onSubmit = async () => {
const stripeResponse = await stripe.createPaymentMethod({
paymentMethodType: 'Card',
});
console.log('onProcess', stripeResponse); // this is where I see the error message
if (stripeResponse.error) // Handle
submitPaymentRequestToApi(id, stripeResponse.paymentMethod.id); // Sends the details to our API
};
return (
<PaymentView paymentDetails={paymentDetails} onSubmit={onSubmit} />
);
};
thanks! can you share much more like, like the complete component hierachy and how this Payment component is used in its parent?
and the contents of the PaymentView component
PaymentView.tsx
export const PaymentView = ({ paymentDetails, onSubmit }) => {
const stripe = useStripe();
useEffect(() => {
async function initialize() {
await initStripe({
publishableKey: Config.REACT_APP_STRIPE_PK,
stripeAccountId: paymentDetails.stripeAccount,
});
}
initialize().catch(console.error);
});
return (
<View>
<CardField
style={styles.cardField}
postalCodeEnabled
onCardChange={} // A validation function to enable/disable the submit button
/>
// ... the rest of the form
<Button title='Pay' onPress={onSubmit} />
</View>
);
};
to be clear the problem here is likely that the library can't find the CardField (it automatically looks for it when you call createPaymentMethod so it can pull the card details from there), and it highly depends on how you set up your app, how you use the StripeProvider, and so on, so it really needs the full context of your app to say much
I'm not using the StripeProvider as when I did I kept getting 'Card details not complete' - see this issue: https://github.com/stripe/stripe-react-native/issues/508
I'm using initStripe instead in PaymentView
feels to me like the problem here is you initialise Stripe inside the child component PaymentView but try to use it in the parent
I thought that might be the case, but I'd seen other issues where the CardField doesn't work if initStripe is not called in the same component
Or does it need to be called in both?
I suggest using StripeProvider. Can you just follow the guide at https://stripe.com/docs/payments/accept-a-payment?platform=react-native&ui=custom and build it as one component for now? it should just work
https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/react-native-expo/Card.tsx is also a full example of this. For context that app uses StripeProvider at the top level : https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/react-native-expo/App.tsx#L57-L62
It's a bit awkward with the component structure but I can try. We can't use StripeProvider at the top level as it needs to be initialised with stripeAccountId which in our case may be different for each transaction