IAP Game Unity Developer Guide - ONE-store/inapp-sdk GitHub Wiki
< ์ฐธ๊ณ >
๋ณธ ๋ฌธ์๋ ์์คํ ์ด ์ธ์ฑ SDK v16(API v4)์ ๋ํ ๊ฐ์ด๋ ๋ฌธ์์ ๋๋ค. ์ต์ ์์คํ ์ด ์ธ์ฑ SDK v17(API v5)์ ๋ํ ๊ฐ์ด๋ ๋ฌธ์๋ ์์คํ ์ด ๊ฐ๋ฐ์์ผํฐ์์ ์ ๊ณต๋๊ณ ์์ต๋๋ค.
์ต์ ์ธ์ฑ SDK v17 ๊ฐ์ด๋ ๋ฌธ์ ๋งํฌ : https://dev.onestore.co.kr/devpoc/reference/view/IAP_v17
ํด๋น ๋ด์ฉ์ Unity3D ํ๊ฒฝ์ ์๋๋ก์ด๋ ์ฑ์์ IAP SDK ์ ์ฉ์ ๋๊ธฐ ์ํ ์ค๋ช ์์ด๋ค.
Unity ๊ด๋ จ ๊ธฐ๋ณธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(unity_adaptor)์ ํ ์คํธ์ฑ์ ๋ค์ด๋ก๋ ํ์ด์ง์์ ๋ฐ์ ์ ์๋ค.
Unity ๊ด๋ จ ๋ชจ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํ ์คํธ์ฑ์ ์์ค์ ํ๋ก์ ํธ๋ ํจ๊ป ์ ๊ณตํ๋ฉฐ, ํ์์ ๋ฐ๋ผ์ ๊ฐ๋ฐ์ฌ์์ ์์ ํ์ฌ ์ฌ์ฉํด์ผ ํ๋ค.
- unity_adaptor : Unity์ IAP๋ฅผ ์ ์ฉํ๊ธฐ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํ๋ก์ ํธ
- unity_sample : unity_adaptor๋ฅผ ์ ์ฉํ์ฌ ๊ตฌํํ Unity ์ดํ๋ฆฌ์ผ์ด์ ํ๋ก์ ํธ
์ธ์ฑ๊ฒฐ์ ๋ฅผ ์ํด ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(iap_plugin)๋ฅผ ๊ทธ๋๋ก ์ฌ์ฉํ๋ค. ์ด๋ฅผ Unity3D ๋ ์ด์ด์์ ์ฌ์ฉํ ์ ์๋๋ก, ์ถ๊ฐ๋ผ์ด๋ธ๋ฌ๋ฆฌ(unity_adaptor)๋ฅผ ๋ง๋ค์์ผ๋ฉฐ, ์ด๋ ์คํฌ๋ฆฝํธํ์ผ(IapSample.cs)์์ ์ง์ ์ฌ์ฉํ๋ค.
์ ๊ณตํ์ผ | ์ค๋ช | ๋น๊ณ |
---|---|---|
libs/iap_plugin_[๋ฒ์ ]_[๋น๋๋ ์ง].jar | IAP ๋ผ์ด๋ธ๋ฌ๋ฆฌ | |
libs/unity_adaptor_[๋ฒ์ ]_[๋น๋๋ ์ง].jar | Unity3D Adaptor ๋ผ์ด๋ธ๋ฌ๋ฆฌ | |
src/IapSample.cs | ์์ฒญ๊ณผ ์ฝ๋ฐฑ์ด ๊ตฌํ๋ ์์ ํ์ผ | |
src/AndroidManifest.xml | meta-data์ ๊ธฐ๋ณธ Activity๊ฐ ์ ์ธ๋ ํ์ผ | |
src/Response.cs | jsonํํ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ฑํ๋ ๊ฒฝ์ฐ ์ฌ์ฉ | |
src/Error.cs | jsonํํ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ฑํ๋ ๊ฒฝ์ฐ ์ฌ์ฉ | |
src/Response.cs | jsonํํ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ฑํ๋ ๊ฒฝ์ฐ ์ฌ์ฉ |
์๋์ ์ค๋ช ์ _unity_sample_ํ๋ก์ ํธ์ _IapSample.cs_๋ฅผ ๋ฐํ์ผ๋ก ํ๋ค.
AndroidManifest.xml๊ณผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ /Assets/Plugins/Android ์ ์์น์ํจ๋ค
//-----------------
// Initialize
//-----------------
unityPlayerClass = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject> ("currentActivity");
if (currentActivity != null) {
// RequestAdapter๋ฅผ ์ด๊ธฐํ
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (1) ์ฝ๋ฐฑ์ ๋ฐ์ ํด๋์ค ์ด๋ฆ
// (2) Activity Context
// (3) debug ์ฌ๋ถ
iapRequestAdapter = new AndroidJavaObject("com.onestore.iap.unity.RequestAdapter", "IapSample", currentActivity, false); //Release
//iapRequestAdapter = new AndroidJavaObject("com.onestore.iap.unity.RequestAdapter", "IapSample", currentActivity, true); //Debug
}
_iapRequestAdapter_๋ฅผ ์ด์ฉํ์ฌ ์์ฒญ์ ํ๋ฉฐ, ์ฝ๋ฐฑ์ ๊ณตํต์ผ๋ก ๋ฐ๋๋ค.
//------------------------------------------------
//
// Command - Request
//
//------------------------------------------------
public void RequestPurchaseHistory()
{
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (0) ๋ฉ์๋์ด๋ฆ : ๊ตฌ๋งค๋ด์ญ ์กฐํ
// ---------------------------------
// (1) ํ์์์๋ UI ๋
ธ์ถ
// (2) appId
// (3) productIds
// ----------------------------------
string[] productIds = {"0910024112"};
iapRequestAdapter.Call ("requestPurchaseHistory", false, "OA00679020", productIds);
//iapRequestAdapter.Call ("requestPurchaseHistory", true, "OA00679020", productIds); // UI๋
ธ์ถ ์์ด Background๋ก๋ง ์งํ
}
public void RequestProductInfo()
{
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (0) ๋ฉ์๋์ด๋ฆ : ์ํ์ ๋ณด ์กฐํ
// ---------------------------------
// (1) ํ์์์๋ UI ๋
ธ์ถ
// (2) appId
// ----------------------------------
iapRequestAdapter.Call ("requestProductInfo", false, "OA00679020");
//iapRequestAdapter.Call ("requestProductInfo", true, "OA00679020"); // UI๋
ธ์ถ ์์ด Background๋ก๋ง ์งํ
}
public void RequestCheckPurchasability()
{
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (0) ๋ฉ์๋์ด๋ฆ : ๊ตฌ๋งค๊ฐ๋ฅ์ฌ๋ถ ์กฐํ
// ---------------------------------
// (1) ํ์์์๋ UI ๋
ธ์ถ
// (2) appId
// (3) productIds
// ----------------------------------
string[] productIds = {"0910024112"};
iapRequestAdapter.Call ("requestCheckPurchasability", false, "OA00679020", productIds);
//iapRequestAdapter.Call ("requestCheckPurchasability", true, "OA00679020", productIds); // UI๋
ธ์ถ ์์ด Background๋ก๋ง ์งํ
}
public void RequestSubtractPoints()
{
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (0) ๋ฉ์๋์ด๋ฆ : ์ํ ์์ฑ๋ณ๊ฒฝ ์์ฒญ
// ---------------------------------
// (1) ํ์์์๋ UI ๋
ธ์ถ
// (2) action(์์ดํ
์ฐจ๊ฐ)
// (3) appId
// (4) productIds
// ----------------------------------
string[] productIds = {"0910024112"};
iapRequestAdapter.Call ("requestChangeProductProperties", false, "subtract_points", "OA00679020", productIds);
//iapRequestAdapter.Call ("requestChangeProductProperties", true, "subtract_points", "OA00679020", productIds); // UI๋
ธ์ถ ์์ด Background๋ก๋ง ์งํ
}
public void RequestCancelSubscription()
{
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (0) ๋ฉ์๋์ด๋ฆ : ์ํ ์์ฑ๋ณ๊ฒฝ ์์ฒญ
// ---------------------------------
// (1) ํ์์์๋ UI ๋
ธ์ถ
// (2) action(์๋๊ฒฐ์ ์ทจ์)
// (3) appId
// (4) productIds
// ----------------------------------
string[] productIds = {"0910042744"};
iapRequestAdapter.Call ("requestChangeProductProperties", false, "cancel_subscription", "OA00697454", productIds);
//iapRequestAdapter.Call ("requestChangeProductProperties", true, "cancel_subscription", "OA00697454", productIds); // UI๋
ธ์ถ ์์ด Background๋ก๋ง ์งํ
}
//------------------------------------------------
//
// Command - Callback
//
//------------------------------------------------
public void CommandResponse(string response)
{
Debug.Log ("[UNITY] CommandResponse >>> " + response);
// Parsing Json string to "Reponse" class
Response data = JsonUtility.FromJson<Response> (response);
}
public void CommandError(string message)
{
Debug.Log ("[UNITY] CommandError >>> " + message);
// Parsing Json string to "Error" class
Error data = JsonUtility.FromJson<Error> (message);
}
//------------------------------------------------
//
// Payment - Request
//
//------------------------------------------------
public void RequestPaymenet()
{
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (0) ๋ฉ์๋์ด๋ฆ : ๊ตฌ๋งค์์ฒญ
// ---------------------------------
// (1) appId
// (2) productId
// (3) proudtName
// (4) tId
// (5) bpInfo
// (6) gameuserId ํ๋ก๋ชจ์
์ค๋ณต ์ฐธ์ฌ ๋ฐฉ์ง ๊ธฐ๋ฅ (16.04 ์ถ๊ฐ)์ฌ์ฉ์ ์ฃผ์ ์ฒ๋ฆฌ๋ ๋ถ๋ถ ์ฌ์ฉ
// (7) promotionApplicable ํ๋ก๋ชจ์
์ค๋ณต ์ฐธ์ฌ ๋ฐฉ์ง ๊ธฐ๋ฅ (16.04 ์ถ๊ฐ)์ฌ์ฉ์ ์ฃผ์ ์ฒ๋ฆฌ๋ ๋ถ๋ถ ์ฌ์ฉ
// ----------------------------------
iapRequestAdapter.Call ("requestPayment", "OA00679020", "0910024112", "UNITY๊ฒฐ์ ", "TID_0123", "BPINFO_0123");
//iapRequestAdapter.Call ("requestPayment", "OA00679020", "0910024112", "UNITY๊ฒฐ์ ", "TID_0123" ,"BPINFO_0123", "", false);
}
//------------------------------------------------
//
// Payment - Callback
//
//------------------------------------------------
public void PaymentResponse(string response)
{
Debug.Log ("[UNITY] PaymentResponse >>> " + response);
// Parsing Json string to "Reponse" class
Response data = JsonUtility.FromJson<Response> (response);
// Try ReceiptVerification
iapRequestAdapter.Call ("verifyReceipt", "OA00679020", data.result.txid, data.result.receipt);
}
public void PaymentError(string message)
{
Debug.Log ("[UNITY] PaymentError >>> " + message);
// Parsing Json string to "Error" class
Error data = JsonUtility.FromJson<Error> (message);
}
//------------------------------------------------
//
// ์ ์์์์ฆ๊ฒ์ฆ - Request
//
//------------------------------------------------
public void VerifyReceipt()
{
// ---------------------------------
// ํจ์ parameter ์ ๋ฆฌ
// ---------------------------------
// (0) ๋ฉ์๋์ด๋ฆ : ๊ตฌ๋งค์์ฒญ
// ---------------------------------
// (1) appId
// (2) txId
// (3) signData
// ----------------------------------
iapRequestAdapter.Call ("verifyReceipt", appId, txId, signData);
}
//------------------------------------------------
//
// ์ ์์์์ฆ๊ฒ์ฆ - Callback
//
//------------------------------------------------
public void ReceiptVerificationResponse(string result)
{
Debug.Log ("[UNITY] ReceiptVerificationResponse >>> " + result);
// Parsing Json string to "VerifyReceipt" class
VerifyReceipt data = JsonUtility.FromJson<VerifyReceipt> (result);
}
public void ReceiptVerificationError(string message)
{
Debug.Log ("[UNITY] ReceiptVerificationError >>> " + message);
// Parsing Json string to "Error" class
Error data = JsonUtility.FromJson<Error> (message);
}
iapRequestAdapter.Call ("exit");
Unity๋ ์ด์ด๋ก ์ ๋ฌ๋๋ ๋ชจ๋ ๊ฒฐ๊ณผ๋ json ํํ์ string์ผ๋ก ์ ๋ฌ ๋๋ค.
๋ํ, ๊ฒฐ๊ณผ์ ํ์ฑ์ ๋๊ธฐ ์ํด, ํ์ฑ ๊ฒฐ๊ณผ๊ฐ ๋ ์ ์๋ ๋ฐ์ดํฐ ํด๋์ค๋ C#ํ์ผ๋ก ์ ๊ณตํ๋ค.
- Response.cs : ์์ฒญ(์ฟผ๋ฆฌ, ๊ฒฐ์ )๊ฒฐ๊ณผ๋ฅผ ํ์ฑํ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ๋ฐ์ดํฐ ํด๋์ค
- VerifyReceipt.cs : ์ ์์์์ฆ ๊ฒ์ฆ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ๋ฐ์ดํฐ ํด๋์ค
- Error.cs : ์๋ฌ์ ๋ํ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ๋ฐ์ดํฐ ํด๋์ค
unity_sample ์์ ํ์ฑํ๋ ๋ฐฉ๋ฒ์ Unity ๋ฒ์ 5์ด์์์ ์ ๊ณตํ๋ JsonUtility ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ค.
์ดํ ๋ฒ์ ์ ๊ฒฝ์ฐ, ๊ธฐ์กด์ ์ฌ์ฉํ๋ Json Parser ๋ฅผ ์ด์ฉํ์ฌ ํ์ฑ ํ ์ ์๋๋ก ํ๋ค.
์ฑ๊ณต ๊ฒฐ๊ณผ์ ๊ฒฝ์ฐ, ์ธ์ฑSDK๋ก๋ถํฐ ์ ๋ฌ๋๋ ๊ฒฐ๊ณผ์ ๋์ผํ๋ฉฐ, ์์ฒญ ๋ฐ ์๋ต ์์์ ํตํด ํ์ธ ๊ฐ๋ฅํ๋ค.
{
"api_version":"4",
"identifier":"1477984099815",
"method":"purchase",
"result":
{
"code":"0000",
"message":"์์ฒญ์ด ์ฑ๊ณตํ์ต๋๋ค.",
"count":1,
"txid":"TSTOREXXXX_..",
"receipt":"......."
}
}
์๋ฌ์ ๊ฒฝ์ฐ, ์๋์ ๊ฐ์ ํค๋ก ์ฌ์ฉํ๋ฉฐ, ์ ํ์ ์ผ๋ก ์ ๋ฌํ๋ค.
- requestId : ์์ฒญ์๋ณ์
- errorCode : ์์ฒญ์ ๋ํ ์๋ฌ์ฝ๋
- errorMessage : ์๋ฌ์ ๋ํ ๊ฒฐ๊ณผ ๋ฉ์์ง
๊ฒฝ์ฐ์ ๋ฐ๋ผ์, ์ ๋ฌ ๋์ง ์๋ ๊ฐ๋ ์์ผ๋ ์ฃผ์ํ๋ผ.
{
"requestId":"",
"errorCode":"-1001",
"errorMessage":"Service has not allowed."
}
๊ฐ๋ฐ์ฌ์ ํ๊ฒฝ์ ๋ฐ๋ผ, unity_adaptor ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์์ ํด์ผ ํ ํ์๊ฐ ์๋ค.
์ด ๊ฒฝ์ฐ, ํ๋ก์ ํธ๋ฅผ ์์ ํ์ฌ, unity_adaptor ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ง๋ค ์ ์๋ค.
โโโ build.gradle
โโโ gradle
โ โโโ wrapper
โ โโโ gradle-wrapper.jar
โโโ gradlew
โโโ gradlew.bat
โโโ library
โ โโโ build.gradle
โ โโโ libs
โ โ โโโ classes.jar
โ โ โโโ iap_plugin_[๋ฒ์ ]_[๋น๋๋ ์ง].jar
โ โโโ proguard-rules.pro
โ โโโ src
โ โโโ main
โ โโโ AndroidManifest.xml
โ โโโ java
โ โ โโโ com
โ โ โโโ onestore
โ โ โโโ iap
โ โ โโโ unity
โ โ โโโ AbsCallbackAdapter.java
โ โ โโโ MainActivity.java
โ โ โโโ MessageMaker.java
โ โ โโโ ReceiptVerificationCallbackAdapter.java
โ โ โโโ RequestAdapter.java
โ โ โโโ RequestCallbackAdapter.java
โ โโโ res
โ โโโ values
โ โโโ strings.xml
โโโ settings.gradle
ํ์ผ | ์ค๋ช | ๋น๊ณ |
---|---|---|
RequestCallbackAdapter.java | Unity๋ ์ด์ด๋ก ๋ถํฐ ์์ฒญ์ ๋ฐ๊ณ , ์ฝ๋ฐฑ ๋ฉ์๋ ์ ์ํ๋ค. |
ํ๋ก์ ํธ์์ ์๋ ๋ช ๋ น์ด๋ฅผ ํตํด, gradle ๋น๋๋ฅผ ์ํํ๋ค.
./gradlew buildUnityAdaptorJar
๊ฒฐ๊ณผ๋ฌผ์ ์๋ ๊ฒฝ๋ก์ ์๋ค.
unity_adaptor/library/build/outputs/aar/unity_adaptor_[๋ฒ์ ]_[๋น๋๋ ์ง].jar