react-native-iap: `appAccountToken` missing on the return of the `getAvailablePurchases` method

Description

appAccountToken is not on the return of the getAvailablePurchases method.

Expected Behavior

appAccountToken should be on the return of the getAvailablePurchases method.

Environment:

  • react-native-iap: 12.10.5
  • react-native: 0.67.1
  • Platforms: iOS

To Reproduce Steps to reproduce the behavior:

export const getLastSubscription = async () => {
    const purchases = await RNIap.getAvailablePurchases({ automaticallyFinishRestoredTransactions: false })

    let lastSubscription = purchases?.filter(purchase => purchase?.transactionReceipt !== null)
    
    let uuid = Platform.select({
            ios: latestSubscription?.appAccountToken,
            android: latestSubscription?.obfuscatedAccountIdAndroid,
        })

    return {
        sku: lastSubscription?.productId,
        uuid // <------ null on iOS
    }
}

To fix the problem : I added the followings fields on the types files

// file : types/index.ts

export interface ProductPurchase {
  productId: string;
  transactionId?: string;
  transactionDate: number;
  transactionReceipt: string;
  purchaseToken?: string;
  //iOS
  quantityIOS?: number;
  originalTransactionDateIOS?: number;
  originalTransactionIdentifierIOS?: string;
  verificationResultIOS?: string;
  appAccountToken?: string; // <---- I added this
  //Android
  productIds?: string[];
  dataAndroid?: string;
  signatureAndroid?: string;
  autoRenewingAndroid?: boolean;
  purchaseStateAndroid?: PurchaseStateAndroid;
  isAcknowledgedAndroid?: boolean;
  packageNameAndroid?: string;
  developerPayloadAndroid?: string;
  obfuscatedAccountIdAndroid?: string;
  obfuscatedProfileIdAndroid?: string;
  //Amazon
  userIdAmazon?: string;
  userMarketplaceAmazon?: string;
  userJsonAmazon?: string;
  isCanceledAmazon?: boolean;
}
// file : types/appleSk2.ts

export const transactionSk2ToPurchaseMap = ({
  id,
  originalPurchaseDate,
  productID,
  purchaseDate,
  purchasedQuantity,
  originalID,
  verificationResult,
  appAccountToken // <---- I added this
}: TransactionSk2): Purchase => {
  const purchase: Purchase = {
    productId: productID,
    transactionId: String(id),
    transactionDate: purchaseDate, //??
    transactionReceipt: '', // Not available
    purchaseToken: '', //Not available
    quantityIOS: purchasedQuantity,
    originalTransactionDateIOS: originalPurchaseDate,
    originalTransactionIdentifierIOS: originalID,
    verificationResultIOS: verificationResult ?? '',
    appAccountToken: appAccountToken, // <----- I added this
  };
  return purchase;
};

Can you add this to the method ?

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I saw that the appAccountToken was added to the ProductPurchase TS interface, which is also used in the event sent to the purchaseUpdatedListener. However it seems like the appAccountToken is always undefined in that case?

Our setup is quite simple and the appAccountToken also appears in the App Store Server Notifications, so I don’t think we did anything wrong there:

// somewhere on payment page
await requestSubscription({ ...purchase, appAccountToken: "some-uuid" });

// somewhere else
purchaseUpdatedListener((purchase) => purchase.appAccountToken); // always undefined

@fodjan-philip I’ll try to take a look at this as soon as I have time for it !