#kyleruban-integration-help

1 messages ยท Page 1 of 1 (latest)

timber palmBOT
hollow flume
#

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!

timber palmBOT
hollow flume
#

Hey Hanzo! Have you seen an error like this before?

mighty blaze
#

Hey there, do you have an example of this failure you can share?

hollow flume
#

What do you want me to share

mighty blaze
#

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

hollow flume
#

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?

mighty blaze
#

I have a server route that is creating a payment intent
That's where you'd set setup future usage

hollow flume
#

what do i have to do differently in there

#

It is the 2nd picture

mighty blaze
#

set the setup future usage option

#

Did you click the link i sent? It shows examples of this

hollow flume
#

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

mighty blaze
#

Where do you get that error?

mighty blaze
hollow flume
#

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

mighty blaze
hollow flume
#

I get that error in my console when hitting the server side create payment element route

#

req_XAvwnBjVqR79RZ

#

that is the error

potent drift
#

Stripe Customer IDs have cus_xxx prefixes

hollow flume
#

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?

potent drift
#

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

hollow flume
#

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

potent drift
hollow flume
#

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

potent drift
#

Or like how can i set the customers payment method before the payment is successful
We support both

hollow flume
#

So do i have to create an empty customer for it to work?

potent drift
#

You can prefill the information you have
It all depends on what your application needs.

The guide is generic

hollow flume
#

I just dont understand because I get the error for customer is not existing yet with it set up that way.

potent drift
#

Can you share the request ID?

hollow flume
#

Like how can i send the customer id if its not created

potent drift
#

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?

hollow flume
#

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

potent drift
hollow flume
#

Okay I would be using #1 I just dont know when to create the customer

potent drift
#

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

hollow flume
#

Can i just create the customer at the top of this method?

potent drift
#

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

hollow flume
#

I just dont think i can do it that way unless i prompt them with the payment element when signing up right?

potent drift
#

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.

hollow flume
#

Okay that makes sense

potent drift
#

Awesome, glad I could help clarify.

hollow flume
#

Might have a few more questions honestly sorry

potent drift
#

Sure

hollow flume
#

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

timber palmBOT
hollow flume
#

Like is the customer Id created from the 1st 3 vars in that screenshot?

potent drift
#

yes

#

you can print customer

hollow flume
#

What do you mean print

#

Is it an object that contains the id?

placid plinth
#

๐Ÿ‘‹ 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)

hollow flume
placid plinth
#

I think hanzo was suggesting you can add some logging to "print" the customer object so you can get a sense for its shape

hollow flume
#

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

placid plinth
#

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

hollow flume
#

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

placid plinth
#

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!

hollow flume
#

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

placid plinth
#

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?

hollow flume
#

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?

placid plinth
#

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

hollow flume
#

How can i pass along the PaymentMethod to the customer value?

#

Arent you supposed to send just the customer id to the customer value?

placid plinth
hollow flume
#

Awesome!

placid plinth
#

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

hollow flume
#

= "off_session",

#

or make it = something else?

placid plinth
#

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

hollow flume
#

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

placid plinth
#

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

hollow flume
#

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?

placid plinth
#

Based on your description, you should use off_session

hollow flume
#

or does on_session mean it is not charged until after a button is clicked confirming the charge

#

Okay

placid plinth
#

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 use off_session

hollow flume
#

Okay that makes sense

#

But the 1st way will be on_session right?

placid plinth
#

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

hollow flume
#

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

placid plinth
#

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

hollow flume
#

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*

placid plinth
#

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

hollow flume
#

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

placid plinth
#

I think we're going around in circles. Are you able to log/inspect the customer value?

hollow flume
#

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

placid plinth
#

Got it. Okay, so just to make sure we're on the same page, can you summarize where you're currently blocked?

timber palmBOT
golden pilot
#

kyleruban-integration-help