I am using the pre-built stripe checkout session in node.js. here's my function:
app.get('/create-checkout-session', async (req, res) => {
let customer = {
price: req.query.price,
quantity: req.query.quantity,
page: req.query.page,
email: req.query.email,
name: req.query.name
}
// insertIntoDbPreCheckout(customer, req, res)
let successurl = 'http://localhost:1111/' + customer.page + ''
let failedurl = 'http://localhost:1111/' + customer.page + ''
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
metadata: {
'description': customer.page
},
customer_email: customer.email,
line_items: [
{
price_data: {
currency: 'cad',
product_data: {
name: customer.page,
},
unit_amount: customer.price,
},
quantity: customer.quantity,
},
],
mode: 'payment',
success_url: successurl,
cancel_url: failedurl,
})
res.redirect(303, session.url);
});
i am trying to pass METADATA through, but it isn't letting me.
I cannot find anything online that shows me how to do this, and it is not working no matter what I try. How can i fix this?
edit:
when i log the customers, it shows like this:
email: 'uuu@u.com',
invoice_prefix: '9FC11B6D',
invoice_settings: { custom_fields: null, default_payment_method: null, footer: null },
livemode: false,
metadata: {},
as you can see, metadata is empty
Based on the updated question, this is expected. The metadata you've provided is on the Checkout session itself. You're examining the Customer object created by the Checkout session, which does not have metadata (yet).
You can add customer metadata if you want to, by updating the customer:
const customer = await stripe.customers.update(
'cus_123',
{metadata: {order_id: '6735'}}
);
Existing metadata would be on the Checkout session object.