/** * docs in {@link * PurchaseObserver#onRestoreTransactionsResponse(com.soomla.billing.BillingService.RestoreTransactions, * com.soomla.billing.Consts.ResponseCode)}. */ @Override public void onRestoreTransactionsResponse( BillingService.RestoreTransactions request, Consts.ResponseCode responseCode) { if (responseCode == Consts.ResponseCode.RESULT_OK) { StoreUtils.LogDebug(TAG, "RestoreTransactions succeeded"); SharedPreferences prefs = new ObscuredSharedPreferences( SoomlaApp.getAppContext(), SoomlaApp.getAppContext() .getSharedPreferences(StoreConfig.PREFS_NAME, Context.MODE_PRIVATE)); SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean("RESTORED", true); edit.commit(); BusProvider.getInstance().post(new RestoreTransactionsEvent(true)); } else { StoreUtils.LogDebug(TAG, "RestoreTransactions error: " + responseCode); BusProvider.getInstance().post(new RestoreTransactionsEvent(false)); } // we're stopping the billing service only if the store was not opened while the request was // sent if (!mStoreOpen) { stopBillingService(); } }
/** Initiate the restoreTransactions process */ public void restoreTransactions() { if (!checkInit()) return; StoreUtils.LogDebug(TAG, "Sending restore transaction request"); mBillingService.restoreTransactions(); BusProvider.getInstance().post(new RestoreTransactionsStartedEvent()); }
/** Private methods * */ private boolean checkInit() { if (!mInitialized) { StoreUtils.LogDebug( TAG, "You can't perform any of StoreController's actions before it was initialized. Initialize it once when your game loads."); return false; } return true; }
/** docs in {@link PurchaseObserver#onBillingSupported(boolean supported, String type)}. */ @Override public void onBillingSupported(boolean supported, String type) { if (type == null || type.equals(Consts.ITEM_TYPE_INAPP)) { if (supported) { StoreUtils.LogDebug(TAG, "billing is supported !"); BusProvider.getInstance().post(new BillingSupportedEvent()); } else { // purchase is not supported. just send a message to JS to disable the "get more ..." // button. StoreUtils.LogDebug(TAG, "billing is not supported !"); BusProvider.getInstance().post(new BillingNotSupportedEvent()); } } else if (type.equals(Consts.ITEM_TYPE_SUBSCRIPTION)) { // subscription is not supported // Soomla doesn't support subscriptions yet. doing nothing here ... } else { // subscription is not supported // Soomla doesn't support subscriptions yet. doing nothing here ... } }
private boolean startBillingService() { mLock.lock(); if (mBillingService == null) { ResponseHandler.register(this); mBillingService = new BillingService(); mBillingService.setContext(SoomlaApp.getAppContext()); if (!mBillingService.checkBillingSupported(Consts.ITEM_TYPE_INAPP)) { StoreUtils.LogDebug(TAG, "There's no connectivity with the billing service."); mLock.unlock(); return false; } } mLock.unlock(); return true; }