#Ese

1 messages · Page 1 of 1 (latest)

sullen mothBOT
cosmic glen
#

Do you have the checkout session ID?

grave night
#

yes

cosmic glen
#

Or do you have the checkout URL?

grave night
#

Yes, that is also in the json render

cosmic glen
#

If you can share with me the checkout URL or a checkout session ID, I'd investigate further

cosmic glen
#

I have no problem opening this checkout page

grave night
#

yes. Me too when I just use the link directly. But when it is used in through the site it does not work

cosmic glen
#

what you mean by " used in through the site " ?

grave night
#

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:checkout: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

cosmic glen
#

Can you show me your code?

grave night
#

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

cosmic glen
#

What is stripify?

grave night
#

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

cosmic glen
#

How does your frontend respond to the result from your backend?

grave night
#

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

sullen mothBOT
simple birch
#

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.

grave night
#

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'

simple birch
#

So it's just a regular link to the Checkout Session url?

#

Do you have a link where I could reproduce the issue?

grave night
#

Everything is run on localhost:3000

simple birch
#

You didn't answer my question:

So it's just a regular link to the Checkout Session url?

grave night
#

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

simple birch
#

OK, there are two ways to make the redirect work:

  1. Return the checkout.url from your backend to your frontend, and then on the frontend update the window.location
  2. Or do a <form action="xxx" method="POST"> on the frontend with an action that points to your backend, and the backend can do a redirect
grave night
#

For the second method, instead of using the regular link_to I should try the form action?

simple birch
#

Yes, can you give it a try and see if it fixes the issue?

grave night
#

Ok, I will try both methods. I will let you know if it works thank you

grave night
#

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

simple birch
#

The errors appear once you are on the Stripe link?

#

I think you can ignore these.

grave night
#

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

simple birch
#

Sounds good!