#Jayy
1 messages · Page 1 of 1 (latest)
👋 Hi there, Happy to help!
If you are using Card payments, you can use one of these card Numbers in order to simulate a decline payment:
https://stripe.com/docs/testing#declined-payments
that didn't actually work because of the flow i am using.
here's what i do:
const checkout = await stripe.checkout.sessions.create({
mode: 'setup',
success_url: `${process.env.NEXTAUTH_URL}/payment/processing?sessionId={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.NEXTAUTH_URL}/payment?canceled=true`,
customer: session.stripeId,
payment_method_types: ['card'],
})
This would still work if the user added a card with not enough funds as the SETUP mode doesn't check for balance.
once the user is redirected to the success_url i create the subscriptions as follows:
const monthlySub = await stripe.subscriptions.create({
customer: paymentMethod.user.stripeCustomerId!,
items: monthly.map((m) => ({
price: m.price,
quantity: m.quantity,
})),
expand: ['latest_invoice.payment_intent'],
collection_method: 'charge_automatically',
default_payment_method: paymentMethodId,
})
This will automatically charge the saved method the customer has.. i want to simulate a failed payment on that
You need to create a PaymentMethod from the decline card (for example : 4000000000000002 using Stripe Elements) and then pass it when creating the subscription default_payment_method
isn't there a way from inside stripe dashboard to save the payment methods!?
cz i get this when i try
Yes ussing dashboard will checks the card is valid or not. So you need to use the stripe.createPaymentMehtod in order just to create the PaymentMehtod without trying to authenticate it:
https://stripe.com/docs/js/payment_methods/create_payment_method
alright i'll give it a try. also i'm getting this on my dashboard:
Some Dashboard features aren’t available right now due to unusually high activity from your account. Check with your team and try again later.
what could cause it ?
checking the logs there are barely any activities
You can ignore it for now, if you have any particular issue don't hesitate to come back
will do, thanks for the help!
i'm sorry but this is not working. here is what i'm trying:
const x = await stripe.paymentMethods.create({
type: 'card',
card: {
exp_month: 12,
exp_year: 2024,
number: '4000000000000002',
cvc: '314',
},
})
const y = await stripe.paymentMethods.attach(x.id, {
customer: session.stripeId!,
})
which is just erroring that card is declined and i cannot attach it to customer.
i tried creating the subscription without attaching which also caused an error (paymentMethod not attached to customer)
could you please share the request id?
req_Igd3DyjIg6SYb0
where did you get that card number from?
you need to use one of our testing cards https://stripe.com/docs/testing
oh yes sorry I missed it
then this explains the decline
when we try to attach a PM to a customer we try to authenticate it
so how am i able to create a subscription and check if it errors ?
if you want to test a decline after attaching you should use the 4000000000000341 card insteaed
the message directly after that table states
The cards in the previous table can’t be attached to a Customer object. To simulate a declined payment with a successfully attached card, use the next one.
oh
and it's just a charge fail decline yes ?
which should be the one i need with my flow
yes
Alright thanks !
let me know if you need any more help