getOneTimePurchaseToken function

String getOneTimePurchaseToken(
  1. PurchaseDetails purchase
)

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).

Example:

final token = getOneTimePurchaseToken(purchase);
final isValid = await VerifyLocalPurchase().verifyPurchase(token);

Implementation

String getOneTimePurchaseToken(PurchaseDetails purchase) {
  if (Platform.isIOS || Platform.isMacOS) {
    // iOS/macOS: use the transactionId (purchaseID)
    return purchase.purchaseID ?? '';
  } else {
    // Android: use serverVerificationData (contains the purchaseToken)
    return purchase.verificationData.serverVerificationData;
  }
}