#trung_code
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/1359782729994211389
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Can you tell me more about the "add card" step?
Below is my add card code
public function addCard($token)
{
try {
$data = [
'source' => $token,
];
$this->user->updateStripeCustomer($data)->toArray();
$paymentMethods = $this->user->paymentMethods()->toArray();
$this->user->update([
'pm_last_four' => $paymentMethods[0]['card']['last4'],
'pm_card_type' => $paymentMethods[0]['card']['brand'],
'pm_type' => 'card',
]);
return true;
} catch (\Stripe\Exception\CardException $e) {
if ($e->getError()->code === trans('stripe.errors.expired_card')) {
throw new InputException('Card expired');
} elseif ($e->getError()->code === trans('stripe.errors.card_declined')) {
if ($e->getError()->decline_code === trans('stripe.errors.insufficient_funds')) {
throw new InputException('Your card has insufficient funds');
}
throw new InputException('Declined by the issuer');
} else {
throw new InputException(trans('stripe.add_card.invalid_request_error'));
}
}
}
Ok, I don't recommend you attaching the card to the customer directly.
https://docs.stripe.com/payments/save-during-payment you should follow this guide to save a payment method during payment.
I want to ask a little more about useConfirmCardPayment, with the code like below, will there be asynchrony, in some cases the confirmCardPaymentSuccess() function is not called. I am using nextjs
export const useConfirmCardPayment = () => {
const stripe = useStripe()
const confirmPayment = async ({
clientSecret,
paymentMethod,
pointPackageId,
onSuccess,
confirmCardPaymentSuccess,
}: {
clientSecret: string
paymentMethod: string
pointPackageId: number
onSuccess: () => void
confirmCardPaymentSuccess: (payload: { payment_intent_id: string; point_package_id: number }) => void
}) => {
if (!stripe) return
const { paymentIntent, error } = await stripe.confirmCardPayment(clientSecret, {
payment_method: paymentMethod,
})
if (error) {
return toast.error(error.message)
}
if (paymentIntent) {
confirmCardPaymentSuccess({
payment_intent_id: paymentIntent.id,
point_package_id: pointPackageId,
})
onSuccess()
}
}
return { confirmPayment }
}
I don't quite understand your question, can you rephrase it?
I'm using useConfirmCardPayment in a Next.js project, and I have a question about potential asynchronous behavior.
In some cases, the confirmCardPaymentSuccess() function doesn't seem to get called. Here's a simplified version of the code:
export const useConfirmCardPayment = () => {
const stripe = useStripe()
const confirmPayment = async ({
clientSecret,
paymentMethod,
pointPackageId,
onSuccess,
confirmCardPaymentSuccess,
}: {
clientSecret: string
paymentMethod: string
pointPackageId: number
onSuccess: () => void
confirmCardPaymentSuccess: (payload: { payment_intent_id: string; point_package_id: number }) => void
}) => {
if (!stripe) return
const { paymentIntent, error } = await stripe.confirmCardPayment(clientSecret, {
payment_method: paymentMethod,
})
if (error) {
return toast.error(error.message)
}
if (paymentIntent) {
confirmCardPaymentSuccess({
payment_intent_id: paymentIntent.id,
point_package_id: pointPackageId,
})
onSuccess()
}
}
return { confirmPayment }
}
My question is:
Could there be any asynchronous issues or edge cases where paymentIntent exists but confirmCardPaymentSuccess() still doesn't get called? Or maybe something is preventing it from running? I'd like to understand under what circumstances this might happen.
If I understand you correctly, confirmCardPaymentSuccess won't be called when there's a payment error.
Is this the thing that you want to confirm?
Iâd like to confirm whether there could be any cases where paymentIntent exists, but confirmCardPaymentSuccess is still not called. Could this be due to some kind of asynchronous issue?
No, there won't be cases when both paymentIntent and error are both non-null.
I've noticed that in some cases where the user's card goes through 3DS frictionless, the confirmCardPaymentSuccess function doesn't get called. I'm not quite sure why this happens â could you help me understand it better?
Could this be due to an asynchronous issue?
Maybe you want to put some logs in your code to troubleshoot?
For cards that require 3DS frictionless, is there anything that needs to be adjusted in my code?
No, the code looks good to me
Are there any test card numbers available that can simulate 3DS frictionless in the test environment?
https://docs.stripe.com/testing#regulatory-cards no I don't see a card dedicated for frictionless flow.