#arteym_checkout-redirect
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1299096191144820807
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there ๐ sounds like you're talking about generating a Checkout Session and seeing an error/exception when you navigate to it, is that right?
Are you seeing this in livemode, testmode, or both? Can you share the ID of a Checkout Session where you saw this? Are there any notes about an error being encountered in the browser's console when the Checkout Session errors?
both on live mode and test mode
yes the above is a screenshot of the error/exception
Gotcha. Do you have a publicly accessible test page where I can see this behavior? And are you able to share the ID of a Checkout Session where this happened (that ID should have a cs_test_ or cs_live_ prefix on it)?
cs_live_a1G18YTE91DZ6JV67zMtCTom27IWyNsPnwJurDyIWv73OfNpKMe6qzuZmd
Removing the link since this is for a live checkout session, and I don't want to risk anyone else in the server processing a real payment with it.
I'm able to access the session fine though. Do you see the error immediately or after you take an action on the page?
I'm also not quickly spotting any client-side logs indicating we encountered an error.
a few seconds later...sometimes i can type a few numbers for credit card no... then it stops
Hm ๐ค what browser are you using? Maybe that's a factor here.
chrome
same code was working in an older version of Stripe.net... so browser may not be the issue
That session is working fine for me. I haven't seen an error or exception on any browser I've tried to use to access it so far.
That's why I'm wondering if it's something environmental on the machine/brwoser accessing the session.
so maybe conflict with Blazor webassembly?
I don't know what that is
c# framework
havent tried... im only familiar with Blazor
Like the URL that you posted earlier that I deleted, if you copy/paste that into your browser does the page load as expected?
ok ill try that
yes it loads and responds correctly..so it is conflict in the Blazor command NavigateTo(url)
Gotcha!
Beats me why there is error...maybe you can consult Microsoft
I'm not sure either. I'm not familiar with how the framework you're referring to plays into this, like I'm not sure what parts of the flow you're using it for. If it's doing a client-side redirect, typically we don't recommend that anymore (we even stopped recommending using our redirectToCheckout function in our stripe.js library), because we noticed better and more consistent behavior if your server responds with a redirect to the URL instead.
have tried server approach.. ran into cross-origin error
arteym_checkout-redirect
@smoky sonnet the redirect from the server is the best approach. You hit CSP because you are likely doing the redirect during an AJAX request from Javascript instead of doing a form submission
copied exactly your docs for server
here is error:
Access to fetch at 'https://checkout.stripe.com/c/pay/cs_live_a1GW9yxPbOUoXN79BU32vg8HPoMs8YuJP9hFudyw2h4Sk1PGwBOnYOkAEt#fid2cGd2ZndsdXFsamtQa2x0cGBrYHZ2QGtkZ2lgYSc%2FY2RpdmApJ2R1bE5gfCc%2FJ3VuWmlsc2BaMDRMfWhEUklDU3RUNEQ2QTFtQURVMXJuTW9of2lOS1R3cWttRnc3MlI8UnV%2FXFZNYF1wUXVENXNxYk9fVVNyfXZVUmpDS3FQcz0yTX98aFR1NnZKf21IV241NUlkSD1kSjc8JyknY3dqaFZgd3Ngdyc%2FcXdwYCknaWR8anBxUXx1YCc%2FJ3Zsa2JpYFpscWBoJyknYGtkZ2lgVWlkZmBtamlhYHd2Jz9xd3BgeCUl' (redirected from 'https://localhost:7227/api/v1/Payments/create-checkout-session') from origin 'https://localhost:7136' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
yes that's exactly what I described and it means you did not follow the docs we have. You think you did, but you didn't. Extremely common mistake
Your client-side code calling that /api/v1/Payments/create-checkout-session endpoint you built is likely using fetch and making an AJAX request
public async Task<HttpResponseMessage> CreateCheckoutSessionAsync(CreateCheckoutSessionRequest req)
{
if (string.IsNullOrEmpty(_loggedInUser.Token) == false)
{
_apihelper.SetDefaultRequestHeaders(_loggedInUser.Token);
}
//string api = "/" + ApiRoutesPayments.CreateCheckoutSession;
//string api = $"{ _config["apiLocation"] }/api/{_controllerName}/create-checkout-session";
string api = $"/api/v1/{_controllerName}/{ApiRoutesPayments.CreateCheckoutSession}";
return await _apihelper.ApiClient.PostAsJsonAsync(api, req);
}
yes see this is not what our docs say right? You wrote this yourself with PostAsJsonAsync and didn't do a real form submission
the PostAsJsonAsync just passes the data to server - email, priceid, cancel and success url; it is not sent to stripe ...but the server code is from your docs....stripe-sample-code.zip
like so:
[HttpPost]
public ActionResult Create()
{
var domain = "http://localhost:4242";
//var priceOptions = new PriceListOptions
//{
// LookupKeys = new List<string> {
// Request.Form["lookup_key"]
// }
//};
//var priceService = new PriceService();
//StripeList<Price> prices = priceService.List(priceOptions);
var options = new SessionCreateOptions
{
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
//Price = prices.Data[0].Id,
Price = "price_1MtsBjLFVqQ1A3D462EPohLt",
Quantity = 1,
},
},
Mode = "subscription",
SuccessUrl = domain + "/success.html?session_id={CHECKOUT_SESSION_ID}",
CancelUrl = domain + "/cancel.html",
};
var service = new SessionService();
Session session = service.Create(options);
Response.Headers.Add("Location", session.Url);
return new StatusCodeResult(303);
This is just your server-side code which is unrelated. The problem is with the client-side code that I described above.
You kind of need to understand how HTTP request works and the different flows that exist. You are currently making a request that says "please send me a response in JSON" and if your server-side code redirects then it breaks the browser. So you need to fix that and change your implementation client-side
the server response is just the session url..... no redirection...i just let Blazor Navigate to that url
ah okay I thought we were still talking about redirect and the CORS error. Because really you absolutely should redirect from the server
so how do you redirect using HttpClient?
I don't understand your question yet. Are we talking about fixing your code to redirect server-side or something else?