Hello.
Today, I implemented in-app related features using Prime31, one of Unity's frameworks.
Prime31 provides two separate managers: StoreKit and Google IAB.
I proceeded by building a unified manager using:
#if UNITY_IOS || UNITY_IPHONE
#elif UNITY_ANDROID
#endif
This approach allowed me to control purchases by issuing identical product keys for both platforms.
The order of operations is as follows:
1. Import Prime31 (Android: ver. 2.10, iOS: ver. 2.15)
For Prime31, the plugin versions for iPhone and Android were different.
2. Test IAP
var listProducts = new string[2]; listProducts[0] = "com.test.crystal100"; listProducts[1] = "com.test.crystal200"; StoreKitManager.productListReceivedEvent += ProductListReceived; //listen for purchase StoreKitManager.purchaseSuccessfulEvent += PurchaseSuccessful; StoreKitManager.purchaseFailedEvent += PurchaseFail; StoreKitManager.purchaseCancelledEvent += PurchaseCancelled; //Request product list StoreKitBinding.requestProductData(listProducts);
To briefly explain the code:
`listProducts` contains the product IDs registered in iTunes. When you call `requestProductData` with these, it checks whether the products exist.
You should set the data in the `ProductListReceived` callback.
For the `Purchase` function, I unified the implementation for both IAB and IAP.
3. Test IAB
GoogleIAB.init( key ); GoogleIAB.setAutoVerifySignatures (true); GoogleIABManager.billingSupportedEvent += billingSupportedEvent; GoogleIABManager.billingNotSupportedEvent += billingNotSupportedEvent; GoogleIABManager.queryInventorySucceededEvent += queryInventorySucceededEvent; GoogleIABManager.queryInventoryFailedEvent += queryInventoryFailedEvent; GoogleIABManager.purchaseCompleteAwaitingVerificationEvent += purchaseCompleteAwaitingVerificationEvent; GoogleIABManager.purchaseSucceededEvent += purchaseSucceededEvent; GoogleIABManager.purchaseFailedEvent += purchaseFailedEvent; GoogleIABManager.consumePurchaseSucceededEvent += consumePurchaseSucceededEvent; GoogleIABManager.consumePurchaseFailedEvent += consumePurchaseFailedEvent;
4. New Class `IAPManager` -> include "GoogleIAB", "StoreKitManager"
I used the following directives to handle platform branching:
#if UNITY_IOS
#elif UNITY_ANDROID
#endif
After that, the purchase logic was handled with common code.
It is easier to manage if you match the product IDs between Android and iOS.
Don't create too many `product_id`s; instead, create a few by type (tier) and reuse them within your own database.
5. Receipt Verification Server Implementation
I used PHP for this. While validation is possible for iOS by receiving only the transaction ID, Google requires the use of their API, which necessitates a client-id, secret-key, and token. (There is a lot to prepare, and it takes some time.)
6. Conclusion
If there was one part that took the longest while proceeding:
Error:
"The item you requested is not available for purchase"
This was the error.
Since the product list I registered was coming in correctly within the `queryInventorySucceededEvent`, the connection between the app and the developer console seemed fine. However, this error kept appearing.
To resolve this, I took the following actions:
1. Checked APK version code and version name (Version code and version name within the manifest must match.)
2. Permission Setting.
I eventually solved it.
To determine if testing is not working, first, you must be able to download it via the link. This means you should not see "404 not found" when clicking the link. (In that case, it seems it is not yet in an enabled state.) In my case, it worked well after the link was activated. It took about a day for the link to be activated.