- Home /
Unity IAP Error: Unable to buy item (response: 7: Item Already Owned ) DuplicateTransaction
Hi,
I use Unity 2018.3 and Unity In-App Purchase in my game. I encountered this error: products that I tried to buy before but failed in the middle of the process seem like bought and I can't buy those products now because it says they are already owned.
Here is how it happens: I try to buy a consumable product. While it is being bought I close the game before the process was completed. Then the product stays as consumed because consuming the product happens at the end of the purchasing process by Unity IAP. Which means, I initialize the buying process but I don't finalize it so, Google Play sees it as bought and not consumed. When I try to buy the same item again, this time it gives me an error that I can't buy it again because the item is already owned.
This is the log file:
03-03 15:39:09.735: I/Unity(8475): Purchasing product asychronously: 'specialpack1'
03-03 15:39:09.735: I/Unity(8475):
03-03 15:39:09.735: I/Unity(8475): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
03-03 15:39:09.736: I/UnityIAP(8475): isUnityVrEnabled = false
03-03 15:39:09.737: I/UnityIAP(8475): onPurchaseProduct: specialpack1
03-03 15:39:09.737: I/UnityIAP(8475): ITEM TYPE:inapp
03-03 15:39:09.753: I/Unity(8475): purchase({0}): specialpack1
03-03 15:39:09.753: I/Unity(8475):
03-03 15:39:09.753: I/Unity(8475): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
03-03 15:39:09.799: I/UnityIAP(8475): Creating purchase activity
03-03 15:39:09.799: I/UnityIAP(8475): oldSkuMetadata is null
03-03 15:39:09.800: I/UnityIAP(8475): invoking callback
03-03 15:39:09.800: I/UnityIAP(8475): Constructing buy intent for specialpack1, item type: inapp
03-03 15:39:09.854: I/UnityIAP(8475): Launching buy intent for specialpack1. Request code: 999
-- Note: App was closed here before the buying process was completed
03-03 15:40:29.066: I/Unity(8722): Purchasing product asychronously: 'specialpack1'
03-03 15:40:29.066: I/Unity(8722):
03-03 15:40:29.066: I/Unity(8722): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
03-03 15:40:29.083: I/UnityIAP(8722): isUnityVrEnabled = false
03-03 15:40:29.087: I/UnityIAP(8722): onPurchaseProduct: specialpack1
03-03 15:40:29.089: I/UnityIAP(8722): ITEM TYPE:inapp
03-03 15:40:29.113: I/Unity(8722): purchase({0}): specialpack1
03-03 15:40:29.113: I/Unity(8722):
03-03 15:40:29.113: I/Unity(8722): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
03-03 15:40:29.162: I/UnityIAP(8722): Creating purchase activity
03-03 15:40:29.162: I/UnityIAP(8722): oldSkuMetadata is null
03-03 15:40:29.163: I/UnityIAP(8722): invoking callback
03-03 15:40:29.163: I/UnityIAP(8722): Constructing buy intent for specialpack1, item type: inapp
03-03 15:40:29.200: I/UnityIAP(8722): onIabPurchaseFinished: false
03-03 15:40:29.200: I/UnityIAP(8722): Unable to buy item (response: 7:Item Already Owned)
03-03 15:40:29.200: I/UnityIAP(8722): Purchase response code:7
03-03 15:40:29.279: I/UnityIAP(8722): onActivityResult
03-03 15:40:29.347: I/Unity(8722): onPurchaseFailedEvent({0}): specialpack1
03-03 15:40:29.347: I/Unity(8722):
03-03 15:40:29.347: I/Unity(8722): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
03-03 15:40:29.363: I/Unity(8722): OnPurchaseFailed: FAIL. Product: 'specialpack1', PurchaseFailureReason: DuplicateTransaction
03-03 15:40:29.363: I/Unity(8722):
03-03 15:40:29.363: I/Unity(8722): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
Answer by MSOTech · Feb 26, 2019 at 02:16 PM
I have solved it. It turns out there was an error in the code that prevented Unity IAP from consuming all of the products at the beginning. Therefore PurchaseProcessingResult.Complete wasn't being returned.
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
// (code with error was here)
return PurchaseProcessingResult.Complete;
}
Not sure I understand what code was causing the error. here is my method. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { bool success = true; if (String.Equals(args.purchasedProduct.definition.id, product_gemsSmall, StringComparison.Ordinal)) { if (isInQuickMenu == true) { PurchaseQuickGemsSuccess(); } else { balloonMenu.PurchaseGemsSuccess(0); } } else if (String.Equals(args.purchasedProduct.definition.id, product_gemsMedium, StringComparison.Ordinal)) { balloonMenu.PurchaseGemsSuccess(1); } else if (String.Equals(args.purchasedProduct.definition.id, product_gemsLarge, StringComparison.Ordinal)) { balloonMenu.PurchaseGemsSuccess(2); } else if (String.Equals(args.purchasedProduct.definition.id, product_gemsExtraLarge, StringComparison.Ordinal)) { balloonMenu.PurchaseGemsSuccess(3); } else if (String.Equals(args.purchasedProduct.definition.id, product_gemsXXLarge, StringComparison.Ordinal)) { balloonMenu.PurchaseGemsSuccess(4); } else if (String.Equals(args.purchasedProduct.definition.id, product_heroOfTheDay, StringComparison.Ordinal)) { balloonMenu.OnConfirmPurchaseHeroOfTheDay(); } else if (String.Equals(args.purchasedProduct.definition.id, product_tokenOfTheDay, StringComparison.Ordinal)) { balloonMenu.OnConfirmPurchaseTokenOfTheDay(); } else { balloonMenu.ExitTimeOutScreen(); success = false; Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id)); } if (success) { //Also checks if logged in in WEB script Web.web.SaveIapReciept(args.purchasedProduct.transactionID); } return PurchaseProcessingResult.Complete; }
Answer by Priyanka-Rajwanshi · Dec 21, 2019 at 04:41 PM
For resolving the bug, all you need is to edit the OnInitialized function as follows:
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
// Purchasing has succeeded initializing. Collect our Purchasing references.
// Overall Purchasing system, configured with products for this application.
m_StoreController = controller;
// Store specific subsystem, for accessing device-specific store features.
m_StoreExtensionProvider = extensions;
foreach (var product in m_StoreController.products.all)
{
m_StoreController.ConfirmPendingPurchase(product);
}
}
You can get more details here: http://codesaying.com/unity-iap-stuck/
Inside the OnInitialized function that Unity provides in their Purchase$$anonymous$$anager class when you use their Unity Purchasing plugin
Your answer
Follow this Question
Related Questions
Unity services linking to different projects at build time (Automated) 0 Answers
Cant build because services tab wont load 1 Answer
In Unity Services, can Managers in an organisation integrate IAP or do they need to be Owners ? 0 Answers
Link Unity Dashboard with Play Store Game 0 Answers
Web Service not running problem 0 Answers