#darkknight-_code
1 messages ยท Page 1 of 1 (latest)
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.
- darkknight-_unexpected, 3 hours ago, 26 messages
๐ 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/1229521630112387193
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
I was going through this link https://docs.stripe.com/payments/finalize-payments-on-the-server?platform=react-native given to me from the last thread
success scenarios work fine ie. saving only credit cards that are not saved (as of now hardcoded the fingerprint to compare)
Does any exception get thrown when you call intentCreationCallback({ error })?
sorry abt the bg noise
Interesting, and nothing shows up in your dev console, and none of your error handling stuff sees anything?
nope
this is the handler code:
const confirmHandler = async (
paymentMethod: PaymentMethod.Result,
_shouldSavePaymentMethod: boolean,
intentCreationCallback: (
result: IntentCreationCallbackParams,
) => void,
) => {
try {
const { client_secret, error } = await createConfirmIntent(
stripeCustomerId,
paymentMethod.id,
);
if (client_secret) {
intentCreationCallback({ clientSecret: client_secret });
} else {
intentCreationCallback({ error });
}
} catch (err) {
console.log({ err }, 'from handler');
}
};
api call code:
const createConfirmIntent = async (
customerId: string,
paymentMethodId: string,
): Promise<ConfirmIntentData> => {
try {
const { data } = await axios.post(
`${CUSTOM_STRIPE_SERVER_URL}/create-confirm-intent`,
{ customerId, paymentMethodId },
{
headers: {
'Content-Type': 'application/json',
},
},
);
return data as ConfirmIntentData;
} catch (err) {
return { error: err } as ConfirmIntentData;
}
};
type ConfirmIntentData = {
client_secret: string;
error: string;
};
api endpoint handler:
app.post('/create-confirm-intent', async (req, res) => {
try {
const { customerId, paymentMethodId } = req.body;
const stripe = new Stripe(STRIPE_SECRET_KEY, {
apiVersion: '2024-04-10',
typescript: true
});
const paymentMethod = await stripe.paymentMethods.retrieve(paymentMethodId);
if (paymentMethod.type !== "card") {
return res.status(400).json("Only credit cards can be saved");
}
if (paymentMethod.card?.funding !== "credit") {
return res.status(400).json("Only credit cards can be saved");
}
if (paymentMethod.card.fingerprint === "vxOxUrmdfHx3dY7M") {
return res.status(400).json("The card has already been saved");
}
const setupCreateParams: Stripe.SetupIntentCreateParams = {
customer: customerId,
payment_method: paymentMethod.id,
confirm: true,
mandate_data: {
customer_acceptance: {
type: "online",
online: {
ip_address: req.ip || "",
user_agent: req.get("user-agent") || "",
}
}
},
};
const { client_secret } = await stripe.setupIntents.create(setupCreateParams);
return res.status(200).json({ client_secret });
} catch (err) {
return res.status(500).json({ error: err.message });
}
});
Thanks. Can you add a log for data right before return data as ConfirmIntentData;
And see if that spits out in metro?
just tried
nothing came, the app just crashed ๐ข
If you replace that axios request with just an abritrary log can you make sure that log is hit?
I can't get what ur saying. currently its like this
console.log({ data }, '@confirm intent');
return data as ConfirmIntentData;
} catch (err) {
return { error: err } as ConfirmIntentData;
}
If you put a log prior to the axios request I'm saying
So just put a log in the line before const { data } = await axios.post(
Alright so it seems like the crash is before the backend request then. Does this code work for successfully saving a PaymentMethod?
Have you tested that yet?
yes it works perfect on the sucess sceanrios when trying to save a credit card that has not yet been saved
Interesting
Okay one minute, let me spin up a repro