#emnaruto07-console-error
1 messages · Page 1 of 1 (latest)
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.
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)
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
??
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?
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
So do i have to use window.location something?
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
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
I don't have the JS code you're looking for, but if you're looking for a specifically non-JS option, I'd recommend checking out the quickstart guide: https://stripe.com/docs/checkout/quickstart
but it didn't worked yesterday
I'm doing this checkout stuff only
Yeah, if you're only doing Checkout stuff, follow the Ruby guide I posted
Are you using a 3rd party app?
Or are you just developing locally on your computer?
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)
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in ord...
ok
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.