#orange-checkout-customer

1 messages · Page 1 of 1 (latest)

neon jayBOT
icy berry
#

hey there!

#

First, it's important to know that sessions expire, so you may wish to defer generating the actual session until your customer clicks some other CTA in your email

#

direct them to a page you control, create the session then and redirect

#

but to answer your question, you need to set up webhook handlers for checkout.session.completed to know when they went through and finished the session

rigid jungle
#

How would I know what account the user payed for? Do they have to use the same email?

icy berry
#

What do you mean? Can you share an example?

rigid jungle
#

Sure,

#
eg lets say orangesidny@stripe.com [random] has the id ORANGE in my user database

When user clicks the checkout it will give a id e.g (1234) then I can say the userid ORANGE their stripe id is 1234
Then when the user's payment has gone though it will say payment id is 1234
then I can go in the database for the stripe id of 1234, and set the subscription to payed
neon jayBOT
icy berry
#

Sorry @rigid jungle I missed this update

rigid jungle
#

Don't worry

icy berry
#

Your email links would track your customers any way you like, when you turn that into a Stripe Checkout session you'd set the customer parameter to tie this to a known/existing customer (or you can create one if it doesnt yet exist)

#

Then when you get the checkout.session.completed event following their payment, that would have the same customer ID set on the contained session object

lone sky
#

orange-checkout-customer

rigid jungle
#

I am unsure what you mean by email links, is there any documentation for the this

#
const session = await stripeInstance.checkout.sessions.create({ 
            mode: "subscription",
            payment_method_types: ["card"],
            automatic_tax: {
                enabled: true
            },
            line_items: {
                "price": "price_.....",

                "quantity": 1,

            },
            success_url: `${req.headers.origin}/api/success?session_id={CHECKOUT_SESSION_ID}`,
            cancel_url: `${req.headers.origin}/shop?cancelledPurchase=true`,

            // shipping_address_collection: { allowed_countries: ["GB"] },
            phone_number_collection: { enabled: true },
        })

Where would I add the already created customer id (ORANGE)

lone sky
#

customer: 'cus_123' as a parameter like all the other parameters

icy berry
#

I'd misread your initial question as you emailing links to checkout sessions -- apologies for that confusion, but @lone sky can help you out

rigid jungle
#

Does it have to be customer, can I pass any random name eg userUid: "1234" for example, and does it have to start with cus or can it be any unique id?

lone sky
#

it has to be the exact Customer id cus_123

#

so you have to keep track of this in your own database to map a given customer on your app/website to the Stripe Customer

rigid jungle
#

Where do I get the cus_123 id from?

lone sky
#

You would have stored it during a previous successful payment

rigid jungle
#

I am a bit confused on what you are saying, I am just going to clarify what I want to do

  1. Website USER id [1234567890abcde] (NOT STRIPE ID / NO CORRELATION)
  2. User Clicks Buy -> Opens checkout window provides session id Of [SES_1234] (STRIPE CHECKOUT SESSION ID)
  3. In Personal User Database say UserId (1234567890abcde) = sessionId [SES_1234] (NOT IN ANY STRIPE DATABASE)
  4. New User has bought the subscription
  5. Webhook Says "User with session id [SES_1234] has bought the subscription" []
  6. In PERSOANL database I find session Id [SES_1234] which shows me user Id [1234567890abcde], Update premium [true]

Sorry about the caps, I am trying to not make myself sound confusing

lone sky
#

All good, so this has nothing to do with repeat customers at all and it's all about mapping the Subscription creation to your own internal customer id?

rigid jungle
#

Yes, all new customers

lone sky
#

Okay, so really all you want here is to put your internal customer id in the metadata of the Checkout Session. That way whenever you get the Event checkout.session.completed or really look at the Session in the API, you'll see its metadata and have the internal customer id

rigid jungle
#

Yes basically

lone sky
#

Okay so metadata should solve your problem in that case!

rigid jungle
#

Do you know any documentation on how would I set that up?

lone sky
#

it's a core concept in our API, it exists on most of our APIs. So really in the call to create the Checkout session you can pass the metadata you want

#
  mode: "subscription",
  payment_method_types: ["card"],
  automatic_tax: {
    enabled: true
  },
  line_items: [
    {
      price: "price_.....",
      quantity: 1,
    },
  ],
  success_url: `${req.headers.origin}/api/success?session_id={CHECKOUT_SESSION_ID}`,
  cancel_url: `${req.headers.origin}/shop?cancelledPurchase=true`,

  // shipping_address_collection: { allowed_countries: ["GB"] },
  phone_number_collection: { enabled: true },

  // Add the metadata you want
  metadata: {
    key1: "this is my value1",
    keyxxxx: "this is my valuexxxx",
    my_customer_id: '1234567890abcde',
  },
})```
#

like the thing at the end

rigid jungle
#

Thank you so much

rigid jungle
#

Will the Metadata be canned on the charge.succeeded as well, like how do I know that the payment has gone through

lone sky
#

@rigid jungle checkout.session.completed