#akakemushi_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
Hi there
Hello
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?
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.
Stripe::APIConnectionError in CheckoutsController#new
Timed out connecting to Stripe (https://api.stripe.com). Please check your internet connection and try again. If this problem persists, you should check Stripe's service status at https://status.stripe.com, or let us know at support@stripe.com.
(Network error: Failed to open TCP connection to api.stripe.com:443 (Connection timed out - user specified timeout))
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?
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.
Can you share your server side code? Please omit your test secret key and any other sensitive details
Of course. Would you like the ruby controller code?
Any code where you're setting up server details
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
Hello ๐
Taking over here
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...
- User navigates to the checkout page where the payment form will be.
- Javascript on the user's machine sends their client secret to Stripe servers.
- Stripe returns a session key (or something of that nature) to the client.
- The session key is passed to my backend servers (at some point? not sure when)
- The user fills in their credit card info, and upon submit, it goes to Stripe, not to my servers.
- Stripe then processes the payment and then returns the status (and maybe the session key?) to my servers
Oh, hello
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
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
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.
Ok, should I request you specifically?
Not really, whoever is around tomorrow should be able to help
Alright, thanks.