#syed-confirm-client-secret
1 messages ยท Page 1 of 1 (latest)
class PaymentIntentController < ApplicationController
skip_before_action :verify_authenticity_token
def create
content_type 'application/json'
data = JSON.parse(request.body.read)
payment_method_type = data['paymentMethodType']
currency = data['currency']
intent = {
payment_method_types: payment_method_type,
amount: 2000,
currency: currency,
payment_method: current_user.payment_method_id,
customer: current_user.stripe_customer_id,
confirm: true,
}
begin
payment_intent = Stripe::PaymentIntent.create(intent)
rescue Stripe::StripeError => e
halt 400,
{ 'Content-Type' => 'application/json' },
{ error: { message: e.error.message }}.to_json
rescue => e
halt 500,
{ 'Content-Type' => 'application/json' },
{ error: { message: e.error.message }}.to_json
end
{
clientSecret: payment_intent.client_secret,
}.to_json
end
end
```Not sure if this is relevant, but I've already saved and stored my user's payment method
Here's what's printed out when i console log:
So yeah that's the issue. It is also going to get confusing when you mix using await and .then
I really recommend only using one or the other
So let's adjust your code above...
๐
url2,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
currency: 'usd',
paymentMethodType: 'card',
}),
}
)
const { clientSecret, error: backendError } = await response.json();```
Then let's see what your log shows
got it, will make the changes now
strange, still spitting out the same errors
clientSecret is also still undefined, i accidentally cut that part off
Okay so let's add a log before const { clientSecret, error: backendError } = await response.json(); that is just console.log(response)
np!
gotcha ๐
So I'd recommend checking your server logs next
will do, I'll come back here once I've given inspecting my backend a solid attempt
Hello, I hope it isn't too late to still ask for help in this thread it seems like when I try to create my payment intent, it doesn't take all of the values that I wish to be passed. it only takes the paymentMethodType and currency. But it doesn't take the other parameters that I have listed here
I'm having a hard time pinpointing exactly what's wrong with the server implementation
Hi ๐
I'm stepping in as @tropic nimbus had to go. I can't really see what you are referencing in the screenshot. Can you find the API request ID for this request and share it with me?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
yep i can do that ๐ also sorry, I'll point it out once i grab the request id
It doesn't look like my request hit the API since my server errored out. As for what I'm referencing in the screenshot, I'm pointing at the parameters that are being passed to my create method. Only the paymentMethodType and currency are being passed to my create method, but the other stuff i have defined in my intent variable is not
Apologies if this is outside of the scope for what Stripe Support covers. Just let me know and I'll find help in a more appropriate place ๐
Okay could you paste your code directly in here as text between three ` marks? I just can't read what you are trying to share.
Oh sorry, I didn't realize it was too small
2022-08-17T20:35:11.906121+00:00 app[web.1]: I, [2022-08-17T20:35:11.906058 #4] INFO -- : Processing by PaymentIntentController#create as JSON
2022-08-17T20:35:11.906161+00:00 app[web.1]: I, [2022-08-17T20:35:11.906121 #4] INFO -- : Parameters: {"currency"=>"usd", "paymentMethodType"=>"card", "payment_intent"=>{"currency"=>"usd", "paymentMethodType"=>"card"}}
2022-08-17T20:35:11.909890+00:00 app[web.1]: I, [2022-08-17T20:35:11.909846 #4] INFO -- : Completed 500 Internal Server Error in 4ms (ActiveRecord: 1.1ms | Allocations: 625)
```The middle line is the main focus
shoot, got it. thank you!
You can review the input syntax in the snippet to the right on that doc