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

Configure the SDK

The iOS Payment Links SDK exposes a ConfigModel. Create an instance with the following arguments:
let config = ConfigModel(
    checkoutPublicKey: "{YOUR_CHECKOUT_PUBLIC_KEY}",
    environment: "sandbox",
    redirectUrl: "https://your-universal-link-redirect-url.com"
)
ArgumentTypeRequired?Description
checkoutPublicKeystringYesThe 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.
environmentstringYesThe checkout environment.
One of:
- sandbox: For testing.
- production: For live operations.
redirectUrlstringYesThe 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 but with 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. 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:
import ACCheckoutSDK
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set your checkout token and environment
        let config = ACConfigModel(
            checkoutPublicKey: "{YOUR_CHECKOUT_PUBLIC_KEY}",
            environment: "sandbox",
            redirectUrl: "https://your-universal-link-redirect-url.com"
        )

        // Initialize the SDK
        ACBridgeAPI.initialize(configModel: config, customerId: "{PLAYER_ID}")

        // Set the callback delegate 
        ACBridgeAPI.delegate = self
    }
}

Re-initialize the SDK

If the customerId changes, such as when the session context is different, you’ll need to re-initialize the SDK to ensure accurate order tracking:
ACBridgeAPI.initialize(configModel: config, customerId: "{PLAYER_ID}")