5. Client Integration and Redirection Testing
In this final step, we render the retrieved checkoutUrl in the client UI and enable secure redirection to the official Shopify checkout screen so users can complete their transactions.
5.1. Rendering UI & Binding Events
We hook up click events, allowing users to inspect the generated checkout URL and transition smoothly to checkout.
// Example of displaying the checkout URL and redirecting the browser
function displayCheckoutLink(checkoutUrl) {
const container = document.getElementById("checkoutLinkContainer");
container.style.display = "block";
// Update HTML interface
container.innerHTML = `
<div><strong>checkoutUrl generated successfully.</strong></div>
<div style="margin-top: 8px;">
<a href="${checkoutUrl}" target="_blank" rel="noopener noreferrer">
Proceed in New Tab
</a>
|
<button type="button" id="goCheckoutButton">
Checkout in This Window
</button>
</div>
`;
// Redirect current window to Shopify checkout on button click
const goButton = document.getElementById("goCheckoutButton");
if (goButton) {
goButton.addEventListener("click", () => {
window.location.href = checkoutUrl;
});
}
}
5.2. Final Integration Test
With everything configured, run your local server and verify the following operational flow:
- Collect the selected product and shipping address details.
- On submission,
storefrontRequesttriggers and executes thecartCreatemutation. - Verify that clicking the generated checkoutUrl safely lands the user on the official Shopify Checkout page.