use of com.android.billingclient.api.BillingResult in project zype-android by zype.
the class MarketplaceGateway method queryGooglePlayProduct.
//
// Google Play
//
private void queryGooglePlayProduct(final Subscription subscription) {
// Get sku details from marketplace (Google Play) for specified sku
Log.d("BillingManager", "queryGooglePlayProduct: subscription: " + subscription);
if (subscription.getZypePlan().marketplaceIds == null) {
Logger.d("queryGooglePlayProduct(): marketplaceIds is empty.");
return;
}
final String sku = subscription.getZypePlan().marketplaceIds.googleplay;
Log.d("BillingManager", "queryGooglePlayProduct: sku: " + sku);
List<String> skuList = new ArrayList<>();
skuList.add(sku);
billingManager.querySkuDetailsAsync(BillingClient.SkuType.SUBS, skuList, new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(@NonNull BillingResult billingResult, @Nullable List<SkuDetails> list) {
if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
Logger.e("onSkuDetailsResponse(): Error retrieving sku details from Google Play");
} else {
if (list != null) {
if (list.size() == 0) {
Logger.e("onSkuDetailsResponse(): Sku is not found in Google Play, sku=" + sku);
} else {
if (list.size() > 1) {
Logger.w("onSkuDetailsResponse(): Unexpected number of items (" + list.size() + ") in Google Play, sku=" + sku);
}
subscription.setMarketplace(list.get(0));
}
}
}
}
});
}
use of com.android.billingclient.api.BillingResult in project zype-android by zype.
the class BillingManager method clearPurchases.
/**
* Consumes all purchases.
* Used only for testing one-time purchases
*/
public void clearPurchases() {
if (purchases != null) {
for (Purchase purchase : purchases) {
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String s) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
// Handle the success of the consume operation.
// For example, increase the number of coins inside the user's basket.
}
}
};
ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
mBillingClient.consumeAsync(consumeParams, listener);
}
}
}
use of com.android.billingclient.api.BillingResult in project sms-backup-plus by jberkel.
the class DonationActivity method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
billingClient = BillingClient.newBuilder(this).setListener(this).enablePendingPurchases().build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult resultCode) {
log("onBillingSetupFinished(" + resultCode + ")" + Thread.currentThread().getName());
switch(resultCode.getResponseCode()) {
case OK:
queryAvailableSkus();
break;
case BILLING_UNAVAILABLE:
case DEVELOPER_ERROR:
case ERROR:
case FEATURE_NOT_SUPPORTED:
case ITEM_ALREADY_OWNED:
case ITEM_NOT_OWNED:
case ITEM_UNAVAILABLE:
case SERVICE_DISCONNECTED:
case SERVICE_UNAVAILABLE:
case USER_CANCELED:
case SERVICE_TIMEOUT:
default:
Toast.makeText(DonationActivity.this, R.string.donation_error_iab_unavailable, LENGTH_LONG).show();
Log.w(TAG, "Problem setting up in-app billing: " + resultCode);
finish();
break;
}
}
@Override
public void onBillingServiceDisconnected() {
Log.d(TAG, "onBillingServiceDisconnected");
}
});
}
use of com.android.billingclient.api.BillingResult in project sms-backup-plus by jberkel.
the class DonationActivity method acknowledgePurchase.
// https://developer.android.com/google/play/billing/billing_library_overview#acknowledge
private void acknowledgePurchase(final Purchase purchase) {
if (purchase.getPurchaseState() == PURCHASED && !purchase.isAcknowledged() && billingClient != null) {
AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
billingClient.acknowledgePurchase(params, new AcknowledgePurchaseResponseListener() {
@Override
public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
log("onAcknowledgePurchaseResponse(" + billingResult + ")");
if (billingResult.getResponseCode() != OK) {
Log.w(TAG, "not acknowledged purchase " + purchase + ":" + billingResult);
}
}
});
}
}
use of com.android.billingclient.api.BillingResult in project Android-InAppBilling by LiteKite.
the class BillingManager method areSubscriptionsSupported.
/**
* Checks if subscriptions are supported for current client.
*
* <p>Note: This method does not automatically retry for RESULT_SERVICE_DISCONNECTED. It is only
* used in unit tests and after queryPurchases execution, which already has a retry-mechanism
* implemented.
*
* @return boolean value of whether the subscription is supported or not.
*/
private boolean areSubscriptionsSupported() {
final BillingResult billingResult = myBillingClient.isFeatureSupported(FeatureType.SUBSCRIPTIONS);
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
MonetizeApp.printLog(TAG, "areSubscriptionsSupported() got an error response: " + billingResult.getResponseCode());
notifyBillingError(R.string.err_subscription_not_supported);
}
return billingResult.getResponseCode() == BillingResponseCode.OK;
}
Aggregations