Search code examples
flutterin-app-purchase

in_app_purchase purchaseID does not stay the same


I am using the package in_app_purchase. I noticed that the PurchaseDetails.purchaseID for past purchases changes because they take the transactionIdentifier instead of checking for a origional transaction. When a transaction is restored the id changes.

Apple In-app purchase transaction_id of one purchase changes sometimes

Is anyone else having the same problem?

This is their code to instantiate product details from a transaction

  PurchaseDetails.fromSKTransaction(
      SKPaymentTransactionWrapper transaction, String base64EncodedReceipt)
      : this.purchaseID = transaction.transactionIdentifier,
        this.productID = transaction.payment.productIdentifier,
        this.verificationData = PurchaseVerificationData(
            localVerificationData: base64EncodedReceipt,
            serverVerificationData: base64EncodedReceipt,
            source: IAPSource.AppStore),
        this.transactionDate = transaction.transactionTimeStamp != null
            ? (transaction.transactionTimeStamp * 1000).toInt().toString()
            : null,
        this.skPaymentTransaction = transaction,
        this.billingClientPurchase = null,
        _platform = _kPlatformIOS {
    status = SKTransactionStatusConverter()
        .toPurchaseStatus(transaction.transactionState);
    if (status == PurchaseStatus.error) {
      error = IAPError(
        source: IAPSource.AppStore,
        code: kPurchaseErrorCode,
        message: transaction.error.domain,
        details: transaction.error.userInfo,
      );
    }
  }

Where

 this.purchaseID = transaction.transactionIdentifier,

Should check if restored and if so take the identifier from the origional transaction.

I'm on the latest version in_app_purchase: ^0.3.4+16 and flutter 1.20.3 stable channel

Everytime when I restart my app and call _connection.queryPastPurchases the purchaseID is different of the purchase found


Solution

  • Using the origional transaction id seems to work great