'unity in app billing'에 해당되는 글 1건

  1. 2015.01.29 prime31 In App Billing plugin 설명 (6)
Game/Unity2015.01.29 12:20

사용법이 쉬운줄 알았는데 설명이나 문서가 없어서 씅질나서 ㅡㅡ

sku랑 init에 넣는 string이 뭔지 한참을 찾았다.


IABUIManager.cs

using UnityEngine;
using System.Collections.Generic;
using Prime31;
 
 
// prime 31 안드로이드 테스트 앱
// 결제 테스트까지 목표를 한다
 
// 참고 자료
// @see https://www.google.co.kr/search?q=prime31+site:http://www.devkorea.co.kr
// @see http://www.androidpub.com/2411952
// @see http://www.devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=26035
 
public class IABUIManager : MonoBehaviourGUI
{
#if UNITY_ANDROID
	void OnGUI()
	{
		beginColumn();
 
		ifGUILayout.Button( "Initialize IAB" ) )
		{
            // 결제를 하기 위한 공개키를 넣는다.
            // note. 해킹때문에 공개키를 넣지 말라는 이야기를 봤다.
            
            // 위치
            // https://play.google.com/apps/publish/
            // 해당 어플리케이션
            // 서비스 및 API
            // 이 애플리케이션용 라이선스 키
            var key = "base64encode";
			GoogleIAB.init( key );
		}
		
		
		ifGUILayout.Button( "Query Inventory" ) )
		{
			// enter all the available skus from the Play Developer Console in this array so that item information can be fetched for them
            // sku가 뭔가 했더니 빌링 정보더라
            // 인앱 목록을 등록하더라도 바로 테스트는 불가능하고 2시간 가량 지나야 가능함.
 
            // 타입 설명
            // 관리 되는 상품 - 1번만 구매 가능
            // 관리되지 않는 상품 - 반복 구매 가능. 다만 구글에서 저장 안해줘서 서버에 저장해야함.
            // 구독 - 매년/매월 비용 청구. 쓸 일 없음.
 
            // 주의
            // 한번 발급한 sku는 변경 불가. 삭제하더라도 그 이름은 다시 못씀
            // https://support.google.com/googleplay/android-developer/answer/1072599?hl=ko
 
            // 위치
            // https://play.google.com/apps/publish/
            // 해당 어플리케이션
            // 인앱 상품
            // 상품들의 ID
			var skus = new string[] {
                "com.deb.iaptestest.managed.money0001",
                "com.deb.iaptestest.purchased.money0001",
                "android.test.purchased"        // 이건 인앱 테스트용 @see http://www.devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=23967&sca=&sfl=wr_subject%7C%7Cwr_content&stx=consumeProduct&sop=and&currentId=76
            };
 
			GoogleIAB.queryInventory( skus );
		}
 
 
        // 구입 시키게 함
		ifGUILayout.Button( "Test Purchase with Test Product" ) )
		{
            GoogleIAB.purchaseProduct("android.test.purchased");
		}
		
		// 구입 한 제품을 소비 시키게 함
 
        // purchaseProduct 는 구매 요청이구요 
        // consumeProduct 는 구매한걸 소비요청하는 겁니다. 
        // 인앱 결제에서 관리되는 제품이랑 소모되는 소모성 제품이 있는데, 소모성 제품은 구매 후 소비 요청을 해야합니다. 
        // (소비 요청을 하지 않으면 해당 항목을 다시는 사지 못합니다 ) 
        
        // @see http://www.devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=26374&sca=&sfl=wr_subject%7C%7Cwr_content&stx=consumeProduct&sop=and&currentId=76
 
		ifGUILayout.Button( "Consume Test Purchase" ) )
		{
            GoogleIAB.consumeProduct("android.test.purchased");
		}
	
 
        // sku에 없는 제품을 구입 시도할 경우
 
		ifGUILayout.Button( "Test Unavailable Item" ) )
		{
			GoogleIAB.purchaseProduct( "android.test.item_unavailable" );
		}
 
		
		endColumn( true );
 
        // 구입을 하면서 파라메터도 돌려준다. 아직 쓰진 않음
		ifGUILayout.Button( "Purchase Real Product" ) )
		{
            GoogleIAB.purchaseProduct("com.deb.iaptestest.purchased.money0001""payload that gets stored and returned");
            //GoogleIAB.purchaseProduct("com.deb.iaptestest.purchased.money0001");
		}
		
		
        // 구입을 했으면 소모를 시켜야 한다.
        // 소모가 되지 않으면 재 구입 불가.
		ifGUILayout.Button( "Consume Real Purchase" ) )
		{
            GoogleIAB.consumeProduct("com.deb.iaptestest.purchased.money0001");
		}
 
		// 쓴 일이 없음.
		ifGUILayout.Button( "Enable High Details Logs" ) )
		{
			GoogleIAB.enableLogging( true );
		}
 
 
        // 여러개를 소모시킨다.
        if (GUILayout.Button("Consume Multiple Purchases"))
        {
            var skus = new string[] { "com.prime31.testproduct""android.test.purchased" };
            GoogleIAB.consumeProducts(skus);
        }
		
		endColumn();
	}
#endif
}




GoogleIABEventListener.cs

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
 
 
public class GoogleIABEventListener : MonoBehaviour
{
#if UNITY_ANDROID
	void OnEnable()
	{
		// Listen to all events for illustration purposes
		GoogleIABManager.billingSupportedEvent += billingSupportedEvent;
		GoogleIABManager.billingNotSupportedEvent += billingNotSupportedEvent;
		GoogleIABManager.queryInventorySucceededEvent += queryInventorySucceededEvent;
		GoogleIABManager.queryInventoryFailedEvent += queryInventoryFailedEvent;
		GoogleIABManager.purchaseCompleteAwaitingVerificationEvent += purchaseCompleteAwaitingVerificationEvent;
		GoogleIABManager.purchaseSucceededEvent += purchaseSucceededEvent;
		GoogleIABManager.purchaseFailedEvent += purchaseFailedEvent;
		GoogleIABManager.consumePurchaseSucceededEvent += consumePurchaseSucceededEvent;
		GoogleIABManager.consumePurchaseFailedEvent += consumePurchaseFailedEvent;
	}
 
 
	void OnDisable()
	{
		// Remove all event handlers
		GoogleIABManager.billingSupportedEvent -= billingSupportedEvent;
		GoogleIABManager.billingNotSupportedEvent -= billingNotSupportedEvent;
		GoogleIABManager.queryInventorySucceededEvent -= queryInventorySucceededEvent;
		GoogleIABManager.queryInventoryFailedEvent -= queryInventoryFailedEvent;
		GoogleIABManager.purchaseCompleteAwaitingVerificationEvent += purchaseCompleteAwaitingVerificationEvent;
		GoogleIABManager.purchaseSucceededEvent -= purchaseSucceededEvent;
		GoogleIABManager.purchaseFailedEvent -= purchaseFailedEvent;
		GoogleIABManager.consumePurchaseSucceededEvent -= consumePurchaseSucceededEvent;
		GoogleIABManager.consumePurchaseFailedEvent -= consumePurchaseFailedEvent;
	}
 
 
 
    /// <summary>
    /// 구매 가능한 앱 버전일 경우 발생하는 이벤트
    /// </summary>
	void billingSupportedEvent()
	{
		Debug.Log( "billingSupportedEvent" );
        guiText.text = "billingSupportedEvent";
	}
 
    /// <summary>
    /// 구매 불가능할 경우 발생하는 이벤트
    /// </summary>
    /// <param name="error"></param>
	void billingNotSupportedEvent( string error )
	{
		Debug.Log( "billingNotSupportedEvent: " + error );
        guiText.text = "billingNotSupportedEvent: " + error;
	}
 
    /// <summary>
    /// 구입자의 계정에 소모되지 않은 sku가 있는지
    /// </summary>
    /// <param name="purchases"></param>
    /// <param name="skus"></param>
	void queryInventorySucceededEvent( List<GooglePurchase> purchases, List<GoogleSkuInfo> skus )
	{
		Debug.Log( "queryInventorySucceededEvent" );
		Prime31.Utils.logObject( purchases );
		Prime31.Utils.logObject( skus );
 
        guiText.text = "queryInventorySucceededEvent"+"\n" +
            Convert.ToString(purchases) + "\n" +
            Convert.ToString(skus);
	}
 
 
    /// <summary>
    /// 인벤토리 목록 요청 실패
    /// </summary>
    /// <param name="error"></param>
	void queryInventoryFailedEvent( string error )
	{
		Debug.Log( "queryInventoryFailedEvent: " + error );
        guiText.text = "queryInventoryFailedEvent: " + error;
	}
 
 
    /// <summary>
    /// 구입 성공 후 인증 대기중
    /// </summary>
    /// <param name="purchaseData"></param>
    /// <param name="signature"></param>
	void purchaseCompleteAwaitingVerificationEvent( string purchaseData, string signature )
	{
		Debug.Log( "purchaseCompleteAwaitingVerificationEvent. purchaseData: " + purchaseData + ", signature: " + signature );
        guiText.text = "purchaseCompleteAwaitingVerificationEvent. "+
        "\n purchaseData: " + purchaseData + 
        "\n ,signature: " + signature;
	}
	
 
    /// <summary>
    /// 구입 성공 완료
    /// </summary>
    /// <param name="purchase"></param>
	void purchaseSucceededEvent( GooglePurchase purchase )
	{
		Debug.Log( "purchaseSucceededEvent: " + purchase );
        guiText.text = "purchaseSucceededEvent";
	}
 
    /// <summary>
    /// 구입 실패
    /// </summary>
    /// <param name="error"></param>
	void purchaseFailedEvent( string error )
	{
		Debug.Log( "purchaseFailedEvent: " + error );
        guiText.text = "purchaseFailedEvent";
	}
 
    /// <summary>
    /// 소모 성공 완료
    /// </summary>
    /// <param name="purchase"></param>
	void consumePurchaseSucceededEvent( GooglePurchase purchase )
	{
		Debug.Log( "consumePurchaseSucceededEvent: " + purchase );
        guiText.text = "consumePurchaseSucceededEvent";
	}
 
    /// <summary>
    /// 소모 실패
    /// </summary>
    /// <param name="error"></param>
	void consumePurchaseFailedEvent( string error )
	{
		Debug.Log( "consumePurchaseFailedEvent: " + error );
        guiText.text = "consumePurchaseFailedEvent";
	}
 
 
#endif
}
 
 

출처 : http://180bpm.tistory.com/82


저작자 표시
신고
Posted by Namseungil