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)

11 Likes

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)

15 Likes

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)

19 Likes