#syed-confirm-client-secret

1 messages ยท Page 1 of 1 (latest)

tropic nimbus
#

Hi there!

winter briar
#

๐Ÿ‘‹

#

thanks for making a thread!

tropic nimbus
#

Sure!

#

What does your console.log(clientSecret) print out?

winter briar
#
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:
tropic nimbus
#

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...

winter briar
#

๐Ÿ‘

tropic nimbus
#
    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

winter briar
#

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

tropic nimbus
#

Okay so let's add a log before const { clientSecret, error: backendError } = await response.json(); that is just console.log(response)

winter briar
#

๐Ÿ‘

#

sorry had to go afk for a minute

tropic nimbus
#

np!

winter briar
tropic nimbus
#

Great

#

So that's the issue

#

Something on your server

#

Not your client

winter briar
#

gotcha ๐Ÿ‘

tropic nimbus
#

So I'd recommend checking your server logs next

winter briar
#

will do, I'll come back here once I've given inspecting my backend a solid attempt

winter briar
#

I'm having a hard time pinpointing exactly what's wrong with the server implementation

visual bridge
winter briar
#

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 ๐Ÿ‘

visual bridge
#

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.

winter briar
#

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
visual bridge
#

You aren't passing an amount. That's not going to work

winter briar
#

shoot, got it. thank you!

visual bridge
#

You can review the input syntax in the snippet to the right on that doc