> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appcharge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Launch the Checkout

To launch the checkout, follow these steps:

1. From your server, call the [Create Checkout Session API](/../../api-reference/checkout/checkout-session/create-checkout-session) to create a checkout session.

   <Warning>
     * When calling the Create Checkout Session API, don't pass the `redirectUrl` parameter. The SDK already handles the redirect automatically using the configuration file.
     * Call the API from your server to ensure session integrity and security. Never invoke this endpoint from your client-side Unity Project.
   </Warning>

2. After receiving the API response on your server, extract the values from the session object:

   ```json theme={"system"}
   {
       "checkoutSessionToken": "session_token_identifier",
       "purchaseId": "pr_purchase_id",
       "url": "https://checkout-v2-sandbox.appcharge.com",
       "parsedUrl": "https://checkout-v2-sandbox.appcharge.com/session_token_identifier#boot=checkout_boot_data"
   }
   ```

   | Parameter              | Description                                                   |
   | ---------------------- | ------------------------------------------------------------- |
   | `checkoutSessionToken` | A unique token to identify and validate the checkout session. |
   | `purchaseId`           | ID to track the purchase.                                     |
   | `url`                  | The base URL of the Appcharge checkout page.                  |
   | `parsedUrl`            | The Parsed URL of the Appcharge checkout page.                |

3. Use the values returned in the checkout session response to open the checkout on the client:

   <CodeGroup>
     ```csharp C# theme={"system"}
     PaymentLinksController.Instance.OpenCheckout(
         purchaseId: "PURCHASE_ID",
         parsedUrl: "PARSED_URL"
     )
     ```
   </CodeGroup>

   <Danger>
     The session response values must be passed exactly as received. Modifying them may result in the checkout failing to load.
   </Danger>

4. Control whether the Android foreground Checkout Service is enabled (optional):

   <br />

   The foreground service is enabled by default and helps keep your app prioritized while checkout is open, reducing the risk of Android closing or deprioritizing it during payment and network operations.

   You can enable or disable the service during runtime using:

   <CodeGroup>
     ```csharp C# theme={"system"}
     PaymentLinksController.Instance.SetConfiguration("setCheckoutServiceMode", true);  // Enable
     PaymentLinksController.Instance.SetConfiguration("setCheckoutServiceMode", false); // Disable
     ```
   </CodeGroup>

   <Note>The foreground service runs only if the required manifest permissions and service declaration are properly configured. If you don't want to use the foreground service, remove `CheckoutService` declaration from your manifest file and disable it during runtime using the method above. The foreground permissions can remain, as they may be used by other services in your app.</Note>

5. You can also override in run-time how the checkout page is opened (optional):

   * **External browser** <br />
     Open the checkout in the device’s default browser. This flow will redirect the player back to the app.

     <CodeGroup>
       ```csharp C# theme={"system"}
       // Unity Android
       PaymentLinksController.Instance.SetConfiguration("browserMode", AndroidBrowserMode.External)

       // Unity iOS
       PaymentLinksController.Instance.SetConfiguration("browserMode", iOSBrowserMode.External);
       ```
     </CodeGroup>

     <Warning> Running the checkout in an external browser may cause inconsistent behavior across devices, incomplete transactions, or app unexpected lifecycle behavior. </Warning>

   * **Non-external browser (default)** <br />
     Open the checkout in a non-external browser. This flow will use the URL scheme provided in the configuration file to return back to the app. <br /><br />

     For Android, choose whether the Checkout opens in a Trusted Web Activity (TWA), or in a Custom Chrome Tab (CCT). For iOS, the checkout opens via [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller). For more information regarding iOS, see [Sell Outside IAP](/../../guides/payment-links/ios-payment-links/sell-outside-iap).

     <CodeGroup>
       ```csharp C# theme={"system"}
       // Unity Android with an internal custom Chrome tab
       PaymentLinksController.Instance.SetConfiguration("browserMode", AndroidBrowserMode.CCT)

       // Unity Android with an internal Trusted Web Activity
       PaymentLinksController.Instance.SetConfiguration("browserMode", AndroidBrowserMode.TWA)

       // Unity iOS
       PaymentLinksController.Instance.SetConfiguration("browserMode", iOSBrowserMode.SFSVC);
       ```
     </CodeGroup>

6. For Unity iOS only, you can force the Checkout page to display in portrait orientation, even if the app is currently in landscape mode (optional):

   <CodeGroup>
     ```csharp C# theme={"system"}
     PaymentLinksController.Instance.SetConfiguration("portraitOrientationLock", "true")
     ```
   </CodeGroup>
