use of com.android.billingclient.api.ConsumeResponseListener in project OsmAnd by osmandapp.
the class BillingManager method consumeAsync.
public void consumeAsync(final ConsumeParams consumeParams) {
// If we've already scheduled to consume this token - no action is needed (this could happen
// if you received the token when querying purchases inside onReceive() and later from
// onActivityResult()
final String purchaseToken = consumeParams.getPurchaseToken();
if (mTokensToBeConsumed == null) {
mTokensToBeConsumed = new HashSet<>();
} else if (mTokensToBeConsumed.contains(purchaseToken)) {
LOG.info("Token was already scheduled to be consumed - skipping...");
return;
}
mTokensToBeConsumed.add(purchaseToken);
// Generating Consume Response listener
final ConsumeResponseListener onConsumeListener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
// If billing service was disconnected, we try to reconnect 1 time
// (feel free to introduce your retry policy here).
mBillingUpdatesListener.onConsumeFinished(purchaseToken, billingResult);
}
};
// Creating a runnable from the request to use it inside our connection retry policy below
Runnable consumeRequest = new Runnable() {
@Override
public void run() {
// Consume the purchase async
mBillingClient.consumeAsync(consumeParams, onConsumeListener);
}
};
executeServiceRequest(consumeRequest);
}
use of com.android.billingclient.api.ConsumeResponseListener in project getsocial-android-sdk by getsocial-im.
the class PurchaseFragment method consumePurchasedItem.
private void consumePurchasedItem(Purchase purchase) {
ConsumeParams params = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
_billingClient.consumeAsync(params, new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
System.out.println("got consumePurchase response");
}
});
}
use of com.android.billingclient.api.ConsumeResponseListener in project AperoModuleAds by AperoVN.
the class AppPurchase method handlePurchase.
private void handlePurchase(Purchase purchase) {
// tracking adjust
double price = getPriceWithoutCurrency(idPurchaseCurrent, typeIap);
String currentcy = getCurrency(idPurchaseCurrent, typeIap);
AdjustApero.onTrackRevenuePurchase((float) price, currentcy);
if (purchaseListioner != null)
isPurchase = true;
purchaseListioner.onProductPurchased(purchase.getOrderId(), purchase.getOriginalJson());
if (isConsumePurchase) {
ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
Log.d(TAG, "onConsumeResponse: " + billingResult.getDebugMessage());
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
}
}
};
billingClient.consumeAsync(consumeParams, listener);
} else {
if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
if (!purchase.isAcknowledged()) {
billingClient.acknowledgePurchase(acknowledgePurchaseParams, new AcknowledgePurchaseResponseListener() {
@Override
public void onAcknowledgePurchaseResponse(@NonNull BillingResult billingResult) {
Log.d(TAG, "onAcknowledgePurchaseResponse: " + billingResult.getDebugMessage());
}
});
}
}
}
}
use of com.android.billingclient.api.ConsumeResponseListener in project AperoModuleAds by AperoVN.
the class AppPurchase method consumePurchase.
public void consumePurchase(String productId) {
Purchase pc = null;
Purchase.PurchasesResult resultINAP = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
if (resultINAP.getResponseCode() == BillingClient.BillingResponseCode.OK && resultINAP.getPurchasesList() != null) {
for (Purchase purchase : resultINAP.getPurchasesList()) {
if (purchase.getSkus().contains(productId)) {
pc = purchase;
}
}
}
if (pc == null)
return;
try {
ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(pc.getPurchaseToken()).build();
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Log.e(TAG, "onConsumeResponse: OK");
verifyPurchased(false);
}
}
};
billingClient.consumeAsync(consumeParams, listener);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations