#santiago-checkout-csp
1 messages · Page 1 of 1 (latest)
santiago-checkout-csp
@slender bay Checkout is likely the right integration for you based on what you described. Can you explain a bit more about the CORS issue you get and share some of you code?
sure, ic an share it, so if use foms, it works just fine, but for my flow, i prefer to use an ajax call. because i want to send the data as raw json, then will redirect to the checkout page, user will pay, and the data will be back to the 'success page' or a session i'm not sure yet how it works with stripe.. but once i get the 'success' from stripe, i'll be able to add the user submitted information to a server.. I am just testing at the moment, and this is what I have, (just edited the demo from the stripe dev docs)
this is the test data with checkout.html
<head>
<title>Buy cool new product</title>
</head>
<body>
<!-- Use action="/create-checkout-session.php" if your server is PHP based. -->
<form action="create-checkout-session.php" method="POST">
<button id="checkout" type="submit"> CHECKOUT</button>
<div id="smsg"></div>
<script>
checkbutton = document.getElementById("checkout");
checkbutton.addEventListener("click",checkout);
function checkout() {
var data = {
"name":"ads",
"amount":1000,
"quantity":3
}
console.log(data);
url = "create-checkout-session.php";
var xhttp = new XMLHttpRequest();
xhttp.open("POST",url,true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhttp.onreadystatechange = function () {
if(this.readyState == 4 && this.status == 200){
document.write(xhttp.responseText);
}
};
xhttp.send(JSON.stringify(data));
}
</script>
</body>
</html>```
and this is the create-checkout-session.php
The problem is that if you use an Ajax call like that, your server can not redirect. You have to return the URL back from the server and then redirect in Javascript
That's why we recommend the form submission which would be way cleaner than the code you wrote
yes that is my problem..
ok, for formsubmission
how can i send a json
in raw format... i've never done that before..
Like your code right now is not really clear, you don't handle any error, etc. If you're not an experienced javascript developer, you're way better off with a form submission
the json is in this order data { "file name", "file base64 blob" "cities ids", "amount" }
You can't do JSON in that flow
I was just testing it i'll add the error handling later
You have to understand the basics of JS and HTTP requests first. If you absolutely want JSON then you have to have your PHP code server-side return the URL instead of doing a redirect
ok, so in that case i'll have to do it with the custom flow if i dont want to use redirect?
ok that also works
having php returning the url
yeah you don't change anything else, you still use Checkout. But your server-side code instead of doing header('Location: ' . $session->url); needs to return that URL back to the client and then you redirect in JS
didn't think of that before..
ok so once the the url is returned...
what data is returned after the payment goes trhough
do i have to keep the data on my own session for the blob item in this case.. or is it also returned with the success url?
you're misunderstanding Checkout completely right now. Did you carefully read the docs first? https://stripe.com/docs/payments/checkout
Your code will send the customer to Checkout, where they pay and then they get redirected to your success_url where your own code needs to recognize them (usually based on a cookie or browser session or similar) to do fulfillment
Yes, I understand it. I was just not clear if the 'session' was separate from the checkout session. on the create-checkout-session' or from my own code... that i needed to do..
but from what you are telling me, it has to be my own session?
or cookie
yes
ok that's clear.. then i think checkout session should work just fine . since it is faster and i need this as soon as possible.. for the custom workflow.. is almost the same thing right, the only thing the stripe api takes care of is the payment.. and return success/fail. everything else needs to be handled on my own server..
that summary isn't really clear so not sure. But you want Checkout so go with Checkout, drastically easier!
yes, its easier.. and faster. I was just asking if for the 'custom checkout flow' becaues you have the stripe hosted, embedded, and custom flow... for the custom flow is the ssame thing, all the api takes care of is the payment. success/ fail
just for future reference
I mean it's not just "the api takes care" there's a lot more to it. The custom integration is a lot more complex.
oh ok i'll read those document more in depth later. but i believe it will also manage the data besides just payment
I don't know what that means I'm sorry, this is really vague
its ok.. do not know how to explain it well, but i got what i need for now..
thanks for your help
sure thing!
ok i tested it, all works as espected. will get to work on the full integration with the error handling now..