#ProfChen

1 messages ยท Page 1 of 1 (latest)

stuck topazBOT
clever peak
#

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."

quasi oasis
#

for subscription mode you can do the same thing, but you need to use subscription_data

clever peak
#

I tried to did it with subscription_data but i'm not able to retrieve the meta in stripe dashboard

quasi oasis
#

Where are you looking?

#

It would be on the subscription

clever peak
#

I'm looking in the payments dashboard

#
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"
    }
]
quasi oasis
#

That metadata set in subscription_data will be on the subscription, not the payment

clever peak
#

Okay ๐Ÿ‘
Is there a way to attach the metadata to the payment ?

quasi oasis
#

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

clever peak
#

Ok i got it !

#

Thank you for your help !

stuck topazBOT