#crawl-customer-multiple

1 messages · Page 1 of 1 (latest)

twilit shardBOT
topaz tulip
#

crawl-customer-multiple

#

@tribal crescent this is definitely doable but it's something you need to build/control yourself in this case. I assume you use Checkout or similar?

topaz tulip
#

@tribal crescent did you have more details? Did you need more help?

tribal crescent
#

I use subscription with links (no code solution) then I have an api nodejs that listen to the webhooks

topaz tulip
#

Okay then that is impossible unfortunately. PaymentLinks are designed to be one link to anyone and there's no way to associated an existing customer to it without writing real code.
What you need to do is detect when an existing customer is back on your website/app and in that case instead of using PaymentLinks you would have your server-side code directly create a Checkout Session for them and pass their existing Customer id cus_123 in the customer parameter which would let them start a second Subscription

#

@tribal crescent does that make sense ^? Sorry to push, just want to make sure you engage in real time as this is real time chat/help. Otherwise it might be better chatting async with our support team

tribal crescent
#

yes, so I in fact I did try the full code solution

tribal crescent
#

do you have an exemple of how I can acheive that ?

topaz tulip
#

Can you be a lot more specific? This is unfortuantely really vague. I did explain exactly what you need to do above

#

There's no "duplicate customer" if your code properly sets the right customer id in the customer parameter.

twilit shardBOT
tribal crescent
#

Here's the details

#

In my api server, I was creating a customer_id when a user first sign up to my app

At the same time, I created a customer then add the db_user_id to stripe metadata - and add the customer_id to my db

Then after at the same time I create a subscription, but since the user didnt pay yet the subscription status is not valid

So when I prompt my user to pay, this create a new customer_id, instead of updating the same

#

Also, when a subcription is created with a status invalid, it's seems like the subscription can in fact expire

#

So what would be the flow for this solution

#

Hope that make sense

noble narwhal
#

Lets focus on one problem at a time. It sounds like you're not passing the Customer ID during Subscription creation. Are you able to locate the block of code you're using to create the Subscription?

tribal crescent
#

Here's my code snippet

 let priceId = 'price_1MVGMsLM4GHVXwuA7E3QM691';
      // If missing customerID, create it
      if (!stripeCustomerId) {
          // CREATE new customer
          const customer = await stripe.customers.create({
              email,
              metadata: {
                  "mongodbUID": userId.toString()
              },
              ...params
          });
          console.log('Customer created ', customer);
          await updateUser(userId, { stripeCustomerId : customer.id })
          console.log('Customer created ', userId);

        // const subscription = await stripe.subscriptions.create({
        //    customer: customer.id,
        //    items: [{
        //      price: priceId,
        //    }],
        //    payment_behavior: 'allow_incomplete',
        //    expand: ['latest_invoice.payment_intent'],
        //    payment_settings: {
        //      payment_method_types: ['card'],
        //    },
        //  }); ```
noble narwhal
#

Okay, so something must be going wrong with the block of code that is creating the stipeCustomerId variable. Are you able to put log lines console.log(); at each step to figure out where/why the stripeCustomerId is not being set?

tribal crescent
#

So here the customer is created without any issue
I can see it on the dashboard customer list with the proper metadata etc....

My issue is more on how can a customer can update the same id

#

maybe it's my subcription creation the issue

noble narwhal
#

Ah, so you want to know how a Customer can come back after they've created a subscription and either (a) create an additional subscription under their customer ID, or (b) modify their current subscription. Is that correct?

tribal crescent
#

Because if I try to checkout with a link the same email for exemple a new customer is create

noble narwhal
#

That will allow you to control what they are/aren't allowed to do regarding their subscriptions

tribal crescent
#

ok so I can pair that with webhook ?

noble narwhal
#

Yup! The customer.subscription.updated event still fires when updates occur