#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/1265411813001138201
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- akakemushi_code, 22 hours ago, 32 messages
Hi there!
Hi again!
What have you tried so far? I see my colleague recommended using Class#create or Class#new to create a checkout session, not both
Yea, I've been working on the code and changed a bunch of things. I've tried to use your tutorial here as a model for my own... https://docs.stripe.com/checkout/embedded/quickstart
It's not exactly made for Rails though, so I'm having trouble with it.
Here's the short version of the problem...
I have an index page for the items in the user's cart.
At the end there's a LINK (I used to have a form, but I changed it) to the checkout page where the Stripe form is supposed to be mounted.
Clicking the link starts to initialize the Stripe form (some animations are shown which indicate that the page is trying to load the form)
after a few seconds the animations stop and theres a small message that just says "something went wrong"
In the console, there's error messages which say the following...
The resource https://js.stripe.com/v3/fingerprinted/js/checkout-embedded-app-init-cc0ad9a076f74f1e9d85e7889f940e30.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate as value and it is preloaded intentionally.
and also this one
embedded-checkout-inner-93fe8dba76e24c14ac1dc201844641168e7453d4.html?publishableKey=pk_test_51PRZH7LUzlW94Gjxt2h5pOO3pVExe4mQfsN7c2NYcbukYQNpgIyGfawZj2Kix6DcSlAQiepyZuIVKydFYejHf1u200w5daBgCb&onComplete=false&onShippingDetailsChange=false&mids[guid]=3a323e7e-f202-4cd1-8900-fb66a0f04aa85bff9b&mids[muid]=96ffb471-a5dc-4c81-ae62-e5e833b224727b2461&mids[sid]=6803f733-f402-4e1c-877f-be25c44ba33d066b8d:8 Error: Timed out waiting for client secret
at embedded-checkout-inner-93fe8dba76e24c14ac1dc201844641168e7453d4.html?publishableKey=pk_test_51PRZH7LUzlW94Gjxt2h5pOO3pVExe4mQfsN7c2NYcbukYQNpgIyGfawZj2Kix6DcSlAQiepyZuIVKydFYejHf1u200w5daBgCb&onComplete=false&onShippingDetailsChange=false&mids[guid]=3a323e7e-f202-4cd1-8900-fb66a0f04aa85bff9b&mids[muid]=96ffb471-a5dc-4c81-ae62-e5e833b224727b2461&mids[sid]=6803f733-f402-4e1c-877f-be25c44ba33d066b8d:8:310054
Okay, I see you are creating Checkout Sessions successfully
I'm happy to share whatever parts of my code that will help you diagnose the issue. I'll remove sensitive info as needed.
The Javascript code you shared above is waiting for the results of the /create-checkout-session endpoint from your server
to be perfectly honest, the javascript I shared above is copied almost verbatum from the example given on your site
Yep, I recognize it ๐
Can you share the bit of your code where you're creating a Checkout Session?
It should be in some controller
sure, right now it's in the Checkout controller in the "new" method
just a sec.
require "stripe"
class CheckoutsController < ApplicationController
def new
Stripe.api_key = ENV['STRIPE_SECRET_KEY']
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/success?session_id={CHECKOUT_SESSION_ID}'
})
{clientSecret: session.client_secret}.to_json
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
There are several parts of this that I'm not sure I'm handling right. For one, the return_url, and for another, the line_items
Give me a few minutes, I'll need to loop in a teammate who's more well versed in Rails. My test integrations use Sinatra
sure thing
Hello
Hi there!
As I told roadrunner, I'm happy to share whatever code that will help you diagnose the issue.
The issue is your fetch request timing out when your javascript runs since your server doesn't really have a /create-checkout-session route..
Can you clarify if you're only using ruby on rails as a backend or are you building an app that runs on rails full stack?
Are your frontend and backend apps separate?
No it's fullstack
The frontend code is also contained within the Rails project folders, if that's what you mean
It's using html.erb files and importmap
Yup that's what I was asking..
So in that case, you should already have access to the client secret when your app loads /new page..
You don't need a fetch separately
You need to assign that client_secret to an instance variable which then becomes available in your erb file
Oh? I'm completely lost when it comes to all the secret keys. I was under the impression that the client secret was generated uniquely for each user by Stripe. But you're saying that the "client secret" will be the same for all my users?
No, client-secret will be generated each time your user visits the page that calls /new
by the logic that's under Controller#new method.. Stripe.js will then use that client-secret to render checkout session.
I can't find a tutorial that works for embedded checkout, however there's this guide that shows you how you can create PaymentIntents + Use that to render Elements: https://ruby.mobidev.biz/posts/stripe-payment-gateway-integration-in-ruby-on-rails-app/#complete-the-payment-page
The flow for embedded checkout is similar to it..
Ok, I can probably work with that-- any tips on what the differences between this and embedded would be?
You mean difference between PaymentElement and Embedded Checkout?
Yes
We have the comparison here: https://docs.stripe.com/payments/accept-a-payment/web/compare-integrations
One issue I've been having a lot when trying to solve this problem myself is outdated info...
Yeah Ruby on Rails isn't really popular these days for new integrations
I'm learning that that hard way.... :/
I do have a question regarding the embedded form and products
Just something that I want to confirm.
Actually, I found this: https://www.youtube.com/watch?v=5AkIe_qP8v4
This is an end to end implementation of Stripe Embedded checkout with Ruby on Rails
Just something that I want to confirm.
Sure
When using the embedded form, does it become neccessary to create (register?) products and product prices on the Stripe website?
Or can you handle all of that information on your own backend and just pass in the info when it's neccessary?
It becomes re-usable if you create products on Stripe.
You can create inline products/prices too if needed using price_data parameter: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-line_items
Ok, but not required though. The teapots the site will sell are each unique, so re-usability is not really a thing that will be needed.
Correct, it is not required
And finally, it's my understanding that the 'stripe-rails' gem is a third party gem, but do you know anything about it, or if it is up to date?
I don't unfortunately. We don't familiarize much with third-party offerings
Ok, fair enough. Well I thank you for your time, and I'll go through the tutorials and references you provided today. If I have further questions I'll try to make another question tomorrow.
NP! ๐ Good luck