#ProfChen
1 messages ยท Page 1 of 1 (latest)
However, when I attempt to do the same thing in subscription mode, the following code:
const session = await stripe.checkout.sessions.create({
customer: customer.id,
billing_address_collection: collectAddress? 'required': 'auto',
locale: 'fr',
payment_intent_data:{
metadata:{
campaignName,
campaignMedium,
campaignSource,
campaignAttribution
},
},
phone_number_collection: {
enabled: collectPhone,
},
line_items: [
{
price: price.id,
quantity: 1,
}],
mode: 'subscription',
success_url: process.env.CLIENT_DOMAIN + process.env.SUCCESS_URL,
cancel_url: process.env.CLIENT_DOMAIN + process.env.CANCEL_URL,
});
gives me : You can not pass payment_intent_data in subscription mode.
returns the error message: 'You cannot include payment_intent_data in subscription mode.'
Is there any way to pass metadata to Stripe in subscription mode? I would greatly appreciate any guidance or assistance on this matter."
for subscription mode you can do the same thing, but you need to use subscription_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I tried to did it with subscription_data but i'm not able to retrieve the meta in stripe dashboard
I'm looking in the payments dashboard
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
const session = await stripe.checkout.sessions.create({
customer: customer.id,
billing_address_collection: collectAddress ? 'required' : 'auto',
locale: 'fr',
subscription_data: {
metadata: {
campaignName,
campaignMedium,
campaignSource,
campaignAttribution
},
},
phone_number_collection: {
enabled: collectPhone,
},
line_items: [
{
price: price.id,
quantity: 1,
}
],
mode: 'subscription',
success_url: process.env.CLIENT_DOMAIN + process.env.SUCCESS_URL,
cancel_url: process.env.CLIENT_DOMAIN + process.env.CANCEL_URL,
});
res.status(200).json({ url: session.url });
However, I still can't see the metadata.
To investigate the issue, I tried adding metadata from the Stripe dashboard to see where the field is stored in the response object.
Now, I can see the added field in a structure at the root of the response object:
"metadata": {
"test": "testMeta"
}
I also noticed that the sent metadata are wrapped in a "data" object:
"data": [
"metadata": {
"campaignSource": "fb",
"campaignName": "test"
}
]
That metadata set in subscription_data will be on the subscription, not the payment
Okay ๐
Is there a way to attach the metadata to the payment ?
Not automatically via checkout like you're probably hoping, no.
You'll either need to propagate than manually, or for subscription payments you'd follow the invoice to the subscription and look at the metadata there