#TomConnolly - Checkout

1 messages · Page 1 of 1 (latest)

sour patrol
#

Hello! Can you provide more details about the issue? Are you seeing an error message? Can you share the code that's attempting to redirect? Is there anything useful in the browser console when this happens?

sour patrol
#

@indigo galleon You still around?

indigo galleon
#

No errors...

#

I create a price and when I visit the dashboard there's a link on the riight side to create a payment page, which is what I want the user to see when he submits the form.

sour patrol
#

Can you share the code here that's not working as expected?

indigo galleon
#

That's my point. None of my code is showing an error. I must be missing code that would launch that payment entry page.

#

I'm happy to show any code. Should I begin with the controller?

#

Here's the show page that has the button to Stripe:

sour patrol
#

Yeah, any code you can share related to the issue would be helpful!

indigo galleon
#

<h1><%= @donation.user.username.titleize %>'s donation is <%= formatted_amount @donation.amount %></h1>
<div class="text-center my-5" max-width="400px">
<%= button_to "Next", checkout_create_path, method: :post, params: { id: @donation.id }, class: "btn btn-success btn-lg", id: "checkout-button" %>
</div>

<% if current_user == @donation.user %>
<%= link_to 'Edit', edit_donation_path(@donation) %> |

<%= link_to 'Cancel this donation', new_donation_path %>
<% end %>

#

And here is the controller:

patent tendon
#

Hello, stepping in and catching up. Waiting for your controller code

indigo galleon
#

class CheckoutController < ApplicationController
protect_from_forgery except: :webhook
before_action :authenticate_user!

def create
@donation = Donation.find(params[:id])
if @donation.nil?
redirect_to root_path
return
end
checkout_session = Stripe::Checkout::Session.create({
success_url: donation_url(@donation) + "?session_id={CHECKOUT_SESSION_ID}",
cancel_url: donations_url,
payment_method_types: ["card"],
submit_type: 'donate',
customer: @donation.user.stripe_id,
line_items: [{
price: @donation.stripe_id,
quantity: 1,
description: "Donation to St. Paul's",
}],
mode: 'payment',
})
redirect_to checkout_session.url, allow_other_host: true
end
end

#

I create the price data in the model when the donation is saved, and use the update with the stripe_id for that payment. That works correctly.

patent tendon
#

So there is the "Next" button, and when customer click on it, your Rails app should take the Donation Id and create a Checkout, then perform a redirection. Which part of it is not working?

indigo galleon
#

Stripe is not returning anything to the browser. I am expecting it to show the payments page.

patent tendon
indigo galleon
#

Yes. All is correct there.

#

I'm thinking it has something to do with my creating a price within my product.

patent tendon
#

So the session is created? Could you share the session id? (cs_xxx) or the request id? (req_xxx)

indigo galleon
#

I created one product with custom prices. Prices are generated programmatically. here's the cs: "id": "cs_test_a1m3w6l0pubEOHsNQtISDED1ku64TEIM6sKySPPVlYHn2LZ0umrZoSfrRk",

#

Looking at dashboard again, there's a button on the right side of the prices creation page that says "payment_links"

#

Wondering if I need to glom onto that for the user.

patent tendon
#

That's Payment Link, similar to Checkout but a no-code option, for people doesn't know to code but still want a link to send out to their customer

#

it looks normal I am looking at this line

redirect_to checkout_session.url, allow_other_host: true
#

Does it work if you replace checkout_session.url to any URL?

indigo galleon
#

Throws error

#

undefined local variable or method 'any'

patent tendon
#

it seems not related to the checkout_session object 🤔

indigo galleon
#

So how did you get the checkout session url that I didn't get?

#

(What I meant by exact same result is the behavior I am use to getting: correct logs but no user-facing payment page.

patent tendon
#

this is the request you send to Stripe. You can confirm it on your Dashboard. I checked the url in the response

#

if you print out checkout_session.url, you should see the value

#
redirect_to "https://stripe.com/", allow_other_host: true
indigo galleon
#

Sounds like there's something wrong with my redirect?

patent tendon
#

I think so. How does the request looks like in your browser?

#
redirect_to "https://stripe.com/", allow_other_host: true

This results in no redireciton?

indigo galleon
#

I Correct. Stays on the "Next" button page

patent tendon
#

The next step is to check Chrome console, see how the redirection looks like

#

It does look like a redirection issue to me

indigo galleon
#

Yep! Access to fetch at (checkout) blocked by CORS policy.

#

"Response to preflight request doesn't pass access control check: No "Access-Control-Allow-Origin' header is present on gthe requested resource...

patent tendon
#

Would it be the same if you change the url to, for example https://www.google.com/

indigo galleon
#

Yes. same exact error messages.

#

Same errors in Chrome and Edge. I'm on Ubuntu, using Rails 7, Ruby 3.1

#

Don't remember seeing anything about CORs in update messages for rails.

#

So It's not a Stripe issue at all, turns out. I'll make friends with Google. Thanks very much for your kind help and direction. I've spent lots of time on this, and your help is most appreciated.

patent tendon
#

You are welcome! I am happy to be useful as much as I can

#

"Fixing the “CORS” error"