#akakemushi_code

1 messages ยท Page 1 of 1 (latest)

spark radishBOT
#

๐Ÿ‘‹ 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.

worldly reefBOT
#

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.

crimson crane
#

Hi there!

wheat pendant
#

Hi again!

crimson crane
#

What have you tried so far? I see my colleague recommended using Class#create or Class#new to create a checkout session, not both

wheat pendant
#

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

crimson crane
#

Okay, I see you are creating Checkout Sessions successfully

wheat pendant
#

I'm happy to share whatever parts of my code that will help you diagnose the issue. I'll remove sensitive info as needed.

crimson crane
#

The Javascript code you shared above is waiting for the results of the /create-checkout-session endpoint from your server

wheat pendant
#

to be perfectly honest, the javascript I shared above is copied almost verbatum from the example given on your site

crimson crane
#

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

wheat pendant
#

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

crimson crane
#

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

wheat pendant
#

sure thing

fallen dome
#

Hello

wheat pendant
#

Hi there!

#

As I told roadrunner, I'm happy to share whatever code that will help you diagnose the issue.

fallen dome
#

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?

wheat pendant
#

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

fallen dome
#

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

wheat pendant
#

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?

fallen dome
#

No, client-secret will be generated each time your user visits the page that calls /new

wheat pendant
#

by Stripe.js?

fallen dome
wheat pendant
#

Ok, I can probably work with that-- any tips on what the differences between this and embedded would be?

fallen dome
#

You mean difference between PaymentElement and Embedded Checkout?

wheat pendant
#

Yes

fallen dome
wheat pendant
#

One issue I've been having a lot when trying to solve this problem myself is outdated info...

fallen dome
#

Yeah Ruby on Rails isn't really popular these days for new integrations

wheat pendant
#

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.

fallen dome
#

Just something that I want to confirm.
Sure

wheat pendant
#

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?

fallen dome
wheat pendant
#

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.

fallen dome
#

Correct, it is not required

wheat pendant
#

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?

fallen dome
#

I don't unfortunately. We don't familiarize much with third-party offerings

wheat pendant
#

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.

fallen dome
#

NP! ๐Ÿ™‚ Good luck