Sample IAP Project

Please find attached a sample Unity project that demonstrates several uses of Unity IAP. The Toggle button allows you to switch between returning Pending and Complete from ProcessPurchase at runtime, and the Complete button allows you to call and test ConfirmPendingPurchase. The code is provided as-is, and should not be used in Production without complete testing. It is recommended to monitor the device logs using adb logcat as described here How To - Capturing Device Logs on Android A 3 minute video showing how to download and use the IAP Sample Project is here

3482317–276993–IAP_Project.zip (2.35 MB)

12 Likes
Editor IAP or Script IAP
Codeless IAP for Subscriptions
Having Trouble with Unity IAP on IOS, Please Help
Same product identifier for 2 stores
Questions about the IAP Sample Project
UNITY IAP(Google)- Purchase failed because Purchasing was not initialized correctly
Handling purchases without the Unity IAP button
Two classes with the same name in unity IAP cause an error in IOS mode
How to get unhandled purchase event?
The type or namespace name 'IStoreListener' could not be found
[Resolve]Unity iap and European Strong Customer Authentication (SCA) / Interrupted purchases
Google Play IAP button just not working, but no errors, no reason I can see
IAP CRASHES Unity with: UnityTls error code: 7 in
Unity IAP Subscription info does not include enough details
Android - OnPurchaseFailed is not called
JDK Error - Building Android
Unity IAP buttons dont work once in app?
Unity IAP Compile errors
can't compile project with custom package
"OnPurchaseFailed,Duplicate transaction" (733943)
In app purchase to remove adds
UnityPurchasing Stores.dll broken assembly
Twice IAP after the scene reload
[Bug] UnityIAP 2.2.0 migration problem - Google v3 initialization
duplicateTransaction when buying an item twice in Alpha APK
[Android]Error when Purchase a Consumable Item that already owned by player
Erorr in build when import IAP
Changes to IAP Catalog are not saved (?)
IAP Sandbox 21105, is this a problem
Double Spend Issue
How to verify that a user has a valid subscription.
ConfirmPendingPurchase cannot be executed correctly during the subscription restore process on iOS.
Unity IAP implementation troubles
Trying to use Windows.Services.Store namespace?
IAP Button goes missing...
[Solved] [2.2.2] Non-consumables don't have a receipt anymore in OnInitialized
Error reporting a crash (request timeout)
Unity Codeless IAP - Purchase failed because Purchasing was not initialized correctly (iOS only)
IAP purchase fails on some iPad and not on others.
[iOS] IAPs working fine in TestFlight, game rejected by Apple because of NoProductsAvailable
[Android] NullReferenceException on pause/resume before init
[Solved] IAP Initialization Not Completing ~5%
[AmazonAppStore] Problem of UnityPurchasing.Initialize
"User's purchase success, but OnPurchaseFailed() is called" (837000)
"User's purchase success, but OnPurchaseFailed() is called" (726479)
Android SubscriptionInfo not working
I'm having a hard time understanding the Codeless IAP Listener
Why is there no purchase validation out of the box ???
Unity IAP How to Retry PurchaseProcessingResult.Pending Purchase?
getSubscriptionInfo() method crashes on Android.
Error Uploading to Google Store : missing android:label and No entry point for your Instant App
Codeless IAP Listeners
Unity IAP implementation troubles
IAP codeless for Android Google play
Codeless IAP is restoring consumable, and it should not.
Codeless IAP, purchases automatically refunded.
What if I Inititlize multiple times?
Disable ads when user buys item
IAP restore issues (Android)
Unity IAP (757413)
Iap Google Receipt
How to implement custom prompt for Unity IAP and Apple Pay integration?
[Solved] Unity IAP does not work on devices
Works in Editor but not in IOS device connected to XCODE
How to verify that a user has a valid subscription.
Unity IAP How to Retry PurchaseProcessingResult.Pending Purchase?
How do I display the value of donation in the game?
General IAP questions for official unity learn tutorial
Codeless IAP - PurchasingUnavailable (Purchasing was not initialized correctly)
Android Imediate crash after implementing unity IAP
Purchasing: the name StandardPurchasingModule does not exist in current context
Apple Subscription product info, any reference for what are the keys?
[Unity 2017.3.1f1] Importing IAP introduces game breaking bug
How to access GooglePlayStore.FinishTransaction
Unity IAP payment interface won't appear
Is it possible to check if a purchase of a non consumable has ever been made?
How to get products from Play Store? Metadata is empty.
Erorr in build when import IAP
IAP Fails to Initialize on UWP
Pending purchases getting called twice on restart
IAP triggering OnPurchaseFailed even after a successful purchase on Android
Update to 2.2.2, have some NullReferenceException
Unity_IAP_2.2.4 and Core Package 2.2.1 Play Store Errors
How do I call Purchase fulfillment function to IAPButton via code
[Android] NullReferenceException on pause/resume before init
Unity IAP (iOS) How to get Subscription product's info?
Issues with TestFlight IAP restores (non-consumable)
Product Id in codeless IAP - Do I define this myself?
Android App crashes using Unity IAP 1.21.0
Unity IAP How to Retry PurchaseProcessingResult.Pending Purchase?
IAP purchase doesn't work in andorid
Codeless IAP not working (770748)
Codeless IAP OnInitialized
Codeless IAP 1.23.2 Restore Workflow
how can I make a IAP Subscription code in unity 2019.1.9 for google play ?
Unavailable product in Unity In app Purchase but it's in my store
Unity IAP Services not Working in my release App since iOS 13.4. The purchase dialog does not show.
Codeless IAP - How to restore purchases on Android?
BuyProductID Initialization Fail on iOS
Question about coding for adding and removing health for an IAP
IAP General Questions
[iOS] Duplicate Transaction error on purchases
Cannot get IAP to work
How to setup In App Subscription with Codeless IAP
Unity IAP Services not Working in my release App since iOS 13.4. The purchase dialog does not show.
Help for managing and controlling the apps , premium membership feature
IAP -goole pay (BuyProductID FALL .Not initialized)
Unity IAP error on 2.1.1(purchase failed because purchasing was not initialized correctly)
Update IAP plugin 1.19 problem: no known instance method for selector 'introductoryPrice'
HELP! IAP Catalog window not showing!
OnPurchase Complete(Product) is not called After Successful
Restore pursce it alway restore success?
Apple iOS Build With Unity IAP Not Launching On iPad
Unity IAP Catalog
Unity 2018.1.2f1 and IAP 1.20 issues on iOS subscriptions
Unity IAP doesn't work after installing Unity Monetisation plug in. Pls help!
IAP does Not work
Codeless IAP not working (770748)
Restoring non-consumable
Is it OK to post my Unity project folder online?
Crash after UpdatedTransactions
Does IAP Work?
"Unity IAP,Completion without reward" (737967)
MethodAccessException: Method `UnityEngine.Purchasing.Product:set_receipt (string)' is inaccessible
Purchase failure due transaction
IAP calls OnPurchaseFailed after success
Unity IAP Question (829719)
Codeless IAP not restoring purchase on android
Can't Able to Add In-App Products at Google Play Console
samsung iap crash
how to add in app purchases and ads
Pending Purchase Not Working
UWP, IAP 1.20.1, non-consumable (durable)
Codeless in App Purchases in iOS not executing pop up in Testflight
UNITY IAP (Android) - Item already own wrong message
Unity IAP Store package 2.2.0 does not update
[bug] Unity IAP 2.2.5 cannot ConfirmPendingPurchase
Codeless IAP works in Testflight, but it's rejected from Apple Store
ProcessPurchase: FAIL. Unrecognized product: (Solve)
Subscriptions stopped working with 1.22.0
Problem with IAP "Purchasing Unavailable "
iOS: Subscription issues with 2.2.7 Store Pakage
IAP restore issues (Android)
Unity IAP bug on PurchaseProcessingResult listener not cleared
GetSubscriptionInfo Help
Unity IAP bug on PurchaseProcessingResult listener not cleared
[IAP] Implementing a Store, IStoreListener, IStore or IStoreCallback?
IAP game not even startin on android
Re-purchase refunded non-consumable google play IAP.
[Wrong behavior] Already recorded transaction
IAP Button goes missing...
Purchases working in Editor not on phone
IAP Subscription setup question
Create promotion as a products not a placement?
In-App Not Working On Android Device
IAP buttons not working IOS
Unity IAP Services not Working in my release App since iOS 13.4. The purchase dialog does not show.
IAP receipt validation on app start
Unity IAP didn't respond onActivityResult infinitely
Set IAPButton productId by script (so that it works)?
Restore auto renewable subscription
"Unable to insert COPY_SEND"
IAP doesn't work in VR mode (Cardboard)
Broken Link on IAPurchases page.
ProcessPurchase should be async
Product does not have receipt for Non Consumable in Unity on Android
Help me understand the local catalog relation with AppStoreConnect
IAP return PurchaseFailureReason Unknown. Android (Google Play)
Unity IAP Weird Stuck Transactions Not Finishing
Android Kills App During IAP Purchase!
Infinite loop during upgrade from 1.22 to 1.23
On Initialized does not pass after purchasing a subscription in the Sample IAP Project
Unity IAP automatically cleans up pending transactions for subscriptions
IAP Dev time
Server Side Receipt Validation at Google Play Store
Xcode error when Archiving linker command failed with exit code 1 (use -v to see invocation) clang (730390)
IAP 2.2.0 Error after purchase
Unavailable product for Google Subscriptions
Implementing Google Play billing
How to implement IAP for users who redeem apple IAP codes? I used codeless IAP in my game
Google payments are being automatically refunded.
Unity IAP InitiatePurchase with payload NullReferenceException
IAP compatibility issues
IAP is restoring consumable items
IAP: BuyProductID: FAIL. Not initialized In-App Purchases error
Unity IAP doesn't work on Android
Linker command failed with exit code 1 Xcode using Unity IAP
Questions about Codeless IAP with non-consumables
IAP Codeless restore problem
Where (in script) does Unity's IAP Plugin call UIFakeStoreCanvas?
ReflectionTypeLoadException: The classes in the module cannot be loaded. (675201)
Unity IAP 1.23.1 "DuplicateTransaction for Consumables"
error CS0246: The type or namespace name 'IAPButton' could not be found
IAP bool UnityEngine.VR.VRSettings.get_enabled() error
The type or namespace name 'IStoreListener' could not be found
copying code from IAP tutorial , then there is a lot of error in the log Unity 2017.2.0f3
Massive problems with IAP hackers
Actual Unity IAP Demo
Could not load type 'UnityEngine.VR.VRSettings' from assembly 'Stores'.
Bug with subscription in IAP version 2.2.5
Is there a way to access Google's purchaseToken directly without Crossplatform validator?
Apple iOS Build With Unity IAP Not Launching On iPad
How do I initialize the product after purchase.
RestoreTransactions does not call back ProcessPurchase
Google Play You already own this item
How to Test Android Subscriptions
"User's purchase success, but OnPurchaseFailed() is called" (837000)
IAP Automatically initializing, how to retry if it failed second time?
BILLING_RESPONSE_RESULT_ERROR
Non-consumable purchases
IAP Restore - Android
Unity IAP automatically cleans up pending transactions for subscriptions
Unity IAP automatically cleans up pending transactions for subscriptions
Unity IAP still not working (720050)
OnInitializeFailed InitializationFailureReason:NoProductsAvailable (759906)
Unity IAP How to Retry PurchaseProcessingResult.Pending Purchase?
error CS0103: The name 'StandardPurchasingModule' does not exist in the current context
onPurchaseFailedEvent : PurchaseState is UNSPECIFIED_STATE, no more details exists {M: GPUL.OPO}
Updating to 1.23 problems, blank update screen, DLL errors...
Question about unity economy real money purchase?
InvalidOperationException: To listen to deferred purchases, please register a listener
Manually initializing Unity IAP
Unity IAP v1.20.0 upgrade questions
Some questions about codeless IAP
UNITY 2019.2.7f2 OnPurchaseFailed bug
UNITY IAP (Android) - Item already own wrong message
unable to restore google non consumables?
Method not found: 'UnityEngine.VR.VRSettings and no API Update triggered
A lot of OverflowException from IAP plugin
Running Codeless IAP buttons on Android restore not working
UIFakeStoreWindow Error
Subscription acknowledged false
UnityIAP init freezes the main thread
IAP CRASHES Unity with: UnityTls error code: 7 in
Codeless IAP - PurchasingUnavailable (Purchasing was not initialized correctly)
No products found when trying to test in iOS sandbox
Unity IAP failing _only_ during Apple review
IAP Button works only in TestMode
Saving Data to PlayerPrefs
Unity IAP Weird Stuck Transactions Not Finishing
Unity IAP InitializeFailed(PurchasingUnavailable)
java.lang.ClassNotFoundException: com.android.billingclient.api.PurchasesUpdatedListener
UnityIAP: Requesting product data... and nothing happend
Tracking Monetization: Receipt Verification
Nothing happens when I click in a product
Unable to purchase subscription via iOS sandbox environment
Double Purchase Call
iOS not pulling data
Bad Link in "Read this before you post"
Restore Transactions is not calling ProcessPurchase
Changing from codelessIAP to coded IAP
I can make IAP work in my game. Failure Reason: Unknown

Here is a sample Unity project to demonstrate Codeless IAP. There are two buttons, one to purchase a consumable (“Gold”), and one to purchase a non-consumable (“No Ads”). The IAP Listener is currently disabled, but can be enabled to test behavior when the Codeless IAP buttons might not be enabled on app start.

3930841–335824–CodelessIAPTest.zip (2.35 MB)

3 Likes

Here is v2 of the Sample IAP Project. This project includes receipt validation and subscription support, as well as a deferred purchase listener. It is using IAP 3.0.1. To use the validator, you’ll need to generate your own tangle files from menu Window/Unity IAP/Receipt Validation Obfuscator. For use with IAP 4.x, see this post IAP iOS sandbox payment success but doesn't give payout - Unity Services - Unity Discussions

6950270–817625–Sample IAP Project.zip (49.7 KB)

16 Likes
OnInitialize Bug
IsPurchasedProductDeferred issues / questions
Problem with Apple RefreshAppReceipt and SubscriptionManager and handling free trial eligibility
IAP works in editor but not on Android/iPhone
NoProductsAvailable issue on iOS, Android is working properly
OnPurchaseFailed ProductUnavailable from Google store
3 days automatic refund on the google play store.
Can I use Codeless IAP for non-UI buttons?
Error in integrated purchases, please help!
No ads IAP and Restore for iOS/Googleplay
facing with lots of error after updating IAP to 3.1.0
How do i add 'no ads' in-app purchase ?
MethodAccessException when UnityIAP is initializing and trying to query interrupted transaction
IAP Button not functioning outside test
How can I check if an in-app product is purchased before?
Auto Renewing Subscription - complaints from users that it is NOT WORKING?!
Build fails on iOS for some missing files from Unity Purchasing
Purchases not restored on Android - Error: You already own this item
NullReferenceException in UnityEngine.Purchasing.ReflectionUtils.HasMethodInInterface
UnityPurchasing.Initialize is no working in android
Microsoft Store IAP Initialisation Exception
In App Purchases (IAP) does not work on Android
IAP works in editor but not on Android/iPhone
"Unity IAP,Completion without reward" (737967)
How to queue a paid function to run after an IAP button purchase completes to fund it?
Order Status: Pending and Chargeable after updating IAP
IAP Restore - Android
Can't restore non-consumable?
Codeless IAP not restoring purchase on android
(Android) Some users do not receive purchased items
Unable to retest IAP after refund in Google Play Console
NullReferenceException in UnityEngine.Purchasing.ReflectionUtils.HasMethodInInterface
Purchase the app and remove the ads (best way to handle it?)
Help Needed: OnPurchaseFailed, PurchaseFailureReason: ProductUnavailable
Unity IAP Package causes errors
PurchaseManager doesn't fire OnProducetsRetrieved on second init
Receipt validation cause restore purchases on iOS automatically
Which PurchaseFailureReason is good to show
Codeless IAP is wonderful and deprecating it is the biggest mistake
[bug] Unity IAP 2.2.5 cannot ConfirmPendingPurchase
IAP Button when clicked again gives Purchase Complete without even clicking Buy/Cancel
IAP stopped registering any purchases.
test purchase not being acknowledged on google playstore
Unity Codeless IAP Error From Mobile Phones iOS and Android
Amazon IAP Initialize not called.
[Solved] Unity IAP unable to strip and OverflowException: Value was either too large exceptions
How do I check my Unity IAP subscription renewal receipt?
Add Security/Obfuscation support to all platforms (including Editor)
IAP prompts DuplicateTransaction
Need help to make sure I did everything right with IAP.
(SOLVED) Do I have to delete the Unity IAP (obsolete)? Keep receiving message for update
Purchases not restored on Android - Error: You already own this item
So many problems with IAP 3.1.0
Disabling Ads and IAP for specific users.
How can I create runtime debug logging for windows build?
Codeless IAP and subscriptions
IAP 4.1.2 Multiple Errors
Google play trial period
Problem with iOS Unity IAP, OnInitializeFailed : No Products Available
Crash in test environment in Slow test card mode.
Unity IAP is not working on android device (837693)
Error IAP version 3.0.2, unity 2019.4.23f1
UnityIAP: Finishing transaction XXXXXXXXXXXX
Unity IAP package 3.0.1 error DeObfuscate
Second subscription product not showing up (Android)
Unity IAP non-consumable (remove ads) gets refund by google after 3 days
Amazon IAP Initialize not called.
Unity IAP .isSubscribed() is always true?
UnityPurchasing.Initialize cannot pass initialization after completing purchase of subscription
Unity IAP - CodelessIAPStoreListener attempted to get unknown product
Unknown error on success payment -android platform
Codeless IAP 3.1.0 package missing UIFakeStoreCanvasPrefab
Subscription/IAP Receipt Validation
IAP Codeless Button not working on Android
Google Play IAPs not restoring: Error. You already own this item

I am posting Version 3 of the Sample IAP Project that better interoperates with IAP 4.x Several new features have been added such as a separate Initialize button and common code examples. There is also a New User button that allows you to call SetObfuscatedAccountId on the Google platform to associate the purchase with a specific/custom user logon, for example. Open MyScene in the /Scenes folder to begin.

7922275–1011082–My_Sample_IAP_Project_v3.zip (3.35 MB)

8 Likes

Remember to update the project with the latest IAP. If you see an error with the deferred listener, see this link https://forum.unity.com/threads/iap-ios-sandbox-payment-success-but-doesnt-give-payout.1148126/#post-7382948

1 Like

Here is Version 4 of the Sample IAP Project. This project is using IAP 4.4.1 and UGS Analytics 4.2.0. It demonstrates a deferred purchase listener as well as the IAP initialization listener. If IAP cannot initialize, we will retry and SetQueryProductDetailsFailedListener is triggered on each retry. For example, test without an Internet connection and you will see the retry count in the debug output. This project also demonstrates UGS Analytics initialization and the sending of a UGS Analytics Custom Event in the Restore method. When opening this project after unzipping, ensure to relink to your own Unity ProjectID. If you want to use receipt validation, you will need to obfuscate your Google Public Key (leave the field blank if targeting Apple only)

8432501–1116704–PureRockets_IAP.zip (224 KB)

20 Likes