MD5 校验值:3096fc569b12aa47ebd57f5bad3c8d5e
GooglePlayPurchasing.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.unity.purchasing.googleplay; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Handler; import android.os.RemoteException; import android.util.Base64; import android.util.Log; import com.android.vending.billing.IInAppBillingService; import com.google.vr.ndk.base.DaydreamApi; import com.unity.purchasing.common.IStoreCallback; import com.unity.purchasing.common.IUnityCallback; import com.unity.purchasing.common.InitializationFailureReason; import com.unity.purchasing.common.ProductDefinition; import com.unity.purchasing.common.ProductDescription; import com.unity.purchasing.common.ProductMetadata; import com.unity.purchasing.common.ProductType; import com.unity.purchasing.common.PurchaseFailureDescription; import com.unity.purchasing.common.PurchaseFailureReason; import com.unity.purchasing.common.StoreDeserializer; import com.unity.purchasing.common.UnityPurchasing; import com.unity.purchasing.googleplay.IabHelper; import com.unity3d.ads.metadata.InAppPurchaseMetaData; import com.unity3d.player.UnityPlayer; import com.unity3d.player.UnityPlayerActivity; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; public class GooglePlayPurchasing extends StoreDeserializer { public static final int ACTIVITY_REQUEST_CODE = 999; protected static final String TAG = "UnityIAP"; private static GooglePlayPurchasing instance; private static final boolean isDaydreamApiAvailable; public boolean activityPending; private Context context; public IabHelper helper; private Inventory inventory; private boolean isUnityVrEnabled; private IActivityLauncher launcher; private IBillingServiceManager manager; public String productJSON; private ProductDefinition productUnderPurchase; private IStoreCallback unityPurchasing; private HashSet<String> suspectFailedConsumableSkus = new HashSet<>(); Features features = new Features(); public IabHelper.OnIabPurchaseFinishedListener PurchaseListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult iabResult, Purchase purchase) { if (!GooglePlayPurchasing.this.purchaseInProgress) { return; } GooglePlayPurchasing.log("onIabPurchaseFinished: %s", Boolean.toString(iabResult.isSuccess())); GooglePlayPurchasing.log(iabResult.mMessage); GooglePlayPurchasing.this.purchaseInProgress = false; if (iabResult.isSuccess()) { GooglePlayPurchasing.log("Product purchased successfully!"); GooglePlayPurchasing.this.NotifyUnityOfPurchase(purchase); return; } int response = iabResult.getResponse(); GooglePlayPurchasing.log("Purchase response code:%s", Integer.toString(response)); PurchaseFailureReason purchaseFailureReason = PurchaseFailureReason.Unknown; GooglePlayPurchasing.this.suspectFailedConsumableSkus.add(GooglePlayPurchasing.this.productUnderPurchase.storeSpecificId); if (response != -1005) { if (response != 7) { switch (response) { case 2: case 3: purchaseFailureReason = PurchaseFailureReason.BillingUnavailable; break; case 4: purchaseFailureReason = PurchaseFailureReason.ItemUnavailable; break; } } else if (GooglePlayPurchasing.this.features.supportsPurchaseFailureReasonDuplicateTransaction) { purchaseFailureReason = PurchaseFailureReason.DuplicateTransaction; } PurchaseFailureDescription purchaseFailureDescription = new PurchaseFailureDescription(GooglePlayPurchasing.this.productUnderPurchase.storeSpecificId, purchaseFailureReason, "GOOGLEPLAY_" + iabResult.mMessage, IabHelper.billingResponseCodeNames.get(Integer.valueOf(response))); if (iabResult.getResponse() != -1002) { GooglePlayPurchasing.log("Received bad response, polling for successful purchases to investigate failure more deeply"); GooglePlayPurchasing.this.reconcileFailedPurchaseWithInventory(purchaseFailureDescription); return; } else { GooglePlayPurchasing.this.unityPurchasing.OnPurchaseFailed(purchaseFailureDescription); return; } } purchaseFailureReason = PurchaseFailureReason.UserCancelled; PurchaseFailureDescription purchaseFailureDescription2 = new PurchaseFailureDescription(GooglePlayPurchasing.this.productUnderPurchase.storeSpecificId, purchaseFailureReason, "GOOGLEPLAY_" + iabResult.mMessage, IabHelper.billingResponseCodeNames.get(Integer.valueOf(response))); if (iabResult.getResponse() != -1002) { } } }; private BroadcastReceiver purchasesUpdatedReceiver = null; private int offlineBackOffTime = 5000; private volatile boolean purchaseInProgress = false; private volatile boolean subscriptionUpdateInProgress = false; static { boolean z; try { Class.forName("com.google.vr.ndk.base.DaydreamApi"); z = true; } catch (Throwable unused) { z = false; } isDaydreamApiAvailable = z; } class Features { public boolean supportsPurchaseFailureReasonDuplicateTransaction; Features() { } } public static GooglePlayPurchasing instance(IUnityCallback iUnityCallback) { if (instance == null) { BillingServiceManager billingServiceManager = new BillingServiceManager(UnityPlayer.currentActivity); instance = new GooglePlayPurchasing(new UnityPurchasing(iUnityCallback), new IabHelper(UnityPlayer.currentActivity, billingServiceManager, new ActivityLauncher()), billingServiceManager, UnityPlayer.currentActivity, new ActivityLauncher()); } return instance; } public static boolean ContinuePurchase(Activity activity, String str, String str2) { if (instance == null) { return false; } instance.StartPurchase(activity, str, str2); return true; } public static boolean ContinueSubscriptionUpdate(Activity activity, String str, String str2) { if (instance == null) { return false; } instance.StartSubscriptionUpdate(activity, str, str2); return true; } public static void ProcessActivityResult(int i, int i2, Intent intent) { if (instance != null) { instance.onActivityResult(i, i2, intent); } } public GooglePlayPurchasing(IStoreCallback iStoreCallback, IabHelper iabHelper, IBillingServiceManager iBillingServiceManager, Context context, IActivityLauncher iActivityLauncher) { this.unityPurchasing = iStoreCallback; this.helper = iabHelper; this.helper.enableDaydreamApi(isDaydreamApiAvailable); this.manager = iBillingServiceManager; this.context = context; this.launcher = iActivityLauncher; instance = this; registerPurchasesUpdatedReceiver(); } public void SetUnityVrEnabled(boolean z) { this.isUnityVrEnabled = z; log("isUnityVrEnabled = %s", String.valueOf(this.isUnityVrEnabled)); } public void RestoreTransactions(final IGooglePlayStoreCallback iGooglePlayStoreCallback) { this.helper.queryInventoryAsync(true, new ArrayList(), new IabHelper.QueryInventoryFinishedListener() { @Override public void onQueryInventoryFinished(IabResult iabResult, Inventory inventory) throws Exception { GooglePlayPurchasing.log("RestoreInventoryFinished: %s", Boolean.toString(iabResult.isSuccess())); GooglePlayPurchasing.log(iabResult.mMessage); if (!iabResult.isFailure()) { GooglePlayPurchasing.this.inventory = inventory; GooglePlayPurchasing.this.NotifyUnityOfProducts(inventory); iGooglePlayStoreCallback.OnTransactionsRestored(true); } else { GooglePlayPurchasing.log("Failed to Restore inventory. UnityIAP will automatically retry in " + GooglePlayPurchasing.this.offlineBackOffTime + "ms"); iGooglePlayStoreCallback.OnTransactionsRestored(false); } } }, 0L); } public void UpgradeDowngradeSubscription(String str, String str2) { if (this.subscriptionUpdateInProgress) { log("Subscription update is in progress"); return; } if (!this.helper.subscriptionUpgradeDowngradeSupported()) { log("UpgradeDowngradeSubscription is not supported, this service needs v5 and higher android in app billing api"); return; } if (str == null || str.length() == 0 || str2 == null || str2.length() == 0) { log("Cannot update subscription. Subscription product identifiers(SKUs) must not be empty"); return; } boolean z = (this.context instanceof UnityPlayerActivity) && this.isUnityVrEnabled && isDaydreamApiAvailable; final Intent createPurchaseIntent = createPurchaseIntent(z); createPurchaseIntent.putExtra("oldSkuMetadata", str); createPurchaseIntent.putExtra("newSku", str2); createPurchaseIntent.putExtra("type", "subscription_update"); this.subscriptionUpdateInProgress = true; this.purchaseInProgress = true; this.activityPending = true; if (z) { new Handler(this.context.getMainLooper()).post(new Runnable() { @Override public void run() { createPurchaseIntent.putExtra("vr", true); DaydreamApi create = DaydreamApi.create(GooglePlayPurchasing.this.context); create.launchInVr(createPurchaseIntent); create.close(); } }); } else { this.launcher.startActivity(this.context, createPurchaseIntent); } } public void StartSubscriptionUpdate(Activity activity, String str, String str2) { String str3; JSONObject jSONObject; try { jSONObject = new JSONObject(str); } catch (JSONException e) { e.printStackTrace(); } if (jSONObject.has(InAppPurchaseMetaData.KEY_PRODUCT_ID)) { str3 = jSONObject.getString(InAppPurchaseMetaData.KEY_PRODUCT_ID); if (str3 != null) { log("Error: the product that is going to be updated does not have a valid product id"); return; } if (!this.inventory.hasDetails(str3)) { log("Error: the product that is going to be updated is not in the current inventory"); return; } if (!this.inventory.hasPurchase(str3)) { log("Error: the product that is going to be updated has not been purchased yet."); return; } if (!this.inventory.hasDetails(str2)) { log("Error: the product that is going to be updated to is not in the current inventory"); return; } this.productUnderPurchase = new ProductDefinition(str2, str2, ProductType.Subscription); ArrayList arrayList = new ArrayList(); arrayList.add(str3); this.helper.launchSubscriptionUpdateFlow(activity, str2, arrayList, ACTIVITY_REQUEST_CODE, this.PurchaseListener, addFreeTrialAndIntroPriceFlagToDeveloperPayload(null, str2, str)); return; } str3 = null; if (str3 != null) { } } public void StartPurchase(Activity activity, String str, String str2) { this.helper.enableUnityVr(this.isUnityVrEnabled); String addFreeTrialAndIntroPriceFlagToDeveloperPayload = addFreeTrialAndIntroPriceFlagToDeveloperPayload(str2, str, null); if (this.inventory.getSkuDetails(str).mItemType == "inapp") { this.helper.launchPurchaseFlow(activity, str, ACTIVITY_REQUEST_CODE, this.PurchaseListener, addFreeTrialAndIntroPriceFlagToDeveloperPayload); } else { this.helper.launchSubscriptionPurchaseFlow(activity, str, ACTIVITY_REQUEST_CODE, this.PurchaseListener, addFreeTrialAndIntroPriceFlagToDeveloperPayload); } } private String addFreeTrialAndIntroPriceFlagToDeveloperPayload(String str, String str2, String str3) { boolean z; boolean z2; String str4 = null; SkuDetails skuDetails = this.inventory.hasDetails(str2) ? this.inventory.getSkuDetails(str2) : null; JSONObject jSONObject = new JSONObject(); String str5 = new String(); if (str == null) { str = ""; } else { try { str5 = new JSONObject(str).getString("accountId"); } catch (JSONException unused) { } } boolean z3 = false; String encodeToString = Base64.encodeToString(str.getBytes(), 0); if (skuDetails == null) { try { jSONObject.put("developerPayload", encodeToString); jSONObject.put("is_free_trial", false); jSONObject.put("has_introductory_price_trial", false); jSONObject.put("is_updated", false); jSONObject.put("update_subscription_metadata", (Object) null); jSONObject.put("accountId", str5); } catch (JSONException unused2) { } return jSONObject.toString(); } if (str3 != null) { log("oldSkuMetadata is NOT null"); str4 = getUpdateMetadata(str3, skuDetails); z = true; } else { log("oldSkuMetadata is null"); z = false; } String type = skuDetails.getType(); String introductoryPricePeriod = skuDetails.getIntroductoryPricePeriod(); String freeTrialPeriod = skuDetails.getFreeTrialPeriod(); boolean hasPurchaseHistory = this.inventory.hasPurchaseHistory(str2); Iterator<String> it = this.inventory.getAllSkus("subs").iterator(); while (true) { if (!it.hasNext()) { z2 = false; break; } String next = it.next(); if (!this.inventory.getSkuDetails(next).getFreeTrialPeriod().isEmpty() && this.inventory.hasPurchaseHistory(next)) { z2 = true; break; } } boolean z4 = (type.equals("inapp") || freeTrialPeriod.isEmpty() || hasPurchaseHistory || z2) ? false : true; if (!type.equals("inapp") && !introductoryPricePeriod.isEmpty() && !hasPurchaseHistory) { z3 = true; } try { jSONObject.put("developerPayload", encodeToString); jSONObject.put("is_free_trial", z4); jSONObject.put("has_introductory_price_trial", z3); jSONObject.put("is_updated", z); jSONObject.put("update_subscription_metadata", str4); jSONObject.put("accountId", str5); } catch (JSONException unused3) { } return jSONObject.toString(); } private String getUpdateMetadata(String str, SkuDetails skuDetails) { String str2; boolean z; boolean z2; String str3; long j; long priceInMicros; String subscriptionPeriod; JSONObject jSONObject; long priceInMicros2 = skuDetails.getPriceInMicros(); try { jSONObject = new JSONObject(str); str3 = jSONObject.getString(InAppPurchaseMetaData.KEY_PRODUCT_ID); } catch (JSONException e) { e = e; str2 = null; } try { z = jSONObject.getBoolean("is_free_trial"); try { z2 = jSONObject.getBoolean("is_introductory_price_period"); try { j = (long) jSONObject.getDouble("remaining_time_in_seconds"); } catch (JSONException e2) { str2 = str3; e = e2; e.printStackTrace(); str3 = str2; j = 0; if (str3 != null) { } return null; } } catch (JSONException e3) { str2 = str3; e = e3; z2 = false; e.printStackTrace(); str3 = str2; j = 0; if (str3 != null) { } return null; } } catch (JSONException e4) { str2 = str3; e = e4; z = false; z2 = false; e.printStackTrace(); str3 = str2; j = 0; if (str3 != null) { } return null; } if (str3 != null || !this.inventory.hasDetails(str3)) { return null; } SkuDetails skuDetails2 = this.inventory.getSkuDetails(str3); if (z) { j = 0; } if (z2 && skuDetails.getPriceInMicros() != 0) { priceInMicros = skuDetails2.getIntroductoryPriceInMicros(); subscriptionPeriod = skuDetails2.getIntroductoryPricePeriod(); } else { priceInMicros = skuDetails2.getPriceInMicros(); subscriptionPeriod = skuDetails2.getSubscriptionPeriod(); } JSONObject jSONObject2 = new JSONObject(); try { jSONObject2.put("old_sku_remaining_seconds", j); jSONObject2.put("old_sku_price_in_micros", priceInMicros); jSONObject2.put("old_sku_period_string", subscriptionPeriod); jSONObject2.put("new_sku_price_in_micros", priceInMicros2); } catch (JSONException e5) { e5.printStackTrace(); } return jSONObject2.toString(); } public void pollForNewPurchases() { reconcileFailedPurchaseWithInventory(null); } public void reconcileFailedPurchaseWithInventory(final PurchaseFailureDescription purchaseFailureDescription) { this.manager.workWith(new BillingServiceProcessor() { @Override public void workWith(IInAppBillingService iInAppBillingService) { boolean z = false; try { boolean hasPurchase = purchaseFailureDescription != null ? GooglePlayPurchasing.this.inventory.hasPurchase(purchaseFailureDescription.productId) : false; if (GooglePlayPurchasing.this.helper.queryPurchases(GooglePlayPurchasing.this.inventory, "inapp", iInAppBillingService) != 0) { GooglePlayPurchasing.log("Received bad response from queryPurchases"); } boolean hasPurchase2 = purchaseFailureDescription != null ? GooglePlayPurchasing.this.inventory.hasPurchase(purchaseFailureDescription.productId) : false; if (purchaseFailureDescription != null) { if ((!hasPurchase && !hasPurchase2) || (hasPurchase && hasPurchase2)) { GooglePlayPurchasing.this.unityPurchasing.OnPurchaseFailed(purchaseFailureDescription); } else if (!hasPurchase && hasPurchase2) { Purchase purchase = GooglePlayPurchasing.this.inventory.getPurchase(purchaseFailureDescription.productId); GooglePlayPurchasing.this.unityPurchasing.OnPurchaseSucceeded(purchase.getSku(), GooglePlayPurchasing.this.encodeReceipt(purchase, GooglePlayPurchasing.this.inventory.getSkuDetails(purchaseFailureDescription.productId)), purchase.getOrderIdOrPurchaseToken()); } z = true; } if (z) { return; } GooglePlayPurchasing.this.NotifyUnityOfProducts(GooglePlayPurchasing.this.inventory); } catch (RemoteException | JSONException e) { Log.e(GooglePlayPurchasing.TAG, "exception", e); if (purchaseFailureDescription == null || z) { return; } GooglePlayPurchasing.this.unityPurchasing.OnPurchaseFailed(purchaseFailureDescription); } } }); } private void registerPurchasesUpdatedReceiver() { if (this.purchasesUpdatedReceiver == null) { this.purchasesUpdatedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { GooglePlayPurchasing.this.pollForNewPurchases(); } }; this.context.registerReceiver(this.purchasesUpdatedReceiver, new IntentFilter("com.android.vending.billing.PURCHASES_UPDATED")); } } public void QueryInventory(final List<String> list, long j) { log("QueryInventory: %s", Integer.toString(list.size())); this.helper.queryInventoryAsync(true, list, new IabHelper.QueryInventoryFinishedListener() { @Override public void onQueryInventoryFinished(IabResult iabResult, Inventory inventory) throws Exception { GooglePlayPurchasing.log("onQueryInventoryFinished: %s", Boolean.toString(iabResult.isSuccess())); GooglePlayPurchasing.log(iabResult.mMessage); if (!iabResult.isFailure()) { GooglePlayPurchasing.this.inventory = inventory; for (String str : list) { if (GooglePlayPurchasing.this.inventory.hasConsumablePurchaseHistory(str) && !GooglePlayPurchasing.this.inventory.hasPurchase(str)) { GooglePlayPurchasing.this.helper.consumeAsync(GooglePlayPurchasing.this.inventory.getHistoryPurchase(str), (IabHelper.OnConsumeFinishedListener) null, true); } } GooglePlayPurchasing.this.NotifyUnityOfProducts(inventory); return; } GooglePlayPurchasing.log("Failed to Query inventory. UnityIAP will automatically retry in " + GooglePlayPurchasing.this.offlineBackOffTime + "ms"); GooglePlayPurchasing.this.QueryInventory(list, (long) GooglePlayPurchasing.this.offlineBackOffTime); GooglePlayPurchasing.this.offlineBackOffTime = Math.min(300000, GooglePlayPurchasing.this.offlineBackOffTime * 2); } }, j); } public void NotifyUnityOfProducts(Inventory inventory) { String str; ArrayList arrayList = new ArrayList(); JSONObject jSONObject = new JSONObject(); for (Map.Entry<String, SkuDetails> entry : inventory.mSkuMap.entrySet()) { SkuDetails value = entry.getValue(); try { jSONObject.put(entry.getKey(), value.getOriginalJSON()); } catch (JSONException e) { e.printStackTrace(); } ProductMetadata productMetadata = new ProductMetadata(value.getPrice(), value.getTitle(), value.getDescription(), value.getISOCurrencyCode(), new BigDecimal(value.getPriceInMicros()).divide(new BigDecimal(1000000))); String key = entry.getKey(); String str2 = null; if (inventory.hasPurchase(key)) { Purchase purchase = inventory.getPurchase(key); str2 = encodeReceipt(purchase, inventory.getSkuDetails(key)); str = purchase.getOrderIdOrPurchaseToken(); } else { str = null; } arrayList.add(new ProductDescription(key, productMetadata, str2, str)); } this.productJSON = jSONObject.toString(); this.unityPurchasing.OnProductsRetrieved(arrayList); } protected void onActivityResult(int i, int i2, Intent intent) { if (this.helper != null) { log("onActivityResult"); this.helper.handleActivityResult(i, i2, intent); this.purchaseInProgress = false; this.subscriptionUpdateInProgress = false; } } private Purchase findPurchaseByOrderId(String str) { for (Purchase purchase : this.inventory.getAllPurchases()) { if (purchase.getOrderIdOrPurchaseToken().equals(str)) { return purchase; } } log("No consumable with order %s", str); return null; } public void NotifyUnityOfPurchase(Purchase purchase) { log("NotifyUnityOfPurchase"); this.inventory.addPurchase(purchase); SkuDetails skuDetails = this.inventory.getSkuDetails(purchase.getSku()); if (purchase.getItemType().equals("subs")) { this.inventory.addPurchaseToSubscriptionPurchaseHistory(purchase.getSku()); } this.unityPurchasing.OnPurchaseSucceeded(purchase.getSku(), encodeReceipt(purchase, skuDetails), purchase.getOrderIdOrPurchaseToken()); } public String encodeReceipt(Purchase purchase, SkuDetails skuDetails) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("json", purchase.getOriginalJson()); jSONObject.put(InAppPurchaseMetaData.KEY_SIGNATURE, purchase.getSignature()); jSONObject.put("skuDetails", skuDetails.getOriginalJSON()); jSONObject.put("isPurchaseHistorySupported", this.helper.subscriptionPurchaseHistorySupported()); } catch (JSONException e) { e.printStackTrace(); } return jSONObject.toString(); } public static void log(String str) { Log.i(TAG, str); } public static void log(String str, String str2) { log(String.format(str, str2)); } @Override public void RetrieveProducts(List<ProductDefinition> list) { final ArrayList arrayList = new ArrayList(); Iterator<ProductDefinition> it = list.iterator(); while (it.hasNext()) { arrayList.add(it.next().storeSpecificId); } IabHelper.OnIabSetupFinishedListener onIabSetupFinishedListener = new IabHelper.OnIabSetupFinishedListener() { @Override public void onIabSetupFinished(IabResult iabResult) { GooglePlayPurchasing.log("onIabSetupFinished: %s", Integer.toString(iabResult.mResponse)); if (iabResult.isFailure()) { GooglePlayPurchasing.log("Failed to setup IAB. Notifying Unity..."); GooglePlayPurchasing.this.unityPurchasing.OnSetupFailed(InitializationFailureReason.PurchasingUnavailable); } else { GooglePlayPurchasing.log("Requesting %s products", Integer.toString(arrayList.size())); GooglePlayPurchasing.this.QueryInventory(arrayList, 0L); } } }; if (!this.helper.mSetupDone) { try { this.manager.initialise(); this.helper.startSetup(onIabSetupFinishedListener); return; } catch (GooglePlayBillingUnAvailableException unused) { this.unityPurchasing.OnSetupFailed(InitializationFailureReason.PurchasingUnavailable); return; } } log("Requesting %s products", Integer.toString(arrayList.size())); QueryInventory(arrayList, 0L); } private void consumeSuspectFailedPurchase(final ProductDefinition productDefinition, final String str) { final String str2 = productDefinition.storeSpecificId; this.suspectFailedConsumableSkus.remove(str2); this.helper.queryInventoryAsync(false, this.inventory.getAllSkus("inapp"), new IabHelper.QueryInventoryFinishedListener() { @Override public void onQueryInventoryFinished(IabResult iabResult, Inventory inventory) throws Exception { if (!iabResult.isFailure()) { GooglePlayPurchasing.this.inventory = inventory; if (GooglePlayPurchasing.this.inventory.hasConsumablePurchaseHistory(str2)) { GooglePlayPurchasing.this.helper.consumeAsync(GooglePlayPurchasing.this.inventory.getHistoryPurchase(str2), new IabHelper.OnConsumeFinishedListener() { @Override public void onConsumeFinished(Purchase purchase, IabResult iabResult2) throws JSONException { GooglePlayPurchasing.this.Purchase(productDefinition, str); } }, true); return; } else { GooglePlayPurchasing.this.Purchase(productDefinition, str); return; } } GooglePlayPurchasing.log("Failed to Query inventory. UnityIAP will automatically retry in " + GooglePlayPurchasing.this.offlineBackOffTime + "ms"); GooglePlayPurchasing.this.QueryInventory(GooglePlayPurchasing.this.inventory.getAllSkus("inapp"), (long) GooglePlayPurchasing.this.offlineBackOffTime); GooglePlayPurchasing.this.offlineBackOffTime = Math.min(300000, GooglePlayPurchasing.this.offlineBackOffTime * 2); } }, 0L); } @Override public void Purchase(ProductDefinition productDefinition) { Purchase(productDefinition, (String) null); } @Override public void Purchase(ProductDefinition productDefinition, String str) { if (this.purchaseInProgress) { this.unityPurchasing.OnPurchaseFailed(new PurchaseFailureDescription(productDefinition.storeSpecificId, PurchaseFailureReason.ExistingPurchasePending)); return; } if (productDefinition.type == ProductType.Consumable && this.suspectFailedConsumableSkus.contains(productDefinition.storeSpecificId) && !this.inventory.hasPurchase(productDefinition.storeSpecificId)) { consumeSuspectFailedPurchase(productDefinition, str); return; } String str2 = productDefinition.storeSpecificId; this.productUnderPurchase = productDefinition; log("onPurchaseProduct: %s", str2); SkuDetails skuDetails = this.inventory.getSkuDetails(str2); log("ITEM TYPE:%s", skuDetails.getType()); boolean z = (this.context instanceof UnityPlayerActivity) && this.isUnityVrEnabled && isDaydreamApiAvailable; final Intent createPurchaseIntent = createPurchaseIntent(z); createPurchaseIntent.putExtra(InAppPurchaseMetaData.KEY_PRODUCT_ID, str2); createPurchaseIntent.putExtra("itemType", skuDetails.getType()); createPurchaseIntent.putExtra("developerPayload", str); this.purchaseInProgress = true; this.activityPending = true; if (z) { new Handler(this.context.getMainLooper()).post(new Runnable() { @Override public void run() { createPurchaseIntent.putExtra("vr", true); DaydreamApi create = DaydreamApi.create(GooglePlayPurchasing.this.context); create.launchInVr(createPurchaseIntent); create.close(); } }); } else { this.launcher.startActivity(this.context, createPurchaseIntent); } } protected Intent createPurchaseIntent(boolean z) { return new Intent(this.context, (Class<?>) (z ? VRPurchaseActivity.class : PurchaseActivity.class)); } @Override public void FinishTransaction(ProductDefinition productDefinition, String str) { Purchase findPurchaseByOrderId; log("Finish transaction:%s", str); if (productDefinition == null) { log("Received FinishTransaction for unknown product with transaction %s. Not consuming.", str); } else { if (productDefinition.type != ProductType.Consumable || (findPurchaseByOrderId = findPurchaseByOrderId(str)) == null) { return; } log("Consuming %s", findPurchaseByOrderId.getSku()); this.inventory.erasePurchase(findPurchaseByOrderId.getSku()); this.helper.consumeAsync(findPurchaseByOrderId, new IabHelper.OnConsumeFinishedListener() { @Override public void onConsumeFinished(Purchase purchase, IabResult iabResult) throws JSONException { GooglePlayPurchasing.log("onConsumeFinished:%s", Boolean.toString(iabResult.isSuccess())); GooglePlayPurchasing.log(iabResult.mMessage); GooglePlayPurchasing.log(String.valueOf(iabResult.getResponse())); } }, false); } } public void FinishAdditionalTransaction(String str, String str2) { log("Finish transaction:%s", str2); Purchase findPurchaseByOrderId = findPurchaseByOrderId(str2); if (findPurchaseByOrderId != null) { log("Consuming %s", findPurchaseByOrderId.getSku()); this.inventory.erasePurchase(findPurchaseByOrderId.getSku()); this.helper.consumeAsync(findPurchaseByOrderId, new IabHelper.OnConsumeFinishedListener() { @Override public void onConsumeFinished(Purchase purchase, IabResult iabResult) throws JSONException { GooglePlayPurchasing.log("onConsumeFinished:%s", Boolean.toString(iabResult.isSuccess())); GooglePlayPurchasing.log(iabResult.mMessage); GooglePlayPurchasing.log(String.valueOf(iabResult.getResponse())); } }, false); } } public void SetFeatures(String str) { for (String str2 : str.split(",")) { if (str2.equals("supportsPurchaseFailureReasonDuplicateTransaction")) { this.features.supportsPurchaseFailureReasonDuplicateTransaction = true; } } } }