BUY BUTTON
Buy Button - iOS
Buy Button Solution (Recommended)β
iOS: In the U.S., Japan, and Brazil, Apple now lets developers direct players to external web payments. The Xsolla SDK aligns with Appleβs updated guidelines.
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.
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
- Objective-C
- Swift
// Enable Buy Button solution
settings.useBuyButtonSolution = YES;
// Enable Buy Button solution
settings.useBuyButtonSolution = true
Web Shop Link-outsβ
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
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:
- Objective-C
- Swift
[settings setupBuyButtonWebShopWithUrl:[NSURL URLWithString:@"https://yourwebshop.xsolla.site"]
userId:@"<USER_ID>"
returnUrl:@"yourgame://"
openExternally:YES];
settings.setupBuyButtonWebShop(url: URL(string: "https://yourwebshop.xsolla.site")!,
userId: "<USER_ID>",
returnUrl: "yourgame://",
openExternally: true)
Parameter explanation:
url: The URL of your Xsolla Web Shop where users complete purchasesuserId: A unique identifier for the user in your system, used for purchase attribution and user trackingreturnUrl: The deep link URL scheme that brings users back to your app after purchase completionopenExternally: 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:
- Objective-C
- Swift
// 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
}
// Attempt to purchase an item via Web Shop
let handledExternally: Bool = SKPaymentQueue.default().purchase(withSKU: "money.100")
if handledExternally {
// Web Shop opened successfully, update UI to reflect the redirect
print("Purchase redirected to Web Shop")
// Optionally show a loading indicator or message to the user
}