#Yousuf
1 messages · Page 1 of 1 (latest)
Let's keep everything in this thread please. Here's your latest message:
I am still getting the same error, INTERNAL. When I remove < setup_future_usage: 'off_session',>, the error goes away but it doesnt save the payment in the payment sheet for future use. Note: I am using react native and firebase cloud functions:
exports.createStripeCharge = functions.https.onCall(async (data, context) => {
const amount = data.amount; // Amount in cents
const customer = data.customer
// const paymentMethodId = data.paymentMethodId;
console.log("customer ID: ", data.customer)
try {
const paymentIntent = await stripe.paymentIntents.create({
amount:1000,
currency: 'usd',
customer:customer,
setup_future_usage: 'off_session',
automatic_payment_methods: {
enabled: true,
},
// payment_method: paymentMethodId,
confirm: true,
});
console.log("ssssssss")
return { clientSecret: paymentIntent.client_secret };
} catch (error) {
throw new functions.https.HttpsError('internal', 'Payment failed 4', "" +error.message);
}
});
There should be more information about the error beyond just "INTERNAL". Can you check your error logs or add some logging to your code to surface more details about what's going wrong, like a stack trace?
the payment failed 3 alert is going off, and this is the log that am getting LOG [Error: INTERNAL]:
This my client side function:
const onPay = async () => {
try {
console.log(loggedUser.stripeCustomer)
setpaymentLoading(true);
const { data } = await functions().httpsCallable('createStripeCharge')({
customer: loggedUser.stripeCustomer, // Provide the customer ID to fetch saved payment methods
});
const { error: paymentSheetError } = await initPaymentSheet({
paymentIntentClientSecret: data.clientSecret,
});
if (paymentSheetError) {
Alert.alert('Something went wrong 1', paymentSheetError.message);
return;
}
const { error } = await presentPaymentSheet();
if (error) {
Alert.alert('Payment failed 2', error.message);
} else {
Alert.alert('Payment successful');
joinMatch();
}
} catch (error) {
console.log(error)
Alert.alert('Payment failed 3', error.message);
} finally {
setpaymentLoading(false);
}
};
Right, but that's not really all that helpful. I need more details about the error. When you log the error what does that show? Can you find a stack trace?
one sec, i am trying accessss the server side logs
StripeInvalidRequestError: You must provide a return_url when confirming a PaymentIntent using automatic_payment_methods[enabled] set to true and automatic_payment_methods[allow_redirects] set to always.
at StripeError.generate (/workspace/node_modules/stripe/cjs/Error.js:10:20)
at res.toJSON.then.Error_js_1.StripeAPIError.message (/workspace/node_modules/stripe/cjs/RequestSender.js:105:54)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
Ah, okay, so that error explains the issue.
.
.
.
if i remove the setup_future_usage, the payment sheet shows after the paymentIntent is created as expected.
Not sure I understand?
The error started showing up once I added
<setup_future_usage: 'off_session'> to my paymentIntent.
I'm not sure why that change would result in that specific error. Can you give me the request ID showing that error? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
I think setup_future_usage is not the only thing that's changing. Looks like you're also setting confirm to true.
yup, i just removed it and it worked
the payment method was added to the customer in stripe dashboard but the payment method isnt appearing in the payment sheet. Does that make sense?
Yes. I don't think exsting payment methods like that appear in the PaymentSheet.
I think there is a way for it:
https://stripe.com/docs/payments/accept-a-payment?platform=react-native&ui=payment-sheet
I am not sure though if I need to create the r Ephemeral Key everytime I create a paymentIntent?
Yeah, you would, that's how access is granted to the Customer.