#emnaruto07-console-error

1 messages · Page 1 of 1 (latest)

remote otter
#

Hi there! I wouldn't recommend posting code with your API key in it (even if it is your API test key), so I deleted the code you posted.

sly knot
#

Don't worry about the key, its only half

#

and secondly its a test key

remote otter
#

Regarding the error you're seeing: it looks like you might be trying to redirect via fetch() to the Checkout Session URL. Are you able to post all the relevant code to this thread so I can look again?

#

(minus the API key)

sly knot
#

ok

#
  def pricing
    Stripe.api_key = 'key'

    session = Stripe::Checkout::Session.create({
      line_items: [{
        # Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
        price: 'price_1KJDWQDaN18cbJKsBh451B4C',
        quantity: 1,
      }],
      mode: 'payment',
      success_url: root_url + 'success',
      cancel_url: root_url,
    })
    redirect_to session.url, allow_other_host: true
  end

end
#

this is rails

#
              <button class="inline-block py-3 px-7 w-full md:w-auto text-lg leading-8 text-red-50 font-medium text-center bg-black hover:bg-gray-900 hover:shadow-red-800/90 border-2 border-solid rounded border-red-900 shadow-2xl" type="submit">🔒 Post a job - $299</button>
            </div>``` this is the submit button.
#

i didn't use any js yet

sly knot
#

??

remote otter
#

Hi there, apologies for the delay. It looks like you are using JS somewhere, as fetch() is being called to get the Checkout Session ID

#

Are you able to step through the code to find out where?

sly knot
#

I'm not using any js

#

the only js i'm using is stripe JS

remote otter
#

Either way. You're trying to redirect to the Checkout Session URL on the Server side via a fetch() call. In order to get the Checkout Session to render in the browser, you need to return the Checkout Session to the client and let the redirect happen there

sly knot
#

So do i have to use window.location something?

remote otter
#

You need some amount of JS for this to work, so if you're not using JS, you will need to, because in order for Stripe to render the Checkout Session in the browser, you need to have client handlers that do things asynchronously

sly knot
#

Do you have that js code?

#
    const res = await fetch(`${process.env.BACKEND_API_URL}/create-checkout-session`, {
      method: 'POST',
      headers: {
        "Content-Type": 'application/json'
      }
    })
    const body = await res.json()
    window.location.href = body.url
  }
#

i have found this

remote otter
sly knot
#

but it didn't worked yesterday

sly knot
remote otter
#

Yeah, if you're only doing Checkout stuff, follow the Ruby guide I posted

sly knot
#

I'm following that guide only

#

its not working

remote otter
#

Are you using a 3rd party app?

#

Or are you just developing locally on your computer?

sly knot
#

Locally

sly knot
#

DO

remote otter
#

So your CORS policy looks like it's blocking all of your requests. It might be worth looking into that first, because that is a configuration on your server (not on Stripe's side)

sly knot
#

ok

remote otter
#

The problem from the image seems to indicate that (on top of not being able to make the request to Stripe) you also cannot make requests internally. So I'd solve that problem first.