#fabbelevin

1 messages · Page 1 of 1 (latest)

green prismBOT
digital plaza
cunning magnet
#

I've tried setting it in the dashboard and just use the payment link urls I get there. And I've tried doing something like this:

api.post('/stripe-checkout', auth, catchAsyncErrors(async (req, res) => {
    const session = await stripe.checkout.sessions.create({
        success_url: 'http://localhost:9000/buy-now/diagnos/17198',
        cancel_url: 'http://localhost:9000/buy-now/diagnos/17198',

        line_items: [{price: req.body.product, quantity: 1}],

        mode: 'subscription',
        client_reference_id: req.body.accountId,
        metadata: {
            typeTest: 'smallPack',
            companySizeTest: '0-5'
        }
    });

    res.json({ url: session.url });

})); ``` 
I also have metadata set for that product
digital plaza
#

Let's take a step back, are you trying to use PaymentLinks or Checkout Session or both?

#

What's your end goal?

cunning magnet
#

It doesn't really matter for me, I've just tried both (seperately) to see if they would give something different.

The end goal is for the customer to be able to buy different subscription plans (payed monthly). There will be quite a lot of different plans with different prices so I think it would be nice to not have to setup different PaymentLinks for each, so my guess is that Checkout Session would be more comfortable?

The thing I'm struggling with at the moment is that when a new user pays I don't know in my webhook what user in my database completed the payment so I can't link it to the users account and I can't activate the account.

digital plaza
#

Gotcha. So if you want to get the metadata on customer.subscription.created event then you need to set it on the subscription when you create the checkout session. Because the code you shared is setting the metadata on the Checkout Session object (cs_xxxx) which is separate from a Subscription object (sub_xxx)

You can set the metadata on the subscription using subscription_data.metadata when you create the checkout session
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata

cunning magnet
#

Ah okay, do you recommend passing a userId in the metadata there as well then and not caring about the client_reference_id?

digital plaza
#

Yeah you can pass it in the metadata if you only want to deal with customer.subscription.created event

client_reference_id is a property of Checkout Session object (cs_xx) so you can only see it on events that deliver checkout object (like checkout.session.completed)

cunning magnet
#

I am actually a little confused as to which events I need to be listening to. What are the ones I need to listen to if I want to create a fully working subscription service? I won't have any trails connected to stripe.

digital plaza
cunning magnet
#

So technically if I only want to check if the customer has paid and should get access it would be enough to listen to customer.created and customer.subscription.updated ?

green prismBOT
vast lake
#

That could be a way to do it. Most users like to listen to events related to the invoices actually being paid but you can just listen to events for the subscription itself if that supports your usecase properly