unityでAndoroid向けに作っているゲームにadmobの広告を実装しているのですが、広告消去機能を購入したかどうか確認するためのレシート検証処理の作り方がunity公式のドキュメントを見てもよくわかりません。
課金機能にはUnity IAPのIAPButtonを使用しています。
また、レシート検証のためのサーバーは必須なのでしょうか?
今までサーバーを作ったことはないのでできればアプリ内で検証するようにしたいです。
参考にしているサイト
Purchase Receipts-Unity マニュアル
購入レシート-Unity マニュアル
わからない点
・必要な名前空間(UnityEngine.Purchasingでしょうか?)
・引数Eはクラス(構造体?)のように見えますがどのようにこの変数を取得(宣言?)するかわかりません。参考
・この例のスクリプトをどこに書けばいいのかわからないです。
public class スクリプト名 : MonoBehaviour{この中には書けない}
ので、どうすればいいのか困っています。
C#
1public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e) 2{ 3 bool validPurchase = true; // Presume valid for platforms with no R.V. 4 5 // Unity IAP's validation logic is only included on these platforms. 6#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX 7 // Prepare the validator with the secrets we prepared in the Editor 8 // obfuscation window. 9 var validator = new CrossPlatformValidator(GooglePlayTangle.Data(), 10 AppleTangle.Data(), Application.bundleIdentifier); 11 12 try { 13 // On Google Play, result will have a single product Id. 14 // On Apple stores receipts contain multiple products. 15 var result = validator.Validate(e.purchasedProduct.receipt); 16 // For informational purposes, we list the receipt(s) 17 Debug.Log("Receipt is valid. Contents:"); 18 foreach (IPurchaseReceipt productReceipt in result) { 19 Debug.Log(productReceipt.productID); 20 Debug.Log(productReceipt.purchaseDate); 21 Debug.Log(productReceipt.transactionID); 22 } 23 } catch (IAPSecurityException) { 24 Debug.Log("Invalid receipt, not unlocking content"); 25 validPurchase = false; 26 } 27#endif 28 29 if (validPurchase) { 30 // Unlock the appropriate content here. 31 } 32 33 return PurchaseProcessingResult.Complete; 34}
また、こちらはもどこの関数に入れればいいかわかりません。
C#
1var result = validator.Validate(e.purchasedProduct.receipt); 2Debug.Log("Receipt is valid. Contents:"); 3foreach (IPurchaseReceipt productReceipt in result) { 4 Debug.Log(productReceipt.productID); 5 Debug.Log(productReceipt.purchaseDate); 6 Debug.Log(productReceipt.transactionID); 7 8 GooglePlayReceipt google = productReceipt as GooglePlayReceipt; 9 if (null != google) { 10 Debug.Log(google.purchaseState); 11 Debug.Log(google.purchaseToken); 12 } 13 14 AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt; 15 if (null != apple) { 16 Debug.Log(apple.originalTransactionIdentifier); 17 Debug.Log(apple.cancellationDate); 18 Debug.Log(apple.quantity); 19 } 20}
あなたの回答
tips
プレビュー