Skip to content

Instantly share code, notes, and snippets.

@jaoltr
Last active December 10, 2023 20:37
Show Gist options
  • Save jaoltr/917e88c0dd2b8b5ed8527067ee92adaa to your computer and use it in GitHub Desktop.
Save jaoltr/917e88c0dd2b8b5ed8527067ee92adaa to your computer and use it in GitHub Desktop.
get checkout - submit url params to php function
async function getCheckoutUrl() {
try {
// Get URL params
const params = new URLSearchParams(window.location.search);
// Make the request to the PHP function
const response = await fetch("/php/get_checkout_url.php", {
method: "POST",
body: JSON.stringify(Object.fromEntries(params)),
headers: {
"Content-Type": "application/json",
},
});
// Check for successful response
if (!response.ok) {
throw new Error("Error getting checkout URL");
}
// Get the checkout URL from the response
const checkoutUrl = await response.text();
// Redirect to the checkout URL
window.location.href = checkoutUrl;
} catch (error) {
// Redirect to the error page
window.location.href = "/error.html";
}
}
// Call the function
getCheckoutUrl();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment