#Meldiron-payments
1 messages · Page 1 of 1 (latest)
@serene bison hi! you should able to see the metadata on the webhook. Can you share exactly how you set the metadata when creating the payment, and which webhook event you listen to and how you look for the metadata in the event?
Create payment (JS):
const session = await stripeClient.checkout.sessions.create({
line_items: [
{
price_data: {
currency: 'eur',
product_data: {
name: package.title,
description: package.description,
},
unit_amount: package.price * 100,
},
quantity: 1,
},
],
mode: 'payment',
success_url: payload.redirectSuccess,
cancel_url: payload.redirectFailed,
metadata: {
userId: req.env.APPWRITE_FUNCTION_USER_ID, // 622750fbf3e64c423913
packageId: package.id, // pack2
},
})
res.json({
paymentUrl: session.url,
})
Webhook function:
const stripeSignature = req.env.STRIPE_SIGNATURE
const payload = JSON.parse(req.payload)
let event = stripe.webhooks.constructEvent(
payload.body,
payload.headers['stripe-signature'],
stripeSignature
)
if (event.type === 'payment_intent.succeeded') {
return res.json({
success: true,
data: event,
})
}
Output:
{"success":true,"data":{"id":"evt_3Kb2ekA3aIKqDDP50mEjjDGN","object":"event","api_version":"2020-08-27","created":1646744472,"data":{"object":{"id":"pi_3Kb2ekA3aIKqDDP50EIzORew","object":"payment_intent","amount":299,"amount_capturable":0,"amount_received":299,"application":null,"application_fee_amount":null,"automatic_payment_methods":null,"canceled_at":null,"cancellation_reason":null,"capture_method":"automatic","charges":{"object":"list","data":[{"id":"ch_3Kb2ekA3aIKqDDP50YTF6iSY","object":"charge","amount":299,"amount_captured":299,"amount_refunded":0,"application":null,"application_fee":null,"application_fee_amount":null,"balance_transaction":"txn_3Kb2ekA3aIKqDDP50yMdd0HP","billing_details":{"address":{"city":null,"country":"CZ","line1":null,"line2":null,"postal_code":null,"state":null},"email":"asd@asd.asd","name":"242424","phone":null},"calculated_statement_descriptor":"Stripe","captured":true,"created":1646744471,"currency":"eur","customer":"cus_LHbsrQOjptH75y","description":null,"destination":null,"dispute":null,"disputed":false,"failure_code":null,"failure_message":null,"fraud_details":{},"invoice":null,"livemode":false,"metadata":{},"on_behalf_of":null,"order":null,"outcome":{"network_status":"approved_by_network","reason":null,"risk_level":"normal","risk_score":58,"seller_message":"Payment complete.","type":"authorized"},"paid":true,"payment_intent":"pi_3Kb2ekA3aIKqDDP50EIzORew","payment_method":"pm_1Kb2f4A3aIKqDDP5ZzzXuvGP","payment_method_details":{"card":{"brand":"visa","checks":{"address_line1_check":null,"address_postal_code_check":null,"cvc_check":"pass"},"country":"US","exp_month":4,"exp_year":2024,"fingerprint":"8tiKNcLDNCTshqoZ","funding":"credit","installments":null,"last4":"4242","network":"visa","three_d_secure":null,"wallet":null},"type":"card"},"receipt_email":null,"receipt_number":null,"receipt_url":"https://pay.stripe.com/receipts/acct_1KJ2s7A3aIKqDDP5/ch_3Kb2ekA3aIKqDDP50YTF6iSY/rcpt_LHbsDXmYSMzKZHfAfFiPYK3Grdpe1b9","refunded":false,"refunds":{"object":"list","data":[],"has_more":false,"total_count":0,"url":"/v1/charges/ch_3Kb2ekA3aIKqDDP50YTF6iSY/refunds"},"review":null,"shipping":null,"source":null,"source_transfer":null,"statement_descriptor":null,"statement_descriptor_suffix":null,"status":"succeeded","transfer_data":null,"transfer_group":null}],"has_more":false,"total_count":1,"url":"/v1/charges?payment_intent=pi_3Kb2ekA3aIKqDDP50EIzORew"},"client_secret":"pi_3Kb2ekA3aIKqDDP50EIzORew_secret_twjBIAb9R1Kbctx3sqWfJHsbR","confirmation_method":"automatic","created":1646744450,"currency":"eur","customer":"cus_LHbsrQOjptH75y","description":null,"invoice":null,"last_payment_error":null,"livemode":false,"metadata":{},"next_action":null,"on_behalf_of":null,"payment_method":"pm_1Kb2f4A3aIKqDDP5ZzzXuvGP","payment_method_options":{"card":{"installments":null,"network":null,"request_three_d_secure":"automatic"}},"payment_method_types":["card"],"processing":null,"receipt_email":null,"review":null,"setup_future_usage":null,"shipping":null,"source":null,"statement_descriptor":null,"statement_descriptor_suffix":null,"status":"succeeded","transfer_data":null,"transfer_group":null}},"livemode":false,"pending_webhooks":1,"request":{"id":"req_WCy5tI7obaANBp","idempotency_key":"db5044d7-e8ce-4cad-882b-b2165bc387bf"},"type":"payment_intent.succeeded"}}
in this case you are setting metadata on the CheckoutSession object but you are listening to an event for a PaymentIntent object.
you should either :
- listen to the
checkout.session.completedevent instead of thepayment_intent.succeededone https://stripe.com/docs/payments/checkout/fulfill-orders#fulfill - or add metadata to the PaymentIntent directly via https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata