Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Official Sample IAP Project

Discussion in 'Unity IAP' started by JeffDUnity3D, May 2, 2018.

Thread Status:
Not open for further replies.
  1. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    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 https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/ A 3 minute video showing how to download and use the IAP Sample Project is here

     

    Attached Files:

    Last edited: Feb 15, 2019
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    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.
     

    Attached Files:

  3. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    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 https://forum.unity.com/threads/iap...-but-doesnt-give-payout.1148126/#post-7382948
     

    Attached Files:

    Last edited: Aug 11, 2021
    steril, Sancejas, konsti1994 and 11 others like this.
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    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.
     

    Attached Files:

  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    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...-but-doesnt-give-payout.1148126/#post-7382948
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    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)
     

    Attached Files:

Thread Status:
Not open for further replies.