#nahoor_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1359165245930864904
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- nahoor_api, 1 hour ago, 25 messages
const confirmHandler = async (paymentMethod: any, shouldSavePaymentMethod: any, intentCreationCallback: any) => {
try {
const response = await axios.post(
`${API_URL}/Stripe/confirm-payment-intent`,
{
paymentMethodId: paymentMethod.id,
currency: 'gbp',
amount: bookingPrices.totalPrice,
orderReference,
description: `${bookingLoadData?.from?.postcode} - ${bookingLoadData?.to?.postcode} / ${bookingLoadData?.minVehicleSize}`,
isMobile: true,
// should_save_payment_method: shouldSavePaymentMethod,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
}
);
console.log('โ
confirmHandler API Response:', response.data);
const responseData = response.data?.data;
if (responseData?.clientSecret) {
intentCreationCallback({ clientSecret: responseData?.clientSecret });
} else if (responseData?.error) {
console.log('Error', responseData.error);
intentCreationCallback({ error: responseData.error });
} else {
console.warn('โ ๏ธ Unexpected response structure:', responseData);
intentCreationCallback({ error: 'Unexpected response from server' });
}
} catch (error: any) {
const errorMsg2 = error.response || error.message || 'Unknown error occurred';
console.error('โ Error in confirmHandler:', errorMsg2);
intentCreationCallback({ error: errorMsg }); // Pass error to Stripe to reject flow
} finally {
setLoading(false);
}
};
hey there taking a look, thanks for the example request
This request looks successful: https://dashboard.stripe.com/test/logs/req_fCYVJbU2Ra8yhS
Are you sure that was the request you meant to send?
What are you passing into intentCreationCallback?
I am passing error from backend my console.log is as follow :
confirmHandler API Response: {"data": {"error": "Your card has insufficient funds."}, "message": "Error processing payment", "status": false}
(NOBRIDGE) LOG Error Your card has insufficient funds.
but it is causing a crash as it is in error state or call intentCreationCallback({ error: responseData.error });
I don't understand what you're expecting, this seems to be hitting this path:
} else if (responseData?.error) {
console.log('Error', responseData.error);
intentCreationCallback({ error: responseData.error });
}
as it hit this my app crashes
Ok, what causes it to crash?
as soon as it goes into this response?.error in intentCreationCallback
i want to show error but it is crashing
so i am unable if i don't do intentCreationCallback it keep on processing
now did u get it ?
I get that you're exercising an error path here, and passing an {error: 'Some error message.' to intentCreationCallback, but its not clear what is actually failing.
Do you have device logs with more information about the crash/error?
I should say explicitly to confirm: i am assuming from your JS snippets that you're using react native here in your app (not android or ios native)
yes i am using react native
And you're following the pattern described here: https://docs.stripe.com/payments/mobile/accept-payment?platform=react-native&type=payment#confirm-the-payment
That's all fine, and the pattern seems to be valid based on the documented structure and what you've shown, so where exactly does the error originate?
Can you confirm which version of stripe-react-native you're using?
The device logs should hopefully provide a pointer to the actual error
What do they say when this happens?
i am trying but it is not showing
Hmm, do the logs just cut off at that point?
yes
If you run through that with a debugger, is the intentCreationCallback variable properly populated? And I assume the console.log is properly logging out the error just before you are passing it to that callback?
In my log as soon as it calls intentCreationCallback({ error: responseData.error }); it crashes
confirmHandler called. Payment Method ID: {"AuBecsDebit": {"bsbNumber": null, "fingerprint": null, "last4": null}, "BacsDebit": {"fingerprint": null, "last4": null, "sortCode": null}, "Card": {"availableNetworks": null, "brand": "Visa", "country": "US", "expMonth": 2, "expYear": 2027, "fingerprint": null, "funding": "credit", "last4": "9995", "preferredNetwork": null, "threeDSecureUsage": {"isSupported": true}}, "Fpx": {"accountHolderType": null, "bank": null}, "Ideal": {"bankIdentifierCode": null, "bankName": null}, "SepaDebit": {"bankCode": null, "country": null, "fingerprint": null, "last4": null}, "Sofort": {"country": null}, "USBankAccount": {"accountHolderType": "Unknown", "accountType": "Unknown", "bankName": null, "fingerprint": null, "last4": null, "linkedAccount": null, "preferredNetworks": null, "routingNumber": null, "supportedNetworks": null}, "Upi": {"vpa": null}, "billingDetails": {"address": {"city": null, "country": "GB", "line1": null, "line2": null, "postalCode": "MK92AH", "state": null}, "email": null, "name": null, "phone": null}, "customerId": null, "id": "pm_1RBd8J00IFw5OXLObmDAAC2S", "livemode": false, "paymentMethodType": "Card"}
(NOBRIDGE) LOG ๐ confirmHandler called. intentCreationCallback: [Function intentCreationCallback] my console for payment and intentCreationCallback
Oh actually it looks like it is crashing before then, because that output doesn't have the "Error" string from your "console.log('Error', responseData.error);" call. Even if you passed an empty string via responseData.error that should still log a line that says "Error"
I recommend stepping through your code with a debugger to get a clearer view of what is happening. If intentCreationCallback is what is crashing things, it could be helpful to try to step in to that method to see if you can see the specific line that is crashing things.
in my responData.error it is string actually
Correct, but your call also passes the string literal "Error"
And that string literal isn't in the output that you just pasted here
It is like if you had a console.log call that had "Nahoor" in it and that string wasn't in your output. That indicates that the log statement isn't being executed
const confirmHandler = async (paymentMethod: any, shouldSavePaymentMethod: any, intentCreationCallback: any) => {
console.log('๐ confirmHandler called. Payment Method ID:', paymentMethod);
console.log('๐ confirmHandler called. intentCreationCallback:', intentCreationCallback);
const orderReference = ${bookingLoadData?.loadId};
try {
const response = await axios.post(
${API_URL}/Stripe/confirm-payment-intent,
{
paymentMethodId: paymentMethod.id,
currency: 'gbp',
amount: bookingPrices.totalPrice,
orderReference,
description: ${bookingLoadData?.from?.postcode} - ${bookingLoadData?.to?.postcode} / ${bookingLoadData?.minVehicleSize},
isMobile: true,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: Bearer ${token},
},
}
);
const responseData = response.data?.data;
if (responseData.clientSecret) {
console.log('client_secret', responseData.clientSecret);
intentCreationCallback({ clientSecret: responseData.clientSecret });
} else if (responseData.error) {
const error = responseData.error;
const serverError = error.response?.data?.error || error.response?.data?.message;
intentCreationCallback({ error: serverError });
}
} catch (error: any) {
const serverError = error.response?.data?.error || error.response?.data?.message;
const errorMsg2 = serverError || error.response || error.message || 'Unknown error occurred';
intentCreationCallback({ error: errorMsg2 }); // Pass error to Stripe to reject flow
}
well this is my code for your better understanding
That all looks fine as far as I can see. I really do think a debugger is the next step. I'll try to run that code in my RN environment and see if I get a similar error as well
That would be so great if you do that
As in how do you get that error from the decline object?
And is that an error message that you are now seeing related to the intentCreationCallback?
Also your code is working fine for me when I run it in my own RN environment now. I think the two options from here are:
- Debugger
- Create a minimal repro project. Like an RN project with one screen that just tries to open a payment sheet and do this flow that still gets this error. If you send that in to our support team, we can try to reproduce on our side and escalate if we see it as well
yes
Your server-side code can check for the decline after making the API call to create and confirm the payment intent. Basically you check the object on the server and return the decline code as the error property for your response
https://docs.stripe.com/payments/mobile/finalize-payments-on-the-server?platform=react-native&type=payment&integration=paymentsheet-flowcontroller#handling-client-side-arguments
Though actually that code doesn't show the decline specifically. You can check the last_payment_error.decline_code property on the payment intent that you get back if the create/confirm erros
https://docs.stripe.com/declines/card#responding-to-failures-api