#BrianHHough
1 messages ยท Page 1 of 1 (latest)
hello! are you referring to Checkout Sessions?
Yes let me send you a code snippet to show you what i'm doing -- i'm using react:
maybe you can share an example Checkout Session id for me to take a look first?
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',
}
)
believe this is the checkout.session.completed that just ran: "id": "cs_test_a1IHF8KtsM9wD49zlqZb0ymGvYAFveNmG2M6eJdccIcZIxrgWNqkl02kzZ"
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Where exactly do you put in the customer ID # though? We have our own database of userIDs so I'd want to pair it with that if possible
I'm just not seeing in the docs where the session.create ingests the customerID # we want to use (or create with it if it doesn't exist)
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',
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'
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',
wow i've been overthinking it hahaha thanks!!
So when I run this, Stripe will check if that customerID already exists....if so, will use it, or will create it, right?
i'd suggest you try what I suggested and see if it fits your requirements
Sounds good! Also, is there a way to require the email to be filled in, or can we prefill it with data when the session is created?
mainly asking b/c I want to be able to send receipts to each user that pays
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
so when the session gets created for the invoice...it's creating a customerID each time after the invoice is processes/paid for...right? I want to be able to edit that customerID variable before it gets created.
I'm mainly trying to create a link between the users in my database (AWS Cognito) and the stripe customers database so they're easy to match up
the way I would go about it is to create a Customer object for the users who register on your site
when creating a Customer object, add in metadata : https://stripe.com/docs/api/customers/create#create_customer-metadata to link the Customer to your users
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I see! That makes sense...so then the customer field can be loaded in to the functions. Thanks, Alex! I'm going to check this out right now
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
gotcha, do you know actually about if this is a better option than metadata? The customer_reference_id: #984902142106173491 message
I was checking out the chat and seems like this is maybe a good way to do this? https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-client_reference_id
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Hi @rustic crater I'm taking over.
Hi Jack! So i'm looking to connect my app's UserID with the stripe customerID
OK so you want to map the Stripe customer to your own Data.
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
Are you storing the Stripe customer ID in your DB?
i'm not, but would we need to?
can't i just store a reference in stripe of that user's appID?
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.
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)
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.
Thanks @flint nacelle ! So if I wanted to do this...would this type of logic make sense?
const customer = await Stripe.customers.create({
// I want to save a reference just to make for easy look-up later
customer_reference_id: userAPPID,
});
^ Then in the customer that's created....I would get a stripeID back, which I save to the userAPPID's Stripe_ID field?
or what is the minimum data required to create a customerID in stripe?
If you prefer to store your data in Stripe resource, we recommend using metadata (https://stripe.com/docs/api/metadata?lang=ruby#metadata)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long.
gotcha, i don't think metadata is the answer, right? customer_reference_id is a value that is like id right?
or is it not, i saw it in the docs, but not in the customer response object: https://stripe.com/docs/api/customers/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
There's no customer_reference_id property in a customer object
ok gotcha...so i think what i'm going to do is what you mentioned where when the user is created....i save that ID to the user's profile, and then I can call that field when I put in the customerID to create a subscription or payment
do i have that right?
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 ๐ค
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)
This is the customer search API https://stripe.com/docs/api/customers/search
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
and these are the query fields https://stripe.com/docs/search#query-fields-for-customers