PurchaseProcessingResult IStoreListener.ProcessPurchase(PurchaseEventArgs e)
{
try
{
bool isSuccess = true;
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
CrossPlatformValidator validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
try
{
IPurchaseReceipt[] result = validator.Validate(e.purchasedProduct.receipt);
foreach (var productReceipt in result)
{
Analytics.Transaction(productReceipt.productID, e.purchasedProduct.metadata.localizedPrice,
e.purchasedProduct.metadata.isoCurrencyCode, productReceipt.transactionID, null);
#if UNITY_ANDROID
GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
if(google != null)
{
if (google.purchaseState != GooglePurchaseState.Purchased)
isSuccess = false;
}
#endif
}
}
catch (IAPSecurityException)
{
isSuccess = false;
Debug.Log("영수증 검증 실패");
}
#endif
if (isSuccess)
{
//구매성공했으니 사운드
Debug.Log("구매 성공! 영수증 검증 성공!");
SoundManager.Instance.PlayAudio("RewardReceived");
string productId = e.purchasedProduct.definition.id;
string receipt = null;
string signature = null;
#if UNITY_ANDROID
GetReceiptSignature(e.purchasedProduct.receipt, out receipt, out signature);
#elif UNITY_IOS
receipt = e.purchasedProduct.receipt;
#endif
string currency = e.purchasedProduct.metadata.isoCurrencyCode;
double price = decimal.ToDouble(e.purchasedProduct.metadata.localizedPrice);
//현재 구매한 가격을 유저 과금 변수에 추가함
//추후 할인 고려하여 구조 확장 필요
GameDataTable.Instance.User.TotalPurchase += cellData.DiscountedPrice;
Debug.LogFormat("ProcessPurchase id : {0}, receipt : {1}, signature : {2}, currency : {3}, price : {4}", productId, receipt, signature, currency, price);
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
#if UNITY_ANDROID
BackEnd.Backend.TBC.ChargeTBC(e.purchasedProduct.receipt,
$"ProcessPurchase id: {productId}, receipt: {receipt}, signature: {signature}, currency: {currency}, price: {price}", callback =>
{
if (callback.IsSuccess())
{
//StartCoroutine(GetTBC());
Invoke("GetTBC", 0.1f);
OnPurchaseSuccess(productId);
}
else
{
Debug.Log("productId : " + productId + "receipt :" + receipt + "signature :" + signature + "currency:" + currency + "price:"+ price);
Debug.Log($"ChargeTBC Fail : {callback.GetErrorCode()}, {callback.GetMessage()}");
if (callback.GetStatusCode() == "404")
OnPurchaseSuccess(productId);
}
});
#elif UNITY_IOS
BackEnd.Backend.TBC.ChargeTBC(productId, e.purchasedProduct.receipt,
$"ProcessPurchase id: {productId}, receipt: {receipt}, signature: {signature}, currency: {currency}, price: {price}", callback =>
{
if (callback.IsSuccess())
{
//StartCoroutine(GetTBC());
Invoke("GetTBC", 0.1f);
OnPurchaseSuccess(productId);
}
else
{
Debug.Log($"ChargeTBC Fail : {callback.GetErrorCode()}, {callback.GetMessage()}");
if(callback.GetStatusCode() == "404")
OnPurchaseSuccess(productId);
}
});
#endif
#else
if (!BackendManager.Instance.IsLocal)
{
//마일리지
Backend.TBC.ChargeTBC(e.purchasedProduct.receipt,
$"ProcessPurchase id: {productId}, receipt: {receipt}, signature: {signature}, currency: {currency}, price: {price}", callback =>
{
if (callback.IsSuccess())
//StartCoroutine(GetTBC());
Invoke("GetTBC", 0.1f);
});
}
OnPurchaseSuccess(productId);
#endif
}
}
catch (Exception error)
{
Debug.LogError(error);
return PurchaseProcessingResult.Pending;
}
return PurchaseProcessingResult.Complete;
}
구매 영수증 확인하는 코드를 이렇게짰는데 영수증 토큰을 재대로 할려면 어떻게해야하나요?