iOS - when opening the app, and checking the receipt, the last transaction is present

When I open my app on iOS, even after it being killed, when IAP initializes and I look into the apple receipt, the latest completed transaction is present in there, is that expected behaviour? I use only consumables.

When I make a purchase, it seems to purge the previous transaction and only contain the latest again. I can work with this but wanted to know if that’s expected behaviour(?)

1 Like

I believe Loris2222 reported similar behavior. Can you show your code so we can confirm if it is the same issue? https://discussions.unity.com/t/800251

Thanks for the reply:
This is my code:

public void Start () {
builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());


builder.AddProduct("product1", ProductType.Consumable);
builder.AddProduct("product2", ProductType.Consumable);
builder.AddProduct("product3", ProductType.Consumable);
builder.AddProduct("product4", ProductType.Consumable);
builder.AddProduct("product5", ProductType.Consumable);
builder.AddProduct("product6", ProductType.Consumable);



UnityPurchasing.Initialize (this, builder);
#if UNITY_IOS
storedReceiptIOS = builder.Configure<IAppleConfiguration>().appReceipt;

var appleConfig = builder.Configure<IAppleConfiguration>();
var appleReceiptData = System.Convert.FromBase64String(appleConfig.appReceipt);
AppleReceipt appleReceipt = new AppleValidator(AppleTangle.Data()).Validate(appleReceiptData);
Debug.Log("Apple start info:");
Debug.Log(appleReceipt.bundleID);
Debug.Log(appleReceipt.receiptCreationDate);
Debug.Log(appleReceipt.inAppPurchaseReceipts.Length);

foreach (AppleInAppPurchaseReceipt productReceipt in appleReceipt.inAppPurchaseReceipts) {
Debug.Log(productReceipt.productID);
Debug.Log(productReceipt.purchaseDate);
}
#endif
}

Please describe in your code where you see “the last completed transaction” and specific steps to reproduce and the corresponding runtime Debug.Log output via XCode https://discussions.unity.com/t/700551

I see it here:

#if UNITY_IOS
storedReceiptIOS = builder.Configure<IAppleConfiguration>().appReceipt;
var appleConfig = builder.Configure<IAppleConfiguration>();
var appleReceiptData = System.Convert.FromBase64String(appleConfig.appReceipt);
AppleReceipt appleReceipt = new AppleValidator(AppleTangle.Data()).Validate(appleReceiptData);
Debug.Log("Apple start info:");
Debug.Log(appleReceipt.bundleID);
Debug.Log(appleReceipt.receiptCreationDate);
Debug.Log(appleReceipt.inAppPurchaseReceipts.Length);
foreach (AppleInAppPurchaseReceipt productReceipt in appleReceipt.inAppPurchaseReceipts) {
Debug.Log(productReceipt.productID);
Debug.Log(productReceipt.purchaseDate);
}
#endif

In the Debug.Log statements. appleReceipt.bundleID, appleReceipt.receiptCreationTime and productReceipt.productID and productReceipt.purchaseDate all print to the console (can see in xCode) the information of the last (successful) transaction I did, even after killing the app and restarting. As you can see in my previous post this is all in Start() so right off the bat. This is in ios sandbox.

That is the app receipt which is a receipt bundle and should always contain all receipts, is my understanding. Does it contain two receipts if you make 2 prior purchases?

Looking further into it, the behaviour does make sense. Looking into Apple dev docs here:
https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html

Since I only have consumables the behaviour makes sense that the last IAP is shown.
BTW @JeffDUnity3D , would you know if the in-app-purchase receipts in AppleReceipts(from Unity IAP) are in order? That the latest transaction would be the first one in the list (index 0) in AppleInAppPurchaseReceipt[ ]?

I would not recommend to rely on any ordering, it’s likely a collection (unordered by definition)

1 Like