Last active
December 10, 2023 20:37
-
-
Save jaoltr/917e88c0dd2b8b5ed8527067ee92adaa to your computer and use it in GitHub Desktop.
get checkout - submit url params to php function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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