#kyleruban-integration-help
1 messages ยท Page 1 of 1 (latest)
I am sending the token from the client to server
Or I might not be sending the right thing
Any bit of guidance would be a huge help!
Hey Hanzo! Have you seen an error like this before?
Hey there, do you have an example of this failure you can share?
What do you want me to share
The error does describe a valid failure though -- if you're trying to use a payment method more than once without attaching to a customer first, it will fail this way
An example failing request ID, ideally
eg: req_123 https://stripe.com/docs/api/request_ids
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
If you're trying to attach a payment method to a customer after using it with a payment, you need to change your integration. I suggest using setup_future_usage on the payment method to achieve this:
https://stripe.com/docs/payments/save-during-payment?platform=web#web-create-payment-intent
Im confused on where to set that setup_future_usage
And I dont known how to find the requestid
Do i need to do all of this work in 1 job?
I have a server route that is creating a payment intent and then I have a server route that is taking in the email name and token to create the customer
does this all have to be done in 1 route? Am i recreating this payment intent with the way I am doing it now?
I have a server route that is creating a payment intent
That's where you'd set setup future usage
set the setup future usage option
Did you click the link i sent? It shows examples of this
Yes I did
I have that in there now but I get an error with the customerID and it says I dont have a customer with that ID yet
Where do you get that error?
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
I am trying to make the customer in the 1st place after an order is completed and then reuse that payment method for that customer if the store I am working with needs to change the price of the order after the payment has gone through
You can get it in the response headers or find the request in your dashboard logs: https://dashboard.stripe.com/test/logs/
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I get that error in my console when hitting the server side create payment element route
req_XAvwnBjVqR79RZ
that is the error
Hello ๐
If you look at the request body
https://dashboard.stripe.com/test/logs/req_XAvwnBjVqR79RZ
You're passing in an ID which isn't a valid Stripe Customer ID
Stripe Customer IDs have cus_xxx prefixes
Okay makes sense
I just am confused how I can set the customer in the 1st place though
Do i have to create the cus_xxx in my frontend and then send it to the backend to create that customer
I understand its saying no such customer I just need to set the customer first is this not done in the create payment route?
Creating a customer requires your secret API key so you can't create it on the front end. You'd create the customer server-side.
It depends on your application when you exactly create the customer as it could be when they sign up for an account on your site OR sometime later
When you create a PaymentIntent you'd pass that customer ID in the customer parameter
Okay how can i create a customer without creating a payment intent at the same time?
Is this close at all?
I am pretty sure that is creating a payment intent as well
We have an example here
https://stripe.com/docs/api/customers/create
And also I am not storing card details so I would need to wait until the customer makes their order to create a new customer and add their payment details to it
Is that typically how it is done?
Or like how can i set the customers payment method before the payment is successful
Here's what you're looking for
https://stripe.com/docs/payments/save-during-payment
Or like how can i set the customers payment method before the payment is successful
We support both
You can prefill the information you have
It all depends on what your application needs.
The guide is generic
I just dont understand because I get the error for customer is not existing yet with it set up that way.
Can you share the request ID?
Like how can i send the customer id if its not created
If its not created then you don't need to use customer field at all
Let's take a step back
What's your end goal?
What flow are you trying to integrate exactly?
I have a pizza place that takes orders. I wrote the code entirely myself. I have it set up so they can take orders and it prints out and everything. When a customer orders they are instantly charged the amount that is listed. This is a pizza place and not every single combo of items and extras for that item can be handled. If the pizza place gets an extra request on a specific item and they require additional payment for it they can go into the admin portal that I built and then go to that specific order and add/change the amount for an item. After they do this since the person already paid obviously I need to recharge the card/method they paid with. I am trying to set up Customers in stripe so everytime someone orders and completes their payment it gets saved somehow and when the store goes into the admin portal they can do what they have to do and when they are done they can click submit and the card gets charged the additoonal amount that was added to the order
That is exactly what I am looking to do
You said 'If its not created then you don't need to use customer field at all' The thing is I need this to be created and then sent and saved
I just need to know where/how it needs to be created
Okay thanks for the context, we ideally support two ways of storing a PaymentMethod
1/ While the customer is paying for something
https://stripe.com/docs/payments/save-during-payment
2/ While the customer isn't paying for something but only providing the payment method for future use
https://stripe.com/docs/payments/save-and-reuse
(adding more..)
Okay I would be using #1 I just dont know when to create the customer
For 1/
You have a couple of options, you can either create a customer prior to creating a PaymentIntent and then use their ID in customer param when you create the PaymentIntent as shown here
https://stripe.com/docs/payments/save-during-payment?platform=web#web-create-a-customer
https://stripe.com/docs/payments/save-during-payment?platform=web#web-create-payment-intent
OR the other option is to not create a customer object until the PaymentIntent with setup_future_usage: off_session succeeds. You won't need to use customer parameter here when you create a PaymentIntent. Once the payment succeeds, you can retrieve it and find the PaymentMethod ID of the object that was created
https://stripe.com/docs/api/payment_intents/retrieve
https://stripe.com/docs/api/payment_intents/object#payment_intent_object-payment_method
And then call attach payment method to customer using the API endpoint here
https://stripe.com/docs/api/payment_methods/attach
Can i just create the customer at the top of this method?
Can i just create the customer at the top of this method?
You can, yes.
The reason this is confusing is because the timing of creating a customer object on stripe depends fully on how your integration is designed to work.
As I mentioned earlier, you decide when the customer gets created.
I.e. when they sign up on your app etc...
Typically developers create a customer object when a user signs up and stores the customer ID in their database, this allows them to retrieve this ID when they create a Payment
I just dont think i can do it that way unless i prompt them with the payment element when signing up right?
You don't need to collect the payment method right away though
You can just create the customer object and store the ID in your Database.
Okay that makes sense
Awesome, glad I could help clarify.
Might have a few more questions honestly sorry
Sure
So would it be like this if I am setting it in that method i sent before
I just am not sure what to send in the customer param
Like the correct ID
Like is the customer Id created from the 1st 3 vars in that screenshot?
๐ stepping in for my teammate!
so customer will be an object. you will need to use its ID when creating the PaymentIntent if you want to associate the payment with that particular customer (and attach the payment details to that customer)
so just customer.id?
I think hanzo was suggesting you can add some logging to "print" the customer object so you can get a sense for its shape
I am now just struggling with sending the token from the parent of my checkout form
I am creating the paymentIntent in my CheckoutForm and the parent of that component is Payment. I need to send the paymentIntent that is created in the child where I stripe.confirmPayment()
Is there anyway I can create the payment intent in the parent and then set it in the child with that stripe.confirmPayment()
Or do these have to be at the same level somehow
I'm not sure I follow what you mean by levels. You're creating a PaymentIntent server side, passing the PaymentIntent's client secret to your frontend, and using this client secret to initialize Elements. Since you're passing along elements when calling confirmPayment, you're using the previously-created PaymentIntent
I am trying to send it from react
Level meaning parent or child component
When the paymentIntent is set in that 1st screen shot it is Stripe element not a normal variable.
So how can i create that in my parent and then set it in my child so that is correctly set when the parent makes the call to that server route
Do you know what I mean or no
Got it. I'm not a React expert and I see this has been a very long discussion. I recommend working with our sample quickstart guide then tailoring this as needed for your use case. This should give you a working integration that you can start with and reference as you edit it to fit your needs: https://stripe.com/docs/payments/quickstart
If you run into specific errors while you edit, we're happy to help debug those
@hollow flume let's continue to chat in this thread!
Is there a way I can update a customer that is created in my stripe account while they are creating a payment?
Okay
That was what i sent
Can you be more specific? Like, is your question whether you can pass along values to update a customer object in the same request as a PaymentIntent creation request?
I want to update this customers payment method since how I am going to be doing it I will set the customer when a user signs up.
Yes that is my question
I will have a customer but just not have their payment method filled out until after they create their first payment
Is that possible?
If you're creating a PI and are passing along setup_future_usage because you intend to use the PaymentMethod for future charges, you can pass along a value for customer to attach that PaymentMethod to a specific customer. That's really the only customer "update" you can make as part of PaymentIntent creation
If there's anything else about the customer object that you want to change, that would have to be changed in a separate update call
How can i pass along the PaymentMethod to the customer value?
Arent you supposed to send just the customer id to the customer value?
We'll do this automatically for you if you include a customer ID and use setup_future_usage when creating a PaymentIntent: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-customer
Awesome!
There's no need to make a separate request to attach the PaymentMethod to a customer as long as you pass along the customer ID and setup_future_usage
so setup_future_usage can take one of two possible values: on_session or off_session. either value will save/attach the PaymentMethod to the customer you specify. on_session means you plan on charging the PaymentMethod at a future date while your customer is actively within your application, while off_session means you plan on charging them at a future date when they're not actively using your application
Using my application what exactly doesthat mean
Like signed into an account with my application?
How can stripe track that?
I will be charging the customer right away on the 1st order and then if the store needs to change the amount of the order I will have it so they can click a button and it will charge that persons payment_method that was used for the order in the 1st place
We're not tracking that. It's up to you to tell us with this parameter how you plan on charging the customer's saved card at a future date
What does the user being signed in have to do with that though?
Did you see my description
Which one would work better with that
Like if its on_session and the user is signed in on my application are you saying it wont work?
Based on your description, you should use off_session
or does on_session mean it is not charged until after a button is clicked confirming the charge
Okay
if the store needs to change the amount of the order I will have it so they can click a button and it will charge that persons payment_method that was used for the order in the 1st place
In this scenario that you described, your customer won't actively be in your checkout flow for this charge, which is why you should useoff_session
Since your customer is in your checkout flow for the first order ("charging the customer right away"), yes, this payment can technically be described as "on_session" but you don't need to flag this anywhere
Okay but it just cant be off_session
?
So i will have to make 2 different paymentIntents in my server?
That is my last question im so sorry
Okay, I think there's a misunderstanding. If you're charging a customer right away and want to save their payment details to charge them again in the future without them having to be in your checkout flow, you just need to create one PaymentIntent and use setup_future_usage: off_session
Can i return my Customer id somehow with this route?
This is what i get in my clients logging when logging the response from that route how it is now
I need to set the customerid in my database with this route
the result of this route*
Is there more to those logs? We're not really here to do code reviews but if you're running into an error I can help review that
No i just want to know how to return the customerId with that route
Its just not giving me the data that is in customer
Is that possible
Like how do i return the id is all i want. The guy before told me that people set the customerID in their database after a user signs up. I am doing what he said i just need to retunr the id so i can put it in my database and use it
I think we're going around in circles. Are you able to log/inspect the customer value?
Thats exactly what i was doing
But the logs were the picture i sent you
We are not going in circles I have got a tremendous amount done today
I figured it out it had to do with how I was retuning my data for some reason it wasnt actually giving me the data until i changed something small
Got it. Okay, so just to make sure we're on the same page, can you summarize where you're currently blocked?
kyleruban-integration-help