#BrianHHough

1 messages ยท Page 1 of 1 (latest)

clear egretBOT
twin rapids
#

hello! are you referring to Checkout Sessions?

rustic crater
twin rapids
#

maybe you can share an example Checkout Session id for me to take a look first?

rustic crater
#

a function like this as the input:

const session = await stripe.checkout.sessions.create({
                payment_method_types: ["card"],
                mode: 'payment',
                billing_address_collection: "auto",
                line_items: [{
                    price:  "price_XXXXXXX",
                    quantity: 1,
                }],
                success_url: 'http://localhost:3000/settings?session_id={CHECKOUT_SESSION_ID}',
                cancel_url: 'http://localhost:3000/settings',
                }
            )
rustic crater
twin rapids
#

so if you want the Checkout Session to reuse the same Customer id, you'd want to maintain a list of Customer ids in your DB linked to their email addresses (or whatever unique login id) they use to login - https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer

#

you can pass in metadata if you want by passing it into the fields listed below, but it would really be better if you make use of an existing Customer Id :
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata

rustic crater
rustic crater
# twin rapids you can pass in metadata if you want by passing it into the fields listed below,...

ok sounds great! I trust you on using an existing CustomerID

Could you help me understand where it fits into the elements we put into the session.create call? I'm a bit stuck on this:

payment_method_types: ["card"],
mode: 'payment',
billing_address_collection: "auto",
line_items: [{
   price:  "price_XXX",
   quantity: 1,
],
success_url: 'http://localhost:3000/settings?session_id={CHECKOUT_SESSION_ID}',
cancel_url: 'http://localhost:3000/settings',
rustic crater
# twin rapids so if you want the Checkout Session to reuse the same Customer id, you'd want to...

do you literally just create a field under it that is set to a string like this? https://stackoverflow.com/questions/70190205/how-to-create-checkout-session-for-payment-intent

payment_method_types: ["card"],
mode: 'payment',
billing_address_collection: "auto",
line_items: [{
   price:  "price_XXX",
   quantity: 1,
],
success_url: 'http://localhost:3000/settings?session_id={CHECKOUT_SESSION_ID}',
cancel_url: 'http://localhost:3000/settings',
customer: 'customerUserIDGoesHere'
twin rapids
#

it would really just be like that

payment_method_types: ["card"],
customer : "cus_xxx",
mode: 'payment',
billing_address_collection: "auto",
line_items: [{
   price:  "price_XXX",
   quantity: 1,
],
success_url: 'http://localhost:3000/settings?session_id={CHECKOUT_SESSION_ID}',
cancel_url: 'http://localhost:3000/settings',
rustic crater
twin rapids
#

i'd suggest you try what I suggested and see if it fits your requirements

rustic crater
#

mainly asking b/c I want to be able to send receipts to each user that pays

twin rapids
#

to clarify, the Customer Id refers to a Stripe Customer object : https://stripe.com/docs/api/customers

You should pass in an existing Customer ID if it already exists, otherwise you should ideally create one before hand

#

it's not an ID that you define yourself

rustic crater
twin rapids
#

the way I would go about it is to create a Customer object for the users who register on your site

rustic crater
rustic crater
# twin rapids the way I would go about it is to create a Customer object for the users who reg...

Hi Alex, I have a mechanism to run updates to the user upon sign-up and/or authentication....i'm not seeing where to create a customer in stripe with a specific ID...am i looking in the right place? https://stripe.com/docs/api/customers/create#create_customer-metadata

twin rapids
#

you cannot create a Customer with a specific ID. When you create a Customer, Stripe will return an id for that Customer object

#

if you want, you can add metadata to store your own ID on the Customer object

rustic crater
flint nacelle
#

Hi @rustic crater I'm taking over.

rustic crater
flint nacelle
#

OK so you want to map the Stripe customer to your own Data.

rustic crater
#

Alex had a suggestion of creating a post-sign-up function call to stripe to create a customer...I just saw the client_reference_id as a field to use for users, but not sure if that's better/worse than metadata

flint nacelle
#

Are you storing the Stripe customer ID in your DB?

rustic crater
#

can't i just store a reference in stripe of that user's appID?

flint nacelle
#

I believe this is one of the easiest way to associate Stripe resources with your own data.

#

What's this appID? I need more context to understand your use case.

rustic crater
#

sure! so in my app, there is a generated userID let's say this is our user database:

[APP]

| ID | name | email |
| app_user_1 | joe | joe@gmail.com |
| app_user_2 | sam | sam@gmail.com |

[PRODUCTS - Stripe]
Premium Subscription - $5

When joe or sam go to make a payment in our app, it's causing Stripe to make separate customerIDs for each purchase.

[ WHAT I WANT IN STRIPE ]
| ID | name | customer_reference_id |
| stripe_user_1 | joe@gmail.com | app_user_1 |
| stripe_user_2 | sam@gmail.com | app_user_2 |

Let's say that joe makes 2 purchases and sam makes 5 purchaes....I need to make sure that there are only TWO (2) customers....with 7 transactions, NOT SEVEN (7) customers and 7 transactions

#

@flint nacelle does that make sense? My created stripe sessions and successful payments are doing this? These are payments by the same user....yet it's creating separate customerIDs for each individual transaction (i.e. I even was using the same email in the stripe invoice)

flint nacelle
#

Thanks for the detailed explanation, I get the picture now.

#

A subscription requires a customer, and that's why Stripe would create a new customer if none is specified during checkout session creation.

#

So my suggestion is to create a Stripe customer upfront, save the customerID in your app tabled (maybe another column to save the customer_id ?), so that when you want to create checkout session for subscription, get the customer_id from your DB, and pass it to the checkout session creation request.

rustic crater
#

or what is the minimum data required to create a customerID in stripe?

flint nacelle
#

You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long.

rustic crater
flint nacelle
#

There's no customer_reference_id property in a customer object

rustic crater
#

do i have that right?

flint nacelle
#

Totally agree

rustic crater
# flint nacelle Totally agree

Yesssss!! Just got it to create the user! ๐Ÿ”ฅ

Ok so this makes tons of sense....and i can actually customize the name to be my user's subID so that it's easy to look up in our portal as well

#

Thanks so much @flint nacelle ๐Ÿค

flint nacelle
#

Welcome!

rustic crater
# flint nacelle Welcome!

Btw, is there a way to search a customers database for a specific name using the key? Or how searchable is the customers DB from a server?

I basically want to make a stop where if the name already exists, don't create a customer (i.e. if that was ever an option)

flint nacelle