Skip to main content

CONFIGURATION

Configuration - iOS

This guide covers how to configure the Xsolla Mobile SDK for iOS to enable payment processing in your mobile application. The SDK provides multiple integration approaches, from full native implementations to web-based solutions, allowing you to choose the method that best fits your app's requirements and development timeline.

Basic SDK Configuration​

The Xsolla Mobile SDK requires configuration with your project credentials from the Xsolla Publisher Account β†— (https://publisher.xsolla.com/). These settings control how the SDK connects to Xsolla's services and handles payment flows.

Required Configuration Parameters​

  • Project ID: Your Xsolla project identifier (numeric value)
  • Login Project ID: Your Xsolla Login project identifier (UUID string)
  • Platform: Specifies the target platform (typically .standalone for mobile apps)

For initial development and testing, you can use the example credentials shown below:

#import <XsollaMobileSDK/StoreKitWrapper.h>

// Initialize SDK settings with your project credentials
SKPaymentSettings* settings = [[SKPaymentSettings alloc] initWithProjectId: 301871
loginProjectId:@"dfcb133b-6d0b-4937-b8d2-c4f4d58fb53a"
platform: SKPaymentPlatformStandalone
paystationUIThemeId: SKPaystationThemeDark
paystationUISize: SKPaystationSizeMedium];

// Enable sandbox mode for testing (disable for production)
settings.useSandbox = YES;

// Enable the SDK functionality (set to NO to completely disable payments)
settings.enablePayments = YES;

// Configure external browser behavior (see compliance section below)
settings.openExternalBrowser = YES; // Set based on your compliance requirements

// Initialize the payment queue with your settings
SKPaymentQueue* queue = [SKPaymentQueue defaultQueue];
[queue startWithSettings: settings];
[queue addTransactionObserver: self];

Regional Compliance Configuration​

The openExternalBrowser setting controls whether a purchase completes on an external web payment page (true) or inside the app (false). Set it to match your target market β€” a growing number of jurisdictions now require Apple to let developers direct players to external payments:

  • United States β€” external purchase links are permitted (Epic v. Apple) β†’ openExternalBrowser = true
  • Japan β€” the Mobile Software Competition Act (MSCA) permits external payments and web link-outs β†’ openExternalBrowser = true
  • Brazil β€” Apple's CADE antitrust settlement permits external payments and link-outs β†’ openExternalBrowser = true
  • European Union β€” under the Digital Markets Act (DMA) either works: keep the flow in-app β†’ openExternalBrowser = false, or send the player to the web β†’ openExternalBrowser = true. Apple charges a different commission for each, and from October 1, 2026 you have to keep whichever you pick for 12 months, so agree it with your business team first
settings.openExternalBrowser = YES; // External web payment β€” US, Japan, Brazil
settings.openExternalBrowser = NO; // In-app payment β€” EU
note

Platform rules and commissions differ by market and continue to change. Confirm Apple's current requirements for every region you ship to before going live.

For more advanced compliance scenarios, you can programmatically detect the user's region and distribution channel to automatically configure the appropriate settings. Learn how to detect iOS storefront to enable external payments for the regions that permit them, or detect alternative app distribution status for enabling EU-specific compliance flows based on the app's installation source.

Essential Configuration Notes​

  • Enable Payments: The SDK must be explicitly enabled by setting enablePayments to true. This allows you to completely disable payment functionality if needed without removing the SDK integration.
  • Sandbox Mode: useSandbox is true by default, so the SDK runs against the sandbox environment unless you change it. Keep it true during development and testing to avoid processing real transactions, and be sure to set useSandbox = false before going live.
  • Transaction Observer: Don't forget to add your class as a transaction observer to receive payment completion callbacks.

Default Payment Method​

You can set a default payment method for Xsolla Pay Station. Configure it globally in settings (applies to all purchases) or per purchase. The value is the Pay Station payment method identifier (for example, 3175 is Apple Pay).

// Global default (set before starting the SDK)
settings.paymentMethodId = [NSNumber numberWithInt:3175]; // 3175 = Apple Pay

// Per purchase override
SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];
payment.paymentMethodId = [NSNumber numberWithInt:3175]; // 3175 = Apple Pay
[[SKPaymentQueue defaultQueue] addPayment:payment];
note

If both are set, the per-purchase value overrides the global default for that transaction.

Purchase Restoration Settings​

By default, the SDK automatically handles local purchase restoration to ensure users can recover their purchases when reinstalling your app or when the app crashes or goes out of memory during payment processing. However, this behavior should be adjusted based on your backend integration architecture.

Restoration reads the player's Xsolla Inventory unless you turn on the Events API below. For what you get back in each case, and what you don't, see Restored purchases.

note

Coming from Apple StoreKit? There is no manual "Restore Purchases" call to wire up β€” restoreCompletedTransactions() is a no-op in this SDK. Restoration happens automatically, as described above, through local restoration and, optionally, the Xsolla Events API. Consumable balances are recovered through your own backend or the Xsolla Inventory, so persist them there when the purchase is awarded.

Alternatively, if you prefer a serverless approach without maintaining webhooks, you can enable the Xsolla Events API for purchase restoration (see the subsection below) while keeping local purchase restoration enabled.

For webhook-based integrations where your backend receives and processes purchase notifications directly from Xsolla, disable local restoration to prevent conflicts with server-side transaction management:

// Disable local purchase restoration for webhook-based integrations
settings.useLocalPurchaseRestoration = NO;
warning

When to disable local purchase restoration:

  • Your backend uses webhooks to receive purchase notifications from Xsolla
  • You handle transaction lifecycle management on your server
  • You want to avoid duplicate purchase processing between local and server-side systems

Important limitations:

  • Restored purchases cannot be validated through the standard validation flow
  • Restored purchases don't carry the identifiers of the original Xsolla order unless restoration runs through the Events API
  • Transaction finishing must be handled by your backend when webhooks are used
  • If local purchase restoration is disabled, the SDK will not perform restoration via either local restoration or the Events API
  • Web Shop link-out mode skips restoration entirely, whatever these settings say

This setting directly impacts the finishTransaction(_ transaction: SKPaymentTransaction) method behavior described in the Purchase Flow guide. When local restoration is disabled, your backend becomes responsible for managing the complete transaction lifecycle through webhook notifications. Note that with local restoration disabled, unfinished transactions will not reappear on app relaunch, making proper backend handling essential.

Using Xsolla Events API for Restoration​

The Xsolla Events API serves as an alternative to webhook-based integrations, where the integrator’s backend usually handles most of the logic (purchase validation, awarding, etc.). Instead of sending webhooks directly, the API intercepts them and stores their payloads in a remote queue managed by Xsolla. This approach enables serverless integrations for projects that lack backend capacity or don't require one, yet still prefer handling the entire transaction flow directly from the app.

Restoring through the Events API also fills in transactionIdentifier with the order ID and invoiceIdentifier with the invoice ID from the player's original order, so you can match a restored purchase to your own records. Restoring from the inventory leaves both nil, because the inventory only lists what the player owns β€” there's no order behind it.

Opting for the Xsolla Events API disables your project's webhooks β€” you cannot use both simultaneously.

To enable it, open your project in Publisher Account, go to Project settings > Integration settings, select Use API and click Save. See Events API in Publisher Account for details.

Enabling Events in the iOS SDK​

Enable Events-based purchase restoration in the SDK configuration:

// Enable Events API for purchase restoration
settings.useEventsApiForPurchaseRestoration = YES;
info

For additional information, see the webhooks page.

note

Events-based restoration requires settings.useLocalPurchaseRestoration = true. If you disable local purchase restoration, the SDK will not query or use the Events API for restoration.

Attribution User ID​

If you use an attribution platform (AppsFlyer, Adjust, etc.), set attributionUserId so that purchases made through Pay Station are reported to it under the same user as the rest of your app's events. The SDK sends this value to Pay Station as custom_parameters.custom_id, and purchase events forwarded to the attribution platform are keyed on it.

The value must equal the customer user ID your attribution SDK reports; otherwise the purchase events will not match up with that user. If you leave it unset, purchase events are matched on the user ID in the payment token. By default that is the player's Xsolla Login user ID.1

1 If your project authenticates players through server-side custom ID login or PlayFab, or maps the user ID to a custom JWT claim, the payment token carries that value instead of the Login user ID. Set attributionUserId explicitly, or purchase events won't match your attribution platform.

This is separate from customUserId, which is sent as custom_parameters.custom_user_id and returned to you in purchase webhooks, but is not used for attribution.

// Must match the customer user ID reported by your attribution SDK
settings.attributionUserId = @"your-attribution-user-id";

Install Source​

Set installSource to report the channel your app was distributed through, such as your own website or launcher. The SDK sends it with the order as user.mobile_app.install_source, and it is sent as is, without trimming.

If you leave it unset, the SDK detects the channel itself, but only on iOS 17.4 and later, where it can tell the App Store, web distribution and an alternative marketplace apart. On earlier iOS versions no install source is sent.

settings.installSource = @"website";

Authentication with Xsolla Login​

If your app uses Xsolla Login for user authentication, you can provide the login token to the SDK so it works with Xsolla's payment services.

Setting the Login Token​

Configure the login token after initializing your settings but before starting the payment queue:

// After initializing settings, set the Xsolla Login token
settings.customLoginToken = @"your_xsolla_login_token";

// Then start the SDK
SKPaymentQueue* queue = [SKPaymentQueue defaultQueue];
[queue startWithSettings: settings];
note

The Xsolla Login token should be obtained from your Xsolla Login β†— (https://xsolla.com/login) integration. Ensure the token is valid and set before starting the payment queue to enable authenticated payment flows.

Testing in Sandbox Mode​

During development, always enable sandbox mode to test your payment integration without processing real transactions or charges. The sandbox environment simulates the complete payment flow while using test data.

Enabling Sandbox Mode​

settings.useSandbox = YES; // Objective-C
settings.useSandbox = true // Swift
note

useSandbox defaults to true, so payments run against the sandbox environment out of the box. Set useSandbox = false before going live to process real transactions.

tip

For full testing guidance, including test card numbers and payment scenarios, see our iOS Testing Guide. This covers avoiding real charges, testing different payment methods, and validating your integration.

Payment Integration Options​

The Xsolla Mobile SDK offers multiple payment integration approaches to suit different development needs and timelines.

The Buy Button Solution provides a complete, native payment experience with minimal integration effort. This approach handles the entire payment flow within your app using Xsolla's optimized UI components.

For more details (including Web Shop link-outs vs Pay Station and platform notes), see Buy Button - iOS.

When to use Buy Button Solution:

  • You want a quick, native payment integration
  • You prefer Xsolla to handle payment UI and optimization
  • You need support for multiple payment methods out of the box
  • You want automatic compliance with regional payment regulations
// Enable Buy Button solution
settings.useBuyButtonSolution = YES;

The Web Shop approach redirects users to your existing Xsolla Web Shop in a browser, then returns them to your app after purchase completion. This method is ideal for gradual migration or when you want to maintain consistency with existing web-based payment flows.

When to use Web Shop link-outs:

  • You already have an established Xsolla Web Shop
  • You want to test Xsolla integration with minimal code changes
  • You need to maintain payment consistency across multiple platforms
  • You're implementing a phased migration from web to mobile payments
caution

In Web Shop link-out mode, the SDK does not execute its native in-app payment flow. It only opens the Web Shop and immediately cancels any SDK purchase callbacks. This mode is intended for minimal code changes: handle fulfillment and post-payment updates via your Web Shop processes (for example, webhooks or server-side logic), not via SDK purchase callbacks.

Configuring Web Shop Integration​

Use the helper method to configure the Web Shop redirect flow:

[settings setupBuyButtonWebShopWithUrl:[NSURL URLWithString:@"https://yourwebshop.xsolla.site"] 
userId:@"<USER_ID>"
returnUrl:@"yourgame://"
openExternally:YES];

Parameter explanation:

  • url: The URL of your Xsolla Web Shop where users complete purchases
  • userId: A unique identifier for the user in your system, used for purchase attribution and user tracking
  • returnUrl: The deep link URL scheme that brings users back to your app after purchase completion
  • openExternally: Whether to open the Web Shop in an external browser (recommended for compliance and better user experience)

Initiating Web Shop Purchases​

After configuration, initiate purchases by calling the purchase method with your product SKU:

// Attempt to purchase an item via Web Shop
BOOL handledExternally = [[SKPaymentQueue defaultQueue] purchaseWithSKU:@"money.100"];

if (handledExternally) {
// Web Shop opened successfully, update UI to reflect the redirect
NSLog(@"Purchase redirected to Web Shop");
// Optionally show a loading indicator or message to the user
}
Backend Integration

With the Web Shop approach, you don't need to fetch product catalogs through the mobile SDK (though you can for display purposes). Purchase fulfillment should be handled on your backend using the same webhooks and processes you use for standard Web Shop transactions, ensuring consistency across your payment infrastructure.

Deep links are essential for completing payment flows when users are redirected to external payment pages and need to return to your app. The SDK provides both automatic and manual deep link handling options.

tip

The SDK also supports Universal Links (HTTPS), which can be used instead of custom URL schemes (and avoid the β€œOpen in App Name?” prompt when returning from an external browser). See iOS Universal Links.

Setting Up URL Scheme​

Before configuring deep link handling, you must set up a custom URL scheme for your app. This URL scheme enables external sources (like payment pages) to redirect users back to your application.

To configure your URL scheme:

  1. Select your project in the Xcode project navigator
  2. Select your app target
  3. Open the Info tab
  4. Scroll down to URL Types and click the βž• button
  5. Set the URL Schemes field to $(PRODUCT_BUNDLE_IDENTIFIER)

URL Scheme Configuration

tip

Using $(PRODUCT_BUNDLE_IDENTIFIER) ensures your URL scheme matches your app's bundle identifier, which guarantees uniqueness and prevents conflicts with other apps.

By default, the Xsolla Mobile SDK automatically handles deep links using method swizzlingβ€”a technique that intercepts and modifies iOS method calls at runtime. This means the SDK automatically captures incoming URLs and processes them without requiring additional code from you.

Benefits of automatic handling:

  • Zero additional code required
  • Works with most app architectures
  • Handles all Xsolla-related URLs automatically
  • Maintains compatibility with your existing URL handling

The automatic handling works out of the box once you've configured your URL scheme as described above.

In some scenarios, you may need to disable automatic handling and implement manual deep link processing. This is typically necessary when:

  • Your app has existing custom URL handling logic that conflicts with method swizzling
  • You're using a framework (like React Native or Unity) that doesn't work well with method swizzling
  • You need more control over how deep links are processed
  • You're experiencing issues with automatic handling in your specific setup
  • Your app architecture requires explicit URL routing

Implementing Manual Handling​

Step 1: Disable Automatic Handling

Before starting the SDK, disable automatic URL handling:

// Disable automatic deep link handling before starting SDK
settings.swizzleUrlHandling = NO;

// Then start the SDK as usual
SKPaymentQueue* queue = [SKPaymentQueue defaultQueue];
[queue startWithSettings: settings];

Step 2: Implement Manual URL Handling

Add URL handling to your AppDelegate or SceneDelegate. The SDK's openWithUrl: method returns a boolean indicating whether it recognized and handled the URL:

// In your AppDelegate.m
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

// First, try to handle the URL with Xsolla SDK
BOOL handledBySDK = [[SKPaymentQueue defaultQueue] openWithUrl:url];

if (handledBySDK) {
// URL was recognized and handled by Xsolla SDK
return YES;
}

// Handle other URLs specific to your app
// Add your custom URL handling logic here
return [self handleCustomURL:url];
}

// Alternative: In your SceneDelegate.m (for iOS 13+)
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
for (UIOpenURLContext *context in URLContexts) {
NSURL *url = context.URL;

// Try to handle with Xsolla SDK first
BOOL handledBySDK = [[SKPaymentQueue defaultQueue] openWithUrl:url];

if (!handledBySDK) {
// Handle other URLs specific to your app
[self handleCustomURL:url];
}
}
}
Return Value Usage

The openWithUrl: method returns true/YES if the URL was recognized as a Xsolla payment callback and processed by the SDK. This allows you to implement fallback logic for URLs that aren't related to Xsolla payments, ensuring your app can handle all types of deep links appropriately.

Step 3: Handle Pay Station Screen Orientation (Optional)

If your app supports a different orientation than you want for the Pay Station screen, you need to implement additional orientation handling. For example, if your game supports only landscape orientation but you want the Pay Station to appear in portrait mode, add the following method to your AppDelegate:

// In your AppDelegate.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(UIWindow *)window {

// Since the app may not support portrait, we must ensure that for the UIWindow
// that SDK creates it returns correct value for portrait support
UIInterfaceOrientationMask mask = [[SKPaymentQueue defaultQueue] supportedInterfaceOrientationsForWindow:window];

if (mask != 0) {
return mask;
}

// Fall back to default app orientation support
return [application supportedInterfaceOrientationsForWindow:window];
}

This method allows the SDK to specify orientation requirements for its own windows (like the Pay Station screen) while maintaining your app's normal orientation restrictions for other windows. Note that this is automatically handled if automatic deep link handling is enabled.

Choosing the Right Approach

If you're unsure whether you need manual deep link handling, start with the default automatic handling. It works for most applications and requires no additional code. You can always switch to manual handling later if you encounter specific issues or have requirements that necessitate more control over the URL handling process.

Next Steps​

After configuring the SDK, you're ready to initialize it and start processing payments. Continue to the iOS Initialization Guide to learn how to set up payment observers and handle transaction events in your application.