#akakemushi_code

1 messages ยท Page 1 of 1 (latest)

warped gladeBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1265066584238587977

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

crude adder
#

Hi there

leaden rivet
#

Hello

crude adder
#

For your use case, it makes sense to use price_data instead of creating reusable Prices

#

As for using Embedded Checkout with Sinatra, can you share more details on the error you see?

leaden rivet
#

Ah no, I'm not using sinatra, I'm using rails. I wanted to say that the docs on your site give examples with sinatra, but not rails.

crude adder
#

Hm are you able to make other requests to api.stripe.com from this machine?

#

Like, if you make a cURL request, does that work fine?

leaden rivet
#

Well, I installed that Stripe CLI and I can make requests through that

#

I haven't tried cURL (mostly because I'm still learning and am not comfortable using it yet if I'm being honest)

#

ok, I just tried a cURL request and did get a JSON response, so that seems to work fine.

crude adder
#

Can you share your server side code? Please omit your test secret key and any other sensitive details

leaden rivet
#

Of course. Would you like the ruby controller code?

crude adder
#

Any code where you're setting up server details

leaden rivet
#

There's redundant code in here at the moment because I've been trying so many things for the last 10 hours or so.... At the moment I'm not sure I should be setting the form up through the "new" method or the "create" method. I know that one of those will need to be deleted/changed.

require "stripe"

class CheckoutsController < ApplicationController

def new
session = Stripe::Checkout::Session.create({
payment_method_types: ['card'],
line_items: [{
price_data: {
currency: 'jpy',
product_data: {
name: 'yokode teapot',
},
unit_amount: 123456,
},
quantity: 1,
}],
mode: 'payment',
ui_mode: 'embedded',
return_url: 'http://127.0.0.1:3000/checkouts/create'
})

render json: { clientSecret: session.client_secret }

end

def create
session = Stripe::Checkout::Session.create({
payment_method_types: ['card'],
line_items: [{
price_data: {
currency: 'usd',
product_data: {
name: 'T-shirt',
},
unit_amount: 2000,
},
quantity: 1,
}],
mode: 'payment',
ui_mode: 'embedded',
return_url: 'http://127.0.0.1:3000/checkouts/create'
})

render json: { clientSecret: session.client_secret }

end

def session_status
session = Stripe::Checkout::Session.retrieve(params[:session_id])
customer = Stripe::Customer.retrieve(session.customer)

render json: {
  status: session.status,
  payment_status: session.payment_status,
  customer_email: customer.email
}

end
end

warped gladeBOT
frank hemlock
#

Hello ๐Ÿ‘‹
Taking over here

leaden rivet
#

It may help me know understand the "flow" of data and keys to and from the Stripe server. From what I can gather, it goes something like this...

  1. User navigates to the checkout page where the payment form will be.
  2. Javascript on the user's machine sends their client secret to Stripe servers.
  3. Stripe returns a session key (or something of that nature) to the client.
  4. The session key is passed to my backend servers (at some point? not sure when)
  5. The user fills in their credit card info, and upon submit, it goes to Stripe, not to my servers.
  6. Stripe then processes the payment and then returns the status (and maybe the session key?) to my servers
#

Oh, hello

frank hemlock
#

can you try downloading this script and running it on your machine? It should help clarify if the machine is having issues connecting to Stripe

leaden rivet
#

sure, just a second.

#

Seems to have worked

frank hemlock
#

In the meantime, I can help clarify the flow of things here..

Typically with Rails as you might already know, Class#new is used for GET request to instantiate instance variable & Class#create is used for POST request to handle form submissions and use the instance variables created in #new

Here though since you're embedding a form, you don't really make a POST request to your server on submission. Meaning there's no use for you Class#create in this case..

However, it really depends on your app. You could either use Class#create or Class#new to create a checkout session secret. You don't need both

leaden rivet
#

Yea, I know... ChatGPT is partially to blame... as I told the other guy helping me, I'm pretty green (fresh out of boot camp) and still on a steep learning curve.

#

Hey, I want to continue this conversation but I'm on Japan time here, can I pick this up tomorrow? I need to head to work soon.

frank hemlock
#

The thread will be closed but you can open up a new thread via #help any time ๐Ÿ™‚

leaden rivet
#

Ok, should I request you specifically?

frank hemlock
#

Not really, whoever is around tomorrow should be able to help

leaden rivet
#

Alright, thanks.