VALIDATION
Purchase validation - iOS
Each purchase should be validated before awarding it to the end-user. This assists in preventing unauthorized purchases and ensures the integrity of your in-app economy. Validating purchases is a critical security measure to prevent fraud, protect your revenue, and ensure fair user experiences.
Essentially, that are two distinct validation approaches readily available.
Server-side Validation
The most secure and reliable way to validate purchases is by using server-to-server (S2S) communication, with the client completely removed from the validation process. This minimizes security risks and ensures that entitlements are only granted based on verified data received directly from Xsolla.
With Xsolla, server-side validation is implemented through a webhook-based model:
- Once a user completes a purchase through your app, Xsolla services automatically trigger a webhook event to your backend.
- This webhook contains all the necessary purchase data, including the Xsolla
order ID, enabling your server to validate and process the purchase asynchronously. - Your backend can then use this data to update the user's entitlements, balance, inventory, etc., without requiring any additional input from the client.
This flow ensures that the client has no role in deciding the outcome of a purchase — all validation logic lives on the server, using trusted data that originates from Xsolla itself.
For more information about how webhooks work, see our Webhooks guide.
Even with server-side validation, the SDK still delivers its usual client callbacks — paymentQueue(_:updatedTransactions:), and the validateTransaction(_:) result if you call it. In a server-side (webhook) flow these are for UI/UX only: show a spinner, a confirmation screen, or refresh the storefront. They do not grant the reward and must not be used to do so — the entitlement is already awarded by your backend from the trusted webhook, independently of the device. Treat the client callback as a display signal, not the source of truth.
Client-side Validation
Provides means of validating a purchase on the user's device without a need for a backend (server). It's better than nothing, but has its own drawbacks, i.e. anything that runs on the client can potentially be exploited.
Before finishing transaction, it can be validated on client side. Unfinished transactions restored after app was closed can't be validated.
- Objective-C
- Swift
SKPaymentTransaction* transaction = ...;
[[SKPaymentQueue defaultQueue] validateTransaction:transaction completion:^(BOOL isValid, NSError * _Nullable error) {
// isValid will be YES for valid transactions
}];
let transaction: SKPaymentTransaction = ...
SKPaymentQueue.default().validateTransaction(transaction) { isValid, error in
// isValid will be true for valid transactions
}
Comparison with Native StoreKit Validation
While Xsolla provides streamlined validation approaches, it's helpful to understand how they compare to Apple's native StoreKit validation methods ↗ (https://developer.apple.com/documentation/storekit/choosing-a-receipt-validation-technique).
Server-side Validation Differences
| Aspect | Xsolla Webhook-based | Apple's verifyReceipt API |
|---|---|---|
| Implementation | Webhook automatically triggered by Xsolla | Manual server-to-server calls to Apple's endpoint |
| Security | High - No client involvement | High - Direct validation with Apple |
| Setup Complexity | Low - Configure webhook endpoint | Medium - Implement receipt parsing and API calls |
| Data Format | JSON webhook payload | Base64-encoded receipt → JSON response |
| Timing | Asynchronous, real-time notifications | Synchronous, on-demand validation |
| Transaction History | Individual purchase events | Complete receipt with all transactions |
| Network Requirements | Webhook endpoint accessible to Xsolla | Secure HTTPS to Apple's servers |
With Xsolla's webhook-based approach, purchase validation happens automatically when Xsolla pushes verified purchase data to your backend endpoint, eliminating the need to handle receipt extraction, parsing, or validation requests.
With Apple's native approach, your app must extract receipt data from the app bundle and your server must make validation requests to Apple's endpoints (https://buy.itunes.apple.com/verifyReceipt for production or https://sandbox.itunes.apple.com/verifyReceipt for sandbox), then parse the JSON response.
Client-side Validation Differences
| Aspect | Xsolla Mobile SDK | Apple's Native Local Validation |
|---|---|---|
| Implementation | Simple SDK method call | Complex PKCS #7 container decoding |
| Code Complexity | Low - Single function call | High - ASN.1 parsing, cryptographic validation |
| Validation Steps | Handled internally by SDK | Manual verification of certificate chain, bundle ID, version, device hash |
| Dependencies | Xsolla Mobile SDK | Security frameworks |
| Maintenance | Managed by Xsolla | Developer maintains cryptographic code |
| Security Level | Medium - Client-side limitations apply | Medium - Client-side limitations apply |
Xsolla's client-side validation provides a simplified interface:
SKPaymentQueue.default().validateTransaction(transaction) { isValid, error in
// Simple validation result
}
Apple's native local validation requires extensive implementation including decoding receipts as PKCS #7 containers using ASN.1 notation, verifying certificate chains and signature validity, computing SHA-1 hashes for device identification, and validating multiple receipt fields (bundle ID, version, device hash).