public void OnInitialized(IStoreController controller, IExtensionProvider extensions) { // Purchasing has succeeded initializing. Collect our Purchasing references. Debug.Log("OnInitialized: PASS"); // Overall Purchasing system, configured with products for this application. m_StoreController = controller; // Store specific subsystem, for accessing device-specific store features. m_StoreExtensionProvider = extensions; // Set play store extensions. _playStoreExtensions = m_StoreExtensionProvider.GetExtension <Google.Play.Billing.IGooglePlayStoreExtensions>(); CheckSubscriptionsAvailabilityBasedOnReceipt(controller); // Pass an obfuscated account id. _playStoreExtensions.SetObfuscatedAccountId(TrivialKartClientUtil.GetObfuscatedAccountId()); // Set the deferred purchases callback. _playStoreExtensions.SetDeferredPurchaseListener( delegate(Product product) { ProcessDeferredPurchase(product.definition.id); // Do not grant the item here. Instead, record the purchase and remind // the user to complete the transaction in the Play Store. }); }
// Check if the obfuscated account id on the receipt is same as the one on the device. private static void ObfuscatedAccountIdValidation(string unityIapReceipt) { Dictionary <string, object> unityIapReceiptDictionary = (Dictionary <string, object>)MiniJson.JsonDecode(unityIapReceipt); string payload = (string)unityIapReceiptDictionary["Payload"]; Dictionary <string, object> payLoadDictionary = (Dictionary <string, object>)MiniJson.JsonDecode(payload); string receipt = (string)payLoadDictionary["json"]; Dictionary <string, object> receiptDictionary = (Dictionary <string, object>)MiniJson.JsonDecode(receipt); if (!receiptDictionary.ContainsKey("obfuscatedAccountId") || !receiptDictionary["obfuscatedAccountId"].Equals(TrivialKartClientUtil.GetObfuscatedAccountId())) { Debug.Log("Obfuscated account id is invalid"); throw new IAPSecurityException(); } }