#Ese
1 messages · Page 1 of 1 (latest)
Do you have the checkout session ID?
yes
should the session ID in the json render be the same as the link, like something like this: https:// chekout.stripe.com/c/pay/sessionID
Or do you have the checkout URL?
Yes, that is also in the json render
If you can share with me the checkout URL or a checkout session ID, I'd investigate further
I have no problem opening this checkout page
yes. Me too when I just use the link directly. But when it is used in through the site it does not work
what you mean by " used in through the site " ?
Like I have a method that creates the stripe session. When the submit button is clicked it takes me to this method that creates the stripe:
:session.create({}). when that is finished being created there is a code: "redirect_to session.url, allow_other_host: true". This snippet of code is supposed to redirect me to the stripe checkout and it does. But when I get to the stripe checkout page, it fails.
The terminal shows the link that is being redirected to and when I click the link from there it works which does not make sense
Can you show me your code?
Ya, here it is:
def stripe
@gaunt stagsion = Stripe::Checkout::Session.create({
payment_method_types: ['card'],
line_items: [Checkout.stripify(@cart, "USD")],
mode: 'payment',
# customer_email: ,
success_url: checkout_success_url,
cancel_url: checkout_cancel_url,
})
redirect_to @gaunt stagsion.url, allow_other_host: true
end
Checkout.stripify(@cart, "USD")] looks like:
Create the static stripe format
def self.stripify(cart, curr)
result = Array.new
cart.cart_products.each do |cart_product|
product = cart_product.product
result<<({
:price_data => {
:currency => curr,
:unit_amount => product.price,
:product_data => {
:name => product.name
}
},
:quantity => cart_product.quantity
})
end
return result
end
What is stripify?
Just the name of a static method that I created to organize the line_items correctly and dynamically. I also provided what that method looks like
It returns an array of what line_items should look like
How does your frontend respond to the result from your backend?
What do you mean. When they press the checkout button it goes from an overview page directly to the stripe website to perform payment. They don't really see that there is the stripe method as a middle man
The bakend goes from the overview page to the stripe method then redirects to the stripe payment portal
The forntend looks like it goes from the overview page directly to the stripe payment portal
Hi! I'm taking over this thread.
Can you clarify exactly how you do the redirect on the frontend? Because that's probably where the issue is.
There is a page with on these two lines of code:
You have gotten to the overview page
<%= link_to "Checkout", checkout_stripe_path %>
In the routes file there is code that connects the method I provided before to the front end link_to action. The routes code are:
get 'checkout/stripe'
get 'checkout/success'
get 'checkout/cancel'
So it's just a regular link to the Checkout Session url?
Do you have a link where I could reproduce the issue?
Everything is run on localhost:3000
You didn't answer my question:
So it's just a regular link to the Checkout Session url?
Oh, the link on the frontend goes to the stripe method I provided before, then that stripe method runs and creates the stripe session then automatically redirects to the stripe portal
OK, there are two ways to make the redirect work:
- Return the checkout.url from your backend to your frontend, and then on the frontend update the
window.location - Or do a <form action="xxx" method="POST"> on the frontend with an
actionthat points to your backend, and the backend can do a redirect
For the second method, instead of using the regular link_to I should try the form action?
Yes, can you give it a try and see if it fixes the issue?
Ok, I will try both methods. I will let you know if it works thank you
It worked, thank you very much.
I used the first method but instead of using the window.location I changed the link_to to go to the stripe portal instead of the stripe method.
Since it works I am happy but in the web console I get bombarded with a lot of Content Security Policy errors. Could that be an issue
Ya, the errors come when I am going to checkout.stripe.com. I will ignore it for now since there are no real issues and I will find a way to whitelist stripe so I don't get those errors
Thank you again
Sounds good!