ONE store In-App Purchase Unity Plugin Guides
Introduction to ONE store Unity Plugin
The ONE store unity plug-in is provided to make it easy to apply the ONE store IAP in the Unity development environment. The ONE store unity plug-in includes the method that handles the payment-related functions and the result of calling those functions. The file configuration of plug-in is as follows.
It is developed with Unity 5.6.0f3 version.
ONE store Unity Plugin
IapPlugin.java
It is responsible for connecting with the SDK.
It imports and uses the unitySendMessage and Activity inside the UnityPlayer through reflection, and therefore it may not use the internal class.jar where Unity is installed.
IapUnityPluginActivity.java
It is the Activity to receive the result value because it displays the Activity during the in-app product purchase or login.
JsonUtil
It is the utility which is used to pass data from Android to Unity.
PopupManager
It is the utility to easily display the result value and error value when each command is executed.
sdk com.onestore.iap.api.*
It is the SDK which is interworking with the IapPlugin (in the existing IAP SDK V16, the rest of the java file except the SDK is called Unity Adaptor).
ONE store Unity Plugin Configuration
If you download ONE store's unity plug-in through Github, you can check the folders seen below.
Assets/Plugins/Android/Onestore
This is the root folder of the ONE store plug-in and it has a subfolder of purchase / example.
In addition, the library for connecting with the ONE store IAP and the default AndroidManifest,xml file exist in this folder.
You can check the content of each file in the following File Configuration section.
Assets/Plubins/Android/Onestore/purchase
Located in this folder are the library provided by ONE store and Unity C# Script (CS) files which are responsible for connection.
Developers are allowed to communicate with the ONE store payment module by using these files.
The files within the purchase are bridge files responsible for communication with the library. You can learn how to use these CS files through the content of example.
You can modify and use this content, however it is recommended to use it without modification if possible.
You can check the content of each file in the following File Configuration section.
Assets/Plubins/Android/Onestore/example
Located in this folder are the library provided by ONE store and sample apps using CS files.
This content provides as the sample how to use all IAP APT provided by ONE store by using the CS file of the purchase in the view(scene) of the unity app.
You can check the content of each file in the following File Configuration section.
ONE store Unity Plugin Sample File Configuration
iap_plugin_all_v17.00.00_20171225.aar (the form in which the SDK, Unity Adaptor and Manifest are combined.)
Assets/Plugins/Android/Onestore
The Plugin file required for the Android build is included in this file.
It can be easily applied with one .aar file.
iap_plugin_v17.00.00_20171225.jar (the SDK part)
unity_adaptor_v17.00.00_20171225.jar (the Unity & SDK connection part)
AndroidManifest.xml
Assets/Plugins/Android/Onestore
The Plugin file required for the Android build is included in this file.
It is configured in the same form as version 16.
<meta-data android:name="iap:api_version" android:value="5"></meta-data>
<meta-data android:name="iap:api_version" android:value="5"></meta-data>
Onestore_IapCallManager.cs
Assets/script/onestore/purchase
It is responsible for calling Android in Unity.
It calls Android Unity plugin through a direct and individual command by using the values received from IapUi.
Onestore_IapCallbackManager.cs
Assets/script/onestore/purchase
Its primary responsibility is to receive the result value from Android to Unity.
Each method is passed in the format of 'method name + listener form' and the value of in-app product information is delivered in JSON format. Errors or other default values are passed in string format.
It converts a response method check, parsing and JSON into the form of PurchaseResponse, Signature, ProductDetail.
By default, it has the event Action which acts as a function pointer for each command. And therefore, it passes the first processed result to Onestore_IapResultListener to allow the end developer to easily use and work with the first processed result.
Onestore_IapResultListener
Assets/script/onestore/purchase
Developers can store, transform and check information to fit each type processed from Onestore_IapCallbackManager.
Each result value is set to appear as a pop-up message by default.
Onestore_PurchaseResponse
Assets/script/onestore/purchase
This is the file for converting the response JSON format into each type.
Onestore_IapUi.cs
Assets/script/onestore/example/UI/
It is responsible for the response when clicking each Button UI of the sample app.
Developers are allowed to modify and use the in-app product name, in-app product type, publicKey, developPayload, and etc. to perform tests. There is no need to revise other parts, and it only acts to pass the parameters set by the developer to Onestore_IapCallManager.
<CAUTION> Up to 100bytes are allowed for the size of the developPayload.'null' is not allowed for developPayload.
AndroidNative.cs
Assets/script/onestore/example/UI/
This is the utility related to a pop-up that displays the result value in each subfolder.
It is used to show the result value directly on the screen without the adb connection.
Example.unity
Assets/script/onestore/example/scene
This is the sample test screen of ONE store's IAP SDK V17.
one_brandmark_breadth, UI Textures/Textures and Sprites/SF Background
Assets/script/onestore/example/Image
This is the background screen and logo-related image.
Application of ONE store Unity Plugin
Apply Unity Plugin
Put the iap_plugin_all_v17.00.00_20171225.aar (or iap_plugin_v17.00.00_20171225.jar, unity_adaptor_v17.00.00_20171225.jar, and AndroidManifest.xml ) in the Asset/Plugins/Android/Onestore.
Or you can use by selecting the Assets/Import Package/Custom Package and importing the IapV17_UnityPluginSample.unityPackage which is attached.
When building, enter packageName as com.onestore.iap.apisample, select signkey01.keystore (check in the Use Existing Keystore) and enter Keystore password: signkey01, choose signkey01 in Key Alias and enter password:signkey01.
Canvas has 10 buttons, and the OnClick of each button is a method within IapUi.cs and connected one-to-one.
Onestore_IapUi GameObject is connecting one script component of Onestore_IapUi.cs.
Onestore_IapCallbackManager GameObject is connecting two script components of Onestore_IapCallbackManager.cs and Onestore_IapResultListener.cs.
Background GameObject simply acts as the background screen.



ONE store Unity Plugin Reference
Basic Operation & Precautions
Android and Unity mutually exchange all data, including PurchaseData, ProudctDetail, the original copy of the purchased in-app products and signature in JSON format. To change in-app product name, payload, public key for the default test, you can modify Onestore_IapUi_IapUi.cs and perform the test.
In the sample app, it is required to check the list of the purchased in-app products and save data after the in-app products are purchased in order to consume the in-app products and change the status of the subscription. And therefore, the PlayerPrefs is used for simple storage and the productId is saved as the key value in JSON format. As for the productId, you can use it by receiving JSON data as the same key value and passing it to Android or changing it into other types.
To use the 'consume' or ManagerRecurring by saving the in-app product information purchased through getPurchase, getbuyIntent, and etc. it is required to develop the in-app product data by using the data structure that the developer desires to create.
Onestore_IapUi.cs and Onestore_IapCallbackManager.cs are responsible for transmission and reception. However, they have Onestore_IapCallMnager and Onestore_IapResultListener separately to easily change the test value without modifying the logic and to conveniently receive the result value such as string and Json in the form of the changed data, including PurchaseData and ProductDetail.
Unlike IapUi, Onestore_IapCallManger has class variables to change the API version when the update is made later. And it has a feature to display an error pop-up on the button operation when initialization has not been performed. Furthermore, when calling from Android to Unity, the following codes are used to designate which game object should be called by importing the com.onestore.iap.sdk.unity.IapPlugin instance to the constructor part and passing it to the constructor parameter. Developers can change the codes according to their needs.
jc = new AndroidJavaClass("com.onestore.iap.sdk.unity.IapPlugin");iapRequestAdapter = jc.CallStatic<AndroidJavaObject>("initAndGet", "IapCallbackManager");
In the IapUi.cs example, when it comes to the 'cancel/reactivate auto', the 'cancel/reactivate' operation has been implemented as a sample to operate alternately on/off due the screen space issue. After this command is performed, recurringState is not changed in the result value which is shown in a pop-up. You can check the updated recurringState only through getPurchase.
Basic Flow from Unity to Android

Basic Flow from Android to Unity
Introduction to ONE store Unity Plugin Methods and Operation
Operation to Initialize Payment
Create PurchaseClient in plugin by passing 'Service Connect : public key', bind ONE store's in-app service and receive the result through the listener. The calling direction is from top to bottom and Unity will call Android.
This is a sequence where Android calls Unity through the connection listener. As a destination to receive the result value from Android to Unity, gameObject has already registered the GameObject named the 'IapCallbackManager' in the constructor part of IapCallManager.cs. With this value, Unity Plugin will pass the result value to this GameObject.
Since Onestore_IapCallbackManager.cs has been registered in the GameObject named 'IapCallbackManager', one of the string parameters of 'onConnected', 'onDisconnected' and 'onErrorNeedUpdateException' will be passed as the callback value to the ServiceConnectionListener method of this file. Each of the string parameters means that 'the service is successfully bound', 'the service is unbound' and 'the OSS is not the latest version or not installed'.
When the 'onConnected' is received through the parameter, serviceAvailableEvent() means a successful connection. And therefore, serviceAvailableEvent() is used to display an error pop-up when the connection is not successful.
Onestore_IapResultListener.cs has also been registered in the GameObject named "IapCallbackManager. During initialization, serviceConnectionEvent(callback) will call the serviceConnectionResult of the Onestore_IapResultListener.cs through Onestore_IapCallbackManager.serviceConnectionEvent += serviceConnectionResult, and will eventually display the connection-related message in the pop-up.
Check Support
The calling direction is from top to bottom and Unity will call Android.
This is a sequence where Android calls Unity through the connection listener. The string types of the result value received from the callback are as follows.
onSuccess: if checking status information is success
onError : if failed, an error code will be passed to the application. A code composed of numbers, and descriptions in the string form are passed in the form of ToString.
onErrorRemoteException: it occurs when a Remote call is requested at the time of unbinding the service.
onErrorSecurityException: it occurs when the application is falsified or abnormal in the APK.
onErrorNeedUpdateException: it occurs when the OSS is not the latest version or not installed.
Check Purchase History
The calling direction is from top to bottom and Unity will call Android.
This is a sequence where Android calls Unity through the connection listener. The string types of the result value received from the callback are as follows.
onSuccess: a success response to the 'check purchase information' calling :
if the purchased data exists, the format of “onSuccess” + json (productType: if the in-app product type is the inapp or the auto, purchaseData: the purchase data of the purchased original json, signature: the purchased signature) will be passed. If there is no purchase data, the format of “onSuccess”+ “[]” + producttype(“inapp” or “auto”) will be passed.
onErrorRemoteException
onErrorSecurityException
onErrorNeedUpdateException
onError: if failed, an error code will be passed to the application. A code composed of numbers, and descriptions in the string form are passed in the form of ToString.
The current signature is received from the IapCallbackManager but is not passed here. It is because that the review has been performed by default through the purchase data and signature within the SDK. If the signature is needed, it can be imported from the IapCallbackManager and used. Setting the PlayerPref value is for the test apps, and developers are required to actually manage or save items.
Click 'getProductDetail ' Button : Method for Checking IAP SDK V17 Purchase Information
The calling direction is from top to bottom and Unity will call Android.
This is a sequence where Android calls Unity through the connection listener. The string types of the result value received from the callback are as follows
onSuccess: a success response to the 'check purchase information' calling, json format. Developers are required to process the information, including the list of in-app products available for purchase and the in-app product type, by receiving data from the end IapResultListener. The sample simply shows the result in a pop-up.
onErrorRemoteException
onErrorSecurityException
onErrorNeedUpdateException
onError: if failed, an error code will be passed to the application. A code composed of numbers, and descriptions in the string form are passed in the form of ToString.
Purchase In-App Products
The calling direction is from top to bottom and Unity will call Android. When it comes to the inapp and auto products, only the in-app ID and in-app product type differs in IapUi.cs and the rest of the flow is the same. gameUserId and promotionApplicable is not frequently used in general, and therefore, if developers desire to use it by passing it to the default value ("" , false), they can put it by changing the value in the IapCallManager.
gameUserId - enter the unique identification number of a user who is using the application. This value is used as a key value to determine if it is available to participate in and to use promotions.
promotionApplicable - this delivers if it is available to participate in the promotion.
true : the user who is passed to the gameUserId is allowed to participate in a single promotion only once.
false : the user who is passed to the gameUserId cannot participate in the promotion.
In case of purchase, the Activity in the Plugin is called because the Activity of the service is required and the result value must be received. And the parameter value is saved in the intent and passed.
After calling mPurchaseClient.launchPurchaseFlow, receive the result value of the completed purchase through the onActivityResult. Verify if the intent data delivered when the purchase is completed in the mPurchaseClient.handlePurchaseData has been signed with the designated signature, and then pass the result value to the listener which was registered during the purchase.
This is a sequence where Android calls Unity through the connection listener. The string types of the result value received from the callback are as follows.
onSuccess - a success response to the 'request purchase'
onErrorRemoteException
onErrorSecurityException
onErrorNeedUpdateException
onError: if failed, an error code will be passed to the application. A code composed of numbers, and descriptions in the string form are passed in the form of ToString.
Consume In-App Products
The calling direction is from top to bottom and Unity will call Android. To perform the 'consume', the JSON data on the purchase in-app product that is saved through getPurchase or buyItem is required. And to import the JSON data, it is required to import the in-app ID as a key value by using the PlayerPrefs and deliver it to Android. Eventually, Android uses Json by converting it into the PurchaseData type.
This is a sequence where Android calls Unity through the connection listener. The string types of the result value received from the callback are as follows.
onSuccess: a success response to the 'consume' request.
onErrorRemoteException
onErrorSecurityException
onErrorNeedUpdateException
onError: if failed, an error code will be passed to the application. A code composed of numbers, and descriptions in the string form are passed in the form of ToString.
Change Subscription Status (Reservation of Cancellation / Cancellation of the Reservation of the Cancellation)
The calling direction is from top to bottom and Unity will call Android. When it come to the subscription(auto) which is the automatic payment in-app product, if recurringState is 0, that means the automatic payment has already made. You can send the 'cancel' command by sending the 'cancel' parameter which cancels the automatic payment. If recurringState is 1, that means the automatic payment has been cancelled. You can make the automatic payment again by sending the 'reactivate' parameter. In the IapUi.cs example, the 'cancel/reactivate' operation has been implemented as a sample to operate alternately on/off.
This is a sequence where Android calls Unity through the connection listener. The string types of the result value received from the callback are as follows.
onSuccess: a success response to the 'change the subscription status' calling
onErrorRemoteException
onErrorSecurityException
onErrorNeedUpdateException
onError: if failed, an error code will be passed to the application. A code composed of numbers, and descriptions in the string form are passed in the form of ToString.
Request ONE store Login
The calling direction is from top to bottom and Unity will call Android. The login check is performed by default before the payment is made. Use this button when login-related errors occur while each command is being executed.
After calling mPurchaseClient.launchLoginFlow, receive the result value of the completed purchase through the onActivityResult. Parse the intent data delivered when the login is completed in the mPurchaseClient.handleLoginData and then pass success or failure to the end listener.
This is a sequence where Android calls Unity through the connection listener. Only one Action event is configured since it consists only of success and error strings. The string types of the result value received from the callback are as follows.
onSuccess: a success response to the login success.
onErrorRemoteException
onErrorSecurityException
onErrorNeedUpdateException
onError: if failed, an error code will be passed to the application. A code composed of numbers, and descriptions in the string form are passed in the form of ToString.
Unbind Payment Operation
The calling direction is from top to bottom and Unity will call Android. Unbind the AIDL service binding.
ONE store Unity Plugin Package / Download Plugin
Move to the download page(Github)
UnityPackage (IapV17_UnityPluginSample.unityPackage)
plugin AAR
If Unity imports IapV17_UnityPluginSample.unityPackage, all related Assets will be automatically imported.

Unity Sample V17 Project & Sample APK
Last updated

