#.sashank
1 messages · Page 1 of 1 (latest)
hi we are currently facing an issue
we are sending the metadata in json format to stripe.checkout.session.create
but when we configured a webhook to check for payment failures, in the payment_intent.payment_failed event, we are not getting the metadata which we passed while creating session
we want to get the failure reason and update it in the db with the metadata information that contains customer information
that's normal, you set the metadata on the Checkout Session itself, not on the PaymentIntent.
one option is to use https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata to store the metadata directly on the PaymentIntent object
oh ok we will try to add in this and see if it works
thank you so much for the quick response
happy to help 🙂
hi we added payment_intent_data, but in response we didn't get this back
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
metadata:{"servicer_id":servicer_id,"job_id":job_id,"customer_id":customer_id,},
payment_intent_data:{metadata:{"servicer_id":servicer_id,"job_id":job_id,"customer_id":customer_id}},
line_items: [{
price_data: {
currency: 'usd',
product_data: {
name: job_name,
},
unit_amount: total_amount,
},
quantity: 1,
}],
mode: 'payment',
success_url: 'https://yourwebsite.com/success',
cancel_url: 'https://yourwebsite.com/cancel',
// shipping_address_collection: {
// allowed_countries: ['IN'], // Allow shipping addresses from any country
// },
});
but in response we didn't get this back
which response?
response from stripe
now the metadata is stored on the PaymentIntent, so it won't be visible on the Checkout Session. These are separate objects!
oh ok
wait you did this:
metadata:{"servicer_id":servicer_id,"job_id":job_id,"customer_id":customer_id,}, payment_intent_data:{metadata:{"servicer_id":servicer_id,"job_id":job_id,"customer_id":customer_id}},
so you should see the metadata on both the Checkout Session and the Payment Intent
where exactly don't you see the metadata?
payment_intent_data is not showing up in the checkout session
just metadata is shown
That's normal:
- On the Checkout Session object you'll see the
metadatayou set. - On the PaymentIntent object you'll see the
payment_intent_data.metadatayou set
ok got it , we will check that in payment_intent.payment_failed
we got the metadata on PaymentIntent now, we made payment using a card which has insufficient funds, but we are not able to get the error message from webhook response, saying the card has insufficient funds, we got the insufficient funds message from the bank as sms on mobile, how can we get this using the webhooks?
which webhook endpoint are you listening to?
can you share the Event ID (evt_xxx)?
payment_intent.payment_failed
yes just give me a min
evt_3OfKjYJhm3jmN1nN1x7Sk119
then the payload contains a PaymentIntent, so you can check the last_payment_error property: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-last_payment_error
there you can see the message retruned by the bank
also... are you doing tests in live mode!?
Don’t use real card details. The Stripe Services Agreement prohibits testing in live mode using real payment method details. Use your test API keys and the card numbers below.
https://stripe.com/docs/testing
yes to check failed transactions in real world scenario
but in test cards we can't check insufficient funds right, so we did with a real card
we got this but we didn't get the message like , failed due to insufficient funds anywhere
"last_payment_error": {
"charge": "ch_3Of2BxJhm3jmN1nN0Y28xmmz", "code": "card_declined",
"decline_code": "transaction_not_allowed", "doc_url": "https://stripe.com/docs/error-codes/card-declined",
"message": "Your card does not support this type of purchase.",
}
we got this but we didn't get the message like , failed due to insufficient funds anywhere
you get the message that the bank sent, which is not always consistent with the real reason.
oh ok got it thanks
also we checked and found this
https://stripe.com/docs/testing#declined-payments
so we are checking in test mode now
yes that's a good idea
also is there a way to get session id inside this webhook event payment_intent.payment_failed ?
you'll need to make an extra API call to this endpoint: https://stripe.com/docs/api/checkout/sessions/list