안녕하세요.
유니티 코드리스IAP를 이용해 결제시스템까지 구축하였습니다.
결제가 진행된 다음, 하기와 같은 코드를 통해 게임내 재화를 지급하도록 작성하였습니다.
문제는 영수증 검증을 위해 뒤끝서버의 영수증 검증 관련한 공부를 하고 있는데…
많이 어렵습니다…
제가 작성하여 이용중인 코드와, 뒤끝서버에서 제공하는 예제를 어떻게 연결해야할지 도움 요청드립니다.
-----------------------------------질무자 작성 코드------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Purchasing;
using UnityEngine.UI;
public class IAP_Manager : MonoBehaviour
{
private string starter = "com.99level.undead_party.starter";
public GameObject fail_Text;
public GameObject item_Save;
public GameObject hero_Save;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnPurcahseComplete (Product product)
{
if(product.definition.id == starter)
{
Hero_Script.gold_Hero+=500000;
Hero_Script.sp_Party+=30;
GameManager.reward_Golem1+=30;
GameManager.reward_Golem2=15;
Hero_Script.matterial_Inventory[0]+=3000;
Hero_Script.matterial_Inventory[1]+=1500;
}
}
public void OnPurchaseFailed (Product product, PurchaseFailureReason failureReason)
{
fail_Text.SetActive(true);
}
-----------------------------------------뒤끝서버 예제----------------------------------------------
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
/*
뒤끝 영수증 검증 처리
*/
BackendReturnObject validation = Backend.Receipt.IsValidateGooglePurchase ( args.purchasedProduct.receipt , "receiptDescription", false);
// 영수증 검증에 성공한 경우
if(validation.IsSuccess())
{
// 구매 성공한 제품에 대한 id 체크하여 그에 맞는 보상
// A consumable product has been purchased by this user.
if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
// The consumable item has been successfully purchased, add 100 coins to the player's in-game score.
ScoreManager.score += 100;
}
// Or ... a non-consumable product has been purchased by this user.
else if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
// TODO: The non-consumable item has been successfully purchased, grant this item to the player.
}
// Or ... a subscription product has been purchased by this user.
else if (String.Equals(args.purchasedProduct.definition.id, kProductIDSubscription, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
// TODO: The subscription item has been successfully purchased, grant this to the player.
}
}
// 영수증 검증에 실패한 경우
else
{
// Or ... an unknown product has been purchased by this user. Fill in additional products here....
Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
}
// Return a flag indicating whether this product has completely been received, or if the application needs
// to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
// saving purchased products to the cloud, and when that save is delayed.
return PurchaseProcessingResult.Complete;
}