Description of your issue
I am implementing a weekly subscription in my game using Codeless IAP, the basic IAP integration seems to go pretty fluent, but the validation process (getting a receipt and check if the user is subscribed) seems to be very foggy and unclear.
As of now, I’m testing my implementation on Google Play, this is the steps I took so far:
Added my subscription as an IAP product
Added licensed testers from Google Play Console and set them to “RESPOND_NORMALLY”
Updated Google License Key in the unity IAP receipt validation obfuscate window
Uploaded my test build for internal testing
Your purchasing script
I don’t have issue in the purchasing script, I wasn’t able to confirm if the user’s subscription is active or not.
Here’s the code that I used in my first scene of the game in order to check if the user has an active subscription:
private void Awake()
{
Product weeklySubscriptionProduct = CodelessIAPStoreListener.Instance.GetProduct(weeklySubscriptionID);
string weeklySubscriptionReciept = weeklySubscriptionProduct.hasReceipt ? weeklySubscriptionProduct.receipt : null;
if (weeklySubscriptionReciept != null)
{
//Check if active
SubscriptionManager manager = new SubscriptionManager(weeklySubscriptionProduct, null);
Result result = manager.getSubscriptionInfo().isSubscribed();
if (result == Result.True)
{
TempData.isSubscribed = true;
return;
}
}
//If function don't return till this line, subscription is inactive
TempData.isSubscribed = false;
}
This code seems to work on the Unity editor, it returns logical values and behaves as desired. However, when I check the version on Google Play’s internal testing, I get the following exception:
No need to say that the product defined on Unity IAP catalog and also in Google Play subscriptions.
The documentation on this is very narrow and unclear, focusing mostly on the basic implementation, but not on the receipt validation process.
Device logs
This is the logcat I got on my Android device:
CodelessIAPStoreListener attempted to get unknown product com.emojo.XXX.XXXXX
Unity Version
Unity 2020.3.15f2
Unity IAP version
4.0.0
Platform you are building for
Building for both Android & iOS, but the implementation tested as of now on Google Play.
Store you are targeting
Google Play
I am pretty sure I’m doing few things wrong, any help is necessary.
You are mixing Codeless and Scripted IAP (you posted code!). Codeless doesn’t currently support subscriptions, I would recommend that you look at the the new samples that are shipped with IAP 4.0.0, there is a subscription example using Scripted IAP. You can also take a look at the Sample IAP Project v2 here Sample IAP Project
Thanks!
I got to say that the subject of IAP/Codeless IAP is the most unclear subject in Unity’s documentation.
I just went over the MyIAPManager class in the IAP Project v2, and I admit I don’t understand few things -
for example, on this page: IAP Catalog | In App Purchasing | 4.0.3
You show two options to create IAP products, one of them is using the IAP catalog, just like the codeless IAP implementation.
If I’m using the IAP button, so I am basically using Codeless IAP…?
Do you mean I need to change all of my implementation?
I can’t “mix” scripted IAP and Codeless IAP?..
What does it mean that the Codeless IAP does not support subscriptions…?
If I’m able to get the product from the StoreListener by its ID, from this point,
How is it different getting the subscription info…?
Yes, unfortunately that is what I was afraid of. You are mixing Codeless (using an IAP Button) and scripted IAP (OnPurchaseComplete is a scripted IAP method). Note in the docs for Codeless it calls GrantCredits only, and that file does not have a using UnityEngine.Purchasing reference. You can add products via the Catalog or through scripting, I prefer the scripted approach like in the Sample IAP Project. Using the Catalog doesn’t necessarily mean you are using Codeless, but using an IAP Button does. We are working to improve that. So you may need to discard the code you are working on, and instead use the Sample project. I might suggest to actually publish the Sample project like it is to Closed testing on Google Play. This may help https://docs.unity3d.com/Packages/com.unity.purchasing@3.2/manual/UnityIAPGoogleConfiguration.html
So I basically “copy” and modify the sample implementation, but I gotta ask, first about the builder.AddProduct overloads - I don’t need to put a price when I define a product, as I do in the IAP catalog…?
All the data I need when I’m adding product is just its ID and its type? and the rest plays by the store in the product and its price etc?
Nothing to add from the editor/Catalog?
The title/language and other advanced details are not really matter?
I would highly recommend not to Copy, but actually publish the Sample IAP Project first. And correct, don’t use the catalog. Your IAP product prices are defined on Google developer dashboard, we get the prices from there.
Ok, I will try publish it.
FYI, I updated the IAP to version 4.0.0 in the sample project, and I got this compiler error:
Assets\Scripts\MyIAPManager.cs(140,28): error CS1061: ‘IGooglePlayStoreExtensions’ does not contain a definition for ‘SetDeferredPurchaseListener’ and no accessible extension method ‘SetDeferredPurchaseListener’ accepting a first argument of type ‘IGooglePlayStoreExtensions’ could be found (are you missing a using directive or an assembly reference?)
Oh yeah, just comment out that line for now. If you look in the Deferred Listener sample shipped with IAP 4.0.0, you’ll see the correct syntax. https://discussions.unity.com/t/850100/10
Well, I listened to your advice and published the sample project, of course with configuring Google’s license key etc.
Now I’m having issues initializing IAP for this reason:
Initialization Failure Reason:NoProductsAvailable
But… I do have a subscription on the store.
I even opened another consumable product to check if there’s an issue with the subscription, but it doesn’t seem like that.
Here you can see that I do have the product active.
I understand from the documentation that there’s no app configuration issue, cause if there was, I would get an error saying appNotKnown.
Please share your code where you are adding products. Also, please provide the device logs. Are you testing in Closed testing? That will ensure that everything is set up correctly. Add your testers and provide them with the opt-in URL. On their device, they would browse to that URL, accept the testing invite, then redirect them to Google Play to download a private version of your game. Also, please provide the adb logcat logs, they will tell you which products are not available in case you misspelled them https://discussions.unity.com/t/699654 I generally create 1 or 2 additional testers using free email addresses.
Besides, for validating subscriptions auto-renewable receipts on Apple the app’s shared secret key must be used.
I don’t see any reference to that in Unity’s documentation.
I saw this post:
But it’s still not clear where do we need to put the shared secret key…?
For Google Play we use the obfuscate license key window, and I expected that when I’ll change my build platform to Apple, I’ll have an option in the window tab to fill my Apple’s app shared secret key.
How does that work?
Is it even possible testing on iOS before the IAP get’s approved…?
Yes, a review is necessary. The Google key can be entered in the Dashboard, and it’s only used for reporting on our Dashboard and does not impact transactions. There is no key for Apple, only Google.
Well sorry to say but you’re wrong and misleading the readers.
I checked on internal testing again cause I didn’t want to wait hours for review, and it did worked.
Apparently, the IAP in the store needed some time to process or something like that.
There’s definitely no reason to wait for review using closed testing, that is not a good advice to say the least.