> ## 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.

# Initialize the SDK

This article explains how to configure and initialize and configure the Payment Links SDK for iOS.

## Configure the SDK

The Payment Links SDK for iOS exposes a `ConfigModel`. Create an instance with the following arguments:

<CodeGroup>
  ```swift Swift theme={"system"}
  let config = ConfigModel(
      checkoutPublicKey: "{YOUR_CHECKOUT_PUBLIC_KEY}",
      environment: "sandbox",
      redirectUrl: "https://your-universal-link-redirect-url.com"
  )
  ```

  ```c Objective-C theme={"system"}
  ACConfigModel *config = [[ACConfigModel alloc] initWithCheckoutPublicKey:@"{YOUR_CHECKOUT_PUBLIC_KEY}" environment:@"sandbox" redirectUrl:@"https://your-universal-link-redirect-url.com"]; 
  ```
</CodeGroup>

| Argument            | Type     | Required? | Description                                                                                                                                                                                                                   |
| ------------------- | -------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `checkoutPublicKey` | `string` | Yes       | The checkout public key, located in the Publisher Dashboard. In the sidebar menu, click **Settings**, then select the **Integration** tab. Copy the **Checkout Public Key** value.                                            |
| `environment`       | `string` | Yes       | The checkout environment. One of:<br />- `sandbox`: For testing.<br />- `production`: For live operations.                                                                                                                    |
| `redirectUrl`       | `string` | Yes       | The URL to redirect the player to after the checkout is complete. This applies on the external browser flow. The URL is the same as the one provided in the associated domain section with the additional prefix, `https://`. |

## Initialize the SDK

When you initialize the SDK, you need to provide a `customerId`. This allows the SDK to handle cases where the player closes the browser during checkout and later returns to the game. In such cases, the SDK begins validating the order using the `customerId` from initialization and the `purchaseId` from the checkout session.  It then contacts the Appcharge server to check the order status and responds to the app with the next step.

Additionally, the `customerId` ensures correct validation even if multiple players share the same device. For example, if different players log into the same game on the same phone, the SDK uses the `customerId` to identify the correct player and validate any associated orders with the Appcharge server.

To initialize the SDK, call the method below using a `ConfigModel` instance and the relevant `customerId`. We recommend doing this on application load, ideally within the `viewDidLoad` lifecycle method:

<CodeGroup>
  ```swift Swift theme={"system"}
  import ACPaymentLinks
  class ViewController: UIViewController {
      override func viewDidLoad() {
          super.viewDidLoad()
          let config = ACConfigModel(
              checkoutPublicKey: "{YOUR_CHECKOUT_PUBLIC_KEY}",
              environment: "sandbox",
              redirectUrl: "https://your-universal-link-redirect-url.com"
          )
          // Initialize the SDK with the delegate
          ACBridgeAPI.initialize(configModel: config, customerId: "{PLAYER_ID}", delegate: self)
      }
  }
  ```

  ```c Objective-C theme={"system"}
  #import <ACPaymentLinks/ACPaymentLinks.h>
  #import <ACPaymentLinks/ACPaymentLinks-Swift.h>

  @interface ViewController : UIViewController <ACBridgeAPIDelegate>
  @end

  @implementation ViewController
  - (void)viewDidLoad {
      [super viewDidLoad];
      ACConfigModel *config = [[ACConfigModel alloc] initWithCheckoutPublicKey:@"{YOUR_CHECKOUT_PUBLIC_KEY}" 
                                                                   environment:@"sandbox" 
                                                                   redirectUrl:@"https://your-universal-link-redirect-url.com"];
      // Initialize the SDK
      [ACBridgeAPI initializeWithConfigModel:config customerId:@"{PLAYER_ID}" delegate:self];
  }

  @end
  ```
</CodeGroup>

## Re-initialize the SDK

If the `customerId` changes, such as when the session context is different, re-initialize the SDK to keep order tracking accurate and ensure orders are linked to the correct player.

<CodeGroup>
  ```swift Swift theme={"system"}
  ACBridgeAPI.initialize(configModel: config, customerId: "{PLAYER_ID}", delegate: self)
  ```

  ```c Objective-C theme={"system"}
  [ACBridgeAPI initializeWithConfigModel:config customerId:@"{PLAYER_ID}" delegate:self];
  ```
</CodeGroup>

## Lock checkout orientation

You can force the Checkout page to display in portrait orientation, even if the app is currently in landscape mode.

<CodeGroup>
  ```swift Swift theme={"system"}
  // Checkout opens using the app’s current orientation (default)
  ACBridgeAPI.portraitOrientationLock = false 

  // Checkout is locked to portrait orientation
  ACBridgeAPI.portraitOrientationLock = true
  ```

  ```c Objective-C theme={"system"}
  // Checkout opens using the app’s current orientation (default)
  [ACBridgeAPI setPortraitOrientationLock:@0];

  // Checkout is locked to portrait orientation.
  [ACBridgeAPI setPortraitOrientationLock:@1];
  ```
</CodeGroup>

## Enable debug mode

Enable debug mode to view detailed logs from all parts of the SDK. This provides deeper visibility into the SDK’s behavior:

<CodeGroup>
  ```swift Swift theme={"system"}
  ACBridgeAPI.setDebugMode = true
  ```

  ```c Objective-C theme={"system"}
  [ACBridgeAPI setSetDebugMode:@YES];
  ```
</CodeGroup>
