getOneTimePurchaseToken function
Returns the token for a ONE-TIME purchase (consumable or non-consumable) to be used with VerifyLocalPurchase.verifyPurchase.
- iOS/macOS: returns
purchase.purchaseID(the transaction ID). - Android: returns
purchase.verificationData.serverVerificationData(the purchase token).
Throws VerifyPurchaseException with VerifyPurchaseErrorCode.invalidToken if the token is missing.
Example:
final token = getOneTimePurchaseToken(purchase);
final result = await VerifyLocalPurchase.verifyPurchase(token);
Implementation
String getOneTimePurchaseToken(PurchaseDetails purchase) {
final token = (Platform.isIOS || Platform.isMacOS)
// iOS/macOS: use the transactionId (purchaseID)
? purchase.purchaseID
// Android: use serverVerificationData (contains the purchaseToken)
: purchase.verificationData.serverVerificationData;
return _requireToken(token, 'purchase token');
}