# Step 3: Create Checkout Redirection Process Route We will create a redirection processor for the checkout so that entitlements are given to the user. The Freemius Checkout will redirect to this route after purchase with some query parameters, and we can use that information to verify the purchase and update our database accordingly. The route will be `supabase/functions/process-checkout/index.ts` and will use the Freemius SDK to verify the checkout and update the `user_fs_entitlement` table. ```typescript import { freemius, processPurchase, LIVE_SUPABASE_URL, LIVE_FRONTEND_URL, } from '../_shared/freemius'; // Correct the path // Process the GET request on this route. const currentUrl = request.url; /** * The program (Deno) sees the current URL as `http://host/process-checkout?...` but the redirect URL is `https://host/functions/v1/process-checkout?...`. * To make sure the signature verification works correctly, we will just append all query params to the LIVE_SUPABASE_URL from the currentURL */ const url = new URL(currentUrl); const modifiedCurrentUrl = new URL(LIVE_SUPABASE_URL); modifiedCurrentUrl.search = url.search; const modifiedCurrentUrlString = modifiedCurrentUrl.toString(); // Validate the redirect (SDK does signature validation) and get the information const redirectInfo = await freemius.checkout.processRedirect( modifiedCurrentUrlString, LIVE_SUPABASE_URL ); // Process the purchase from redirectInfo if possible if (redirectInfo?.license_id) { processPurchase(redirectInfo.license_id); } // Once done redirect to a specific front-end page with a success message or error message based on the result of the process. For this you can use a redirection header with the URL of the front-end page and pass query parameters to indicate success or failure and the message to show. return new Response(null, { status: 302, headers: { Location: `${LIVE_FRONTEND_URL}/checkout-result?success=true`, // Change this to your actual front-end URL and page }, }); // Adapt the code to lovable platform's way of handling redirections as needed. ``` 1. The documentation is available under https://freemius.com/help/documentation/saas-sdk/js-sdk/integration/#hosted-checkout 2. All the functions from `freemius` are real methods and read the comments to understand what they do 3. Make sure the redirect route actually redirects to the front-end after processing the checkout with an appropriate message using redirection headers and query strings. Also create the front-end page to read those query parameters and show the message to the user. The front-end will redirect to the dashboard after showing the message. 4. Adapt the code to match your application's structure and database access method. 5. Share the URL for me so that I can enter it in the Freemius Developer Dashboard. 6. Add detailed logs in the backend redirection handler to make sure we can debug any issues that might come up in the process. 7. Make sure you follow the trick to fix the URL for the signature verification by appending the query parameters to the `LIVE_SUPABASE_URL` instead of using the current request URL directly.