#paarth bajaj
1 messages · Page 1 of 1 (latest)
Is the any chance you can redirect from backend?
No sir
Error
Access to fetch at 'https://checkout-cookies.stripe.com/api/get-cookie' from origin 'https://checkout.stripe.com' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
GET https://checkout-cookies.stripe.com/api/get-cookie net::ERR_FAILED 200
Uncaught (in promise) FetchError: Error fetching https://checkout-cookies.stripe.com/api/get-cookie: Failed to fetch
at cs_test_a1Hsojvb...................
Backend code
try {
let reqFields = ["customerId", "paymentMode", "priceId", "success_url", "cancel_url", "distinctName", "productId", "planId"];
const payload = JSON.parse(event.body) || {};
const user = await getUser(event.headers.Authorization);
const userId = user.UserAttributes["custom:dbUserID"];
const { customerId, paymentMode, priceId, success_url, cancel_url, productId, distinctName, planId} = payload;
const session = await stripe.checkout.sessions.create({
customer: customerId,
line_items: [{ price: priceId, quantity: 1 }],
mode: paymentMode,
success_url,
cancel_url,
metadata: {
distinctName,
productId,
planId,
userId
}
});
console.log(session);
_HTTP_201_CREATED["body"] = JSON.stringify({
status: "success",
data: {url: session.url} ,
message: "",
});
return _HTTP_201_CREATED;
} catch (e) {
console.log(e);
return _HTTP_500_INTERNAL_SERVER_ERROR;
}
This is network call
Strange thing is this is completely random and sometime error occurs and some time it doesn't
Just asking, if you use the JS method https://stripe.com/docs/js/deprecated/redirect_to_checkout would you see the issue?
(Not sure if this is callable from JS)
Ok so you want me to redirect to checkout page from backend?
No this is redirection from frontend. I just want to test to narrow down the issue
Oh ok
I need to install stripe at frontend as well
Um I just tested and window.open works fine for me. Can you try a simple integration without React?
Till now, I haven't included stripe at frontend
Yes it works fine for me as well but not every time 5/10 times it gives me cors error
Um all of this would be way easier if you just use the form and redirection from backend
What is the main reason prevent you to do so:?
-
I am reading this discord chat from yesterday, and I have read this a lot of times from stripe support that do not redirect from backend code.
-
How it is different if I use button make my backend api call instead of form?
Form and redirection is the default behavior we support, so I believe it should have less CORS quirk (hopefully)
Could you share some example when we advise to not redirect from backend? It's the default implementation: https://stripe.com/docs/payments/accept-a-payment?platform=web
Ok let me do it from the backend then