com.android.billingclient.api.BillingResult Java Examples

The following examples show how to use com.android.billingclient.api.BillingResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccelerateDevelop.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
public void initBilling() {
    mBillingClient = BillingClient.newBuilder(activity)
            .enablePendingPurchases()
            .setListener(new PurchasesUpdatedListener() {
                @Override
                public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> purchasesList) {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchasesList != null) {
                        Log.i(LOG_TAG, "Purchases are updated");
                        handlePurchases(purchasesList);
                    }
                }
            }).build();

    CachedExecutor.INSTANCE.getExecutorService().submit(() -> {
        mBillingClient.startConnection(AccelerateDevelop.this);
    });
}
 
Example #2
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
private void onPurchase(Intent intent) {
    if (Helper.isPlayStoreInstall()) {
        BillingFlowParams.Builder flowParams = BillingFlowParams.newBuilder();
        if (skuDetails.containsKey(getSkuPro())) {
            Log.i("IAB purchase SKU=" + skuDetails.get(getSkuPro()));
            flowParams.setSkuDetails(skuDetails.get(getSkuPro()));
        }

        BillingResult result = billingClient.launchBillingFlow(this, flowParams.build());
        if (result.getResponseCode() != BillingClient.BillingResponseCode.OK)
            reportError(result, "IAB launch billing flow");
    } else
        try {
            Uri uri = Uri.parse(BuildConfig.PRO_FEATURES_URI + "?challenge=" + getChallenge(this));
            Helper.view(this, uri, true);
        } catch (NoSuchAlgorithmException ex) {
            Log.unexpectedError(getSupportFragmentManager(), ex);
        }
}
 
Example #3
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
private void onPurchaseCheck(Intent intent) {
    billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
        @Override
        public void onPurchaseHistoryResponse(BillingResult result, List<PurchaseHistoryRecord> records) {
            if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                for (PurchaseHistoryRecord record : records)
                    Log.i("IAB history=" + record.toString());

                queryPurchases();

                ToastEx.makeText(ActivityBilling.this, R.string.title_setup_done, Toast.LENGTH_LONG).show();
            } else
                reportError(result, "IAB history");
        }
    });
}
 
Example #4
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 6 votes vote down vote up
@Override
public void onPurchasesUpdated(BillingResult br, @Nullable List<Purchase> purchases) {
    if (br.getResponseCode() == BillingResponseCode.OK) {
        listener.showToast(Toaster.build().message(R.string.thankYou).extra(purchases == null ? null : purchases.toString()));
        if (purchases == null || purchases.isEmpty()) return;

        for (Purchase p : purchases) {
            if (p.isAcknowledged()) continue;

            AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder()
                    .setPurchaseToken(p.getPurchaseToken())
                    .build();
            billingClient.acknowledgePurchase(params, br1 -> {
                if (br1.getResponseCode() != BillingResponseCode.OK)
                    handleBillingErrors(br1.getResponseCode());
            });
        }
    } else {
        handleBillingErrors(br.getResponseCode());
    }
}
 
Example #5
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
@Override
public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> purchases) {
    int responseCode = billingResult.getResponseCode();
    //PPApplication.logE(TAG, "onPurchasesUpdated() response: " + responseCode);
    if (responseCode == BillingClient.BillingResponseCode.OK) {
        getFragment().purchaseSuccessful(purchases);

        if (purchases != null) {
            for (Purchase purchase : purchases) {
                consumePurchase(purchase);
            }
        }
    }
    else {
        getFragment().purchaseUnsuccessful(purchases);
        getFragment().displayAnErrorIfNeeded(responseCode);
    }
}
 
Example #6
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
private void querySkus(List<String> query) {
    Log.i("IAB query SKUs");
    SkuDetailsParams.Builder builder = SkuDetailsParams.newBuilder();
    builder.setSkusList(query);
    builder.setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(builder.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(BillingResult result, List<SkuDetails> skuDetailsList) {
                    if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                        for (SkuDetails skuDetail : skuDetailsList) {
                            Log.i("IAB SKU detail=" + skuDetail);
                            skuDetails.put(skuDetail.getSku(), skuDetail);
                            for (IBillingListener listener : listeners)
                                listener.onSkuDetails(skuDetail.getSku(), skuDetail.getPrice());
                        }
                    } else
                        reportError(result, "IAB query SKUs");
                }
            });
}
 
Example #7
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 6 votes vote down vote up
public void onStart(@NonNull Activity activity) {
    billingClient = BillingClient.newBuilder(activity).enablePendingPurchases().setListener(new InternalListener()).build();
    billingClient.startConnection(new BillingClientStateListener() {
        private boolean retried = false;

        @Override
        public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
            if (billingResult.getResponseCode() == BillingResponseCode.OK) {
                synchronized (billingReady) {
                    billingReady.notifyAll();
                }
            } else {
                handleBillingErrors(billingResult.getResponseCode());
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
            if (!retried) {
                retried = true;
                billingClient.startConnection(this);
            } else {
                listener.showToast(Toaster.build().message(R.string.failedBillingConnection));
            }
        }
    });
}
 
Example #8
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
                                 final List<String> skuList, final SkuDetailsResponseListener listener) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
                    .setSkusList(skuList).setType(itemType).build();
            mBillingClient.querySkuDetailsAsync(skuDetailsParams,
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(@NonNull BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                            listener.onSkuDetailsResponse(billingResult, skuDetailsList);
                        }
                    });
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #9
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
private void reportError(BillingResult result, String stage) {
    String message;
    if (result == null)
        message = stage;
    else {
        String debug = result.getDebugMessage();
        message = getBillingResponseText(result) + (debug == null ? "" : " " + debug) + " " + stage;

        // https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse#service_disconnected
        if (result.getResponseCode() == BillingClient.BillingResponseCode.SERVICE_DISCONNECTED)
            retry(60);
    }

    EntityLog.log(this, message);

    if (result.getResponseCode() != BillingClient.BillingResponseCode.USER_CANCELED)
        for (IBillingListener listener : listeners)
            listener.onError(message);
}
 
Example #10
Source File: GoogleIap.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private void startServiceConnection() {
    if (mIsServiceConnecting) {
        return;
    }

    mIsServiceConnecting = true;
    mBillingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(@NotNull BillingResult billingResult) {

            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                mIsServiceConnected = true;
                for (Runnable runnable : mRequests) {
                    getExecutor().execute(runnable);
                }
            } else {
                EventCollector.logException("google play billing:" + billingResult.getDebugMessage());
            }
            mIsServiceConnecting = false;
        }

        @Override
        public void onBillingServiceDisconnected() {
            mIsServiceConnected = false;
            mIsServiceConnecting = false;
        }
    });
}
 
Example #11
Source File: PictureInPictureUpgradeActivity.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pipm_upgrade_activity);

    billingClient = BillingClient.newBuilder(this).setListener(this).enablePendingPurchases().build();
    billingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(BillingResult billingResult) {
            if (billingResult.getResponseCode() ==  BillingClient.BillingResponseCode.OK) {
                Log.d("bill", "onBillingSetupFinished");
                loadSKUs();

                for (Purchase p: billingClient.queryPurchases("inapp" ).getPurchasesList()) {
                    Log.d("billp", "purchases: " + p.getPurchaseToken());
                    //already purchased
                    PreferenceManager.getDefaultSharedPreferences(PictureInPictureUpgradeActivity.this)
                            .edit().putBoolean("upgraded",true).apply();
                    Preferences.hasUpgrade = true;
                }
            }
        }
        @Override
        public void onBillingServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
            Log.d("bill", "onBillingServiceDisconnected");
        }
    });
}
 
Example #12
Source File: PictureInPictureUpgradeActivity.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
public void loadSKUs(){
    List<String> skuList = new ArrayList<>();
    skuList.add("upgrade");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(params.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(BillingResult billingResult,
                                                 List<SkuDetails> skuDetailsList) {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && !skuDetailsList.isEmpty()) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            if (skuDetails.getSku().equals("upgrade")){
                                findViewById(R.id.upgrade_button).setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        BillingFlowParams billingFlowParams = BillingFlowParams
                                                .newBuilder()
                                                .setSkuDetails(skuDetails)
                                                .build();
                                        billingClient.launchBillingFlow(PictureInPictureUpgradeActivity.this, billingFlowParams);
                                    }
                                });
                            }

                        }
                    }
                }
            });
}
 
Example #13
Source File: PictureInPictureUpgradeActivity.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
@Override
public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> purchases) {
    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {
        for (Purchase purchase : purchases) {
            handlePurchase(purchase);
        }
    } else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
        // Handle an error caused by a user cancelling the purchase flow.
    } else {
        // Handle any other error codes.
    }
}
 
Example #14
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void startServiceConnectionIfNeeded(final Runnable executeOnSuccess) {
    //PPApplication.logE(TAG, "startServiceConnectionIfNeeded");
    if (mBillingClient.isReady()) {
        if (executeOnSuccess != null) {
            executeOnSuccess.run();
        }
    } else {
        DonationFragment fragment = getFragment();
        if (fragment != null)
            fragment.setWaitScreen(true);

        mBillingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    //Log.i(TAG, "onBillingSetupFinished() response: " + billingResponse);

                    if (executeOnSuccess == null) {
                        if (getFragment() != null)
                            getFragment().updateGUIAfterBillingConnected();
                    }

                    if (executeOnSuccess != null) {
                        executeOnSuccess.run();
                    }
                }/* else {
                    Log.w(TAG, "onBillingSetupFinished() error code: " + billingResponse);
                }*/
            }

            @Override
            public void onBillingServiceDisconnected() {
                //Log.w(TAG, "onBillingServiceDisconnected()");
            }
        });
    }
}
 
Example #15
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void consumePurchase(final Purchase purchase) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            ConsumeParams consumeParams =
                    ConsumeParams.newBuilder()
                            .setPurchaseToken(purchase.getPurchaseToken())

                            // https://developer.android.com/google/play/billing/developer-payload
                            // Developer payload has historically been used for various purposes, including fraud
                            // prevention and attributing purchases to the correct user.
                            // With version 2.2 of the Google Play Billing Library, intended use cases that previously
                            // relied on developer payload, are now fully supported in other parts of the library.
                            //.setDeveloperPayload(purchase.getDeveloperPayload())

                            .build();

            mBillingClient.consumeAsync(consumeParams,
                    new ConsumeResponseListener() {
                        @Override
                        public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String purchaseToken) {
                            //PPApplication.logE(TAG, "onConsumeResponse() response: " + billingResult.getResponseCode());
                            /*if (responseCode == BillingClient.BillingResponse.OK) {
                                // Handle the success of the consume operation.
                                // For example, increase the number of player's coins,
                                // that provide temporary benefits
                            }*/
                        }
                    }
            );
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #16
Source File: PlayBillingWrapper.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
@Override
public void connect() {
    mClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(BillingResult billingResult) {
            mListener.onConnected();
        }

        @Override
        public void onBillingServiceDisconnected() {
            mListener.onDisconnected();
        }
    });
}
 
Example #17
Source File: GoogleIap.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPurchaseHistoryResponse(BillingResult billingResult, List<PurchaseHistoryRecord> list) {
    if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
        EventCollector.logException("queryPurchasesHistory" + billingResult.getDebugMessage());
    }

}
 
Example #18
Source File: GoogleIap.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> list) {
    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
            && list != null) {
        for (Purchase purchase : list) {
            handlePurchase(purchase);
        }
        mPurchasesUpdatedListener.onPurchasesUpdated();
    } else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
        // Handle an error caused by a user cancelling the purchase flow.
    } else {
        // Handle any other error codes.
    }
}
 
Example #19
Source File: GoogleBillingHelper.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Query SKU details. If no connection available, establish connection.
 *
 * @param listener The listener called when the query is finished.
 */
public void querySkuDetails(final OnInventoryFinishedListener listener) {
	if (mIsConnected) {
		doQuerySkuDetails(listener);
	}
	else {
		mBillingClient.startConnection(new BillingClientStateListener() {
			@Override
			public void onBillingSetupFinished(final BillingResult billingResult) {
				if (billingResult.getResponseCode() == BillingResponseCode.OK) {
					Log.d(TAG, "Google Billing Connection established.");
					mIsConnected = true;
					doQuerySkuDetails(listener);
				}
				else {
					Log.i(TAG, "Google Billing Connection failed - " + billingResult.getDebugMessage());
					mIsConnected = false;
				}
			}

			@Override
			public void onBillingServiceDisconnected() {
				Log.d(TAG, "Google Billing Connection lost.");
				mIsConnected = false;
			}
		});
	}
}
 
Example #20
Source File: GoogleBillingHelper.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Launch the purchase flow for a product. If there is no connection, then establish connection before.
 *
 * @param activity   The triggering activity.
 * @param skuDetails The details of the product to be purchased.
 * @param listener   a listener called after the purchase has been completed.
 */
public void launchPurchaseFlow(final Activity activity, final SkuDetails skuDetails, final OnPurchaseSuccessListener listener) {
	if (mIsConnected) {
		doLaunchPurchaseFlow(activity, skuDetails, listener);
	}
	else {
		mBillingClient.startConnection(new BillingClientStateListener() {
			@Override
			public void onBillingSetupFinished(final BillingResult billingResult) {
				if (billingResult.getResponseCode() == BillingResponseCode.OK) {
					Log.d(TAG, "Google Billing Connection established.");
					mIsConnected = true;
					doLaunchPurchaseFlow(activity, skuDetails, listener);
				}
				else {
					Log.i(TAG, "Google Billing Connection failed - " + billingResult.getDebugMessage());
					mIsConnected = false;
				}
			}

			@Override
			public void onBillingServiceDisconnected() {
				Log.d(TAG, "Google Billing Connection lost.");
				mIsConnected = false;
			}
		});
	}
}
 
Example #21
Source File: GoogleBillingHelper.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPurchasesUpdated(final BillingResult billingResult, final @Nullable List<Purchase> purchaseList) {
	Log.i(TAG, "Purchase finished: " + billingResult.getResponseCode());

	if (billingResult.getResponseCode() != BillingResponseCode.OK) {
		Log.e(TAG, "Error purchasing: " + billingResult.getDebugMessage());
		if (mOnPurchaseSuccessListener != null) {
			mOnPurchaseSuccessListener.handleFailure();
		}
		return;
	}

	Log.i(TAG, "Purchase successful.");

	if (mOnPurchaseSuccessListener != null && purchaseList != null) {
		boolean hasPurchase = false;
		boolean isPurchased = false;
		for (Purchase purchase : purchaseList) {
			hasPurchase = true;
			if (purchase.getPurchaseState() == PurchaseState.PURCHASED) {
				Log.i(TAG, "Purchase " + purchase.getSku() + " finished");
				isPurchased = true;
				doAcknowledgePurchaseIfRequired(purchase);
			}
		}
		if (hasPurchase) {
			mOnPurchaseSuccessListener.handlePurchase(!mIsPremium, !isPurchased);
			if (isPurchased) {
				mIsPremium = true;
			}
		}
	}
}
 
Example #22
Source File: GoogleBillingHelper.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Acknowledge a purchase.
 *
 * @param purchase The purchase.
 */
private void doAcknowledgePurchaseIfRequired(final Purchase purchase) {
	if (!purchase.isAcknowledged()) {
		Log.d(TAG, "Acknowledging purchase " + purchase.getSku());
		mBillingClient.acknowledgePurchase(
				AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build(),
				new AcknowledgePurchaseResponseListener() {
					@Override
					public void onAcknowledgePurchaseResponse(final BillingResult billingResult) {
						Log.d(TAG, "Acknowledgement result: " + billingResult.getResponseCode());
					}
				});
	}
}
 
Example #23
Source File: DefaultBillingManager.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> list) {
    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.SERVICE_DISCONNECTED) {
        connectBillingService();
    } else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
        loadPurchases();
    } else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED) {
        loadPurchases();
    }
}
 
Example #24
Source File: PlayBillingWrapper.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
@Override
public boolean launchPaymentFlow(SkuDetails sku) {
    BillingFlowParams params = BillingFlowParams
            .newBuilder()
            .setSkuDetails(sku)
            .build();

    BillingResult result = mClient.launchBillingFlow(mActivity, params);

    return result.getResponseCode() == BillingClient.BillingResponseCode.OK;
}
 
Example #25
Source File: AccelerateDevelop.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
        billingServiceConnected = true;
        Log.i(LOG_TAG, "Billing setup is finished");
        //below you can query information about products and purchase
        querySkuDetails(); //query for products
        List<Purchase> purchasesList = queryPurchases(); //query for purchases

        //if the purchase has already been made to give the goods
        if (purchasesList != null) {
            handlePurchases(purchasesList);
        }
    }
}
 
Example #26
Source File: AccelerateDevelop.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void querySkuDetails() {

        if (!billingServiceConnected) {
            mBillingClient.startConnection(this);
            return;
        }

        SkuDetailsParams.Builder skuDetailsParamsBuilder = SkuDetailsParams.newBuilder();
        List<String> skuList = new ArrayList<>();
        skuList.add(mSkuId);
        skuDetailsParamsBuilder.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);

        mBillingClient.querySkuDetailsAsync(skuDetailsParamsBuilder.build(), new SkuDetailsResponseListener() {
            @Override
            public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    if (!skuDetailsList.isEmpty()) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            mSkuDetailsMap.put(skuDetails.getSku(), skuDetails);
                        }
                    } else {
                        Log.w(LOG_TAG, "Query SKU details is OK, but SKU list is empty " + billingResult.getDebugMessage());


                    }

                } else {
                    Log.w(LOG_TAG, "Query SKU details warning " + billingResult.getResponseCode() + " " + billingResult.getDebugMessage());
                }
            }
        });
    }
 
Example #27
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBillingSetupFinished(BillingResult result) {
    if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
        for (IBillingListener listener : listeners)
            listener.onConnected();

        backoff = 4;
        queryPurchases();
    } else
        reportError(result, "IAB connected");
}
 
Example #28
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPurchasesUpdated(BillingResult result, @Nullable List<Purchase> purchases) {
    if (result.getResponseCode() == BillingClient.BillingResponseCode.OK)
        checkPurchases(purchases);
    else
        reportError(result, "IAB purchases updated");
}
 
Example #29
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private void consumePurchase(final Purchase purchase) {
    Log.i("IAB SKU=" + purchase.getSku() + " consuming");
    ConsumeParams params = ConsumeParams.newBuilder()
            .setPurchaseToken(purchase.getPurchaseToken())
            .build();
    billingClient.consumeAsync(params, new ConsumeResponseListener() {
        @Override
        public void onConsumeResponse(BillingResult result, String purchaseToken) {
            if (result.getResponseCode() != BillingClient.BillingResponseCode.OK)
                reportError(result, "IAB consumed SKU=" + purchase.getSku());
        }
    });
}
 
Example #30
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void buyProduct(@NonNull Activity activity, @NonNull SkuDetails product) {
    BillingFlowParams flowParams = BillingFlowParams.newBuilder()
            .setSkuDetails(product)
            .build();

    BillingResult result = billingClient.launchBillingFlow(activity, flowParams);
    if (result.getResponseCode() != BillingResponseCode.OK)
        handleBillingErrors(result.getResponseCode());
}