diff --git a/README.md b/README.md index 227d1ab..593002b 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); payment = new Payment(getActivityResultRegistry(), this, "PUBLIC_KEY"); - payment.setCanAutoConsume(false); + payment.setGlobalAutoConsume(false); payment.setOnPaymentResultListener(new OnPaymentResultListener() { @Override public void onBillingSuccess(Purchase purchase) { diff --git a/billing/src/main/java/com/farasource/billing/Payment.java b/billing/src/main/java/com/farasource/billing/Payment.java index d72cb24..fd6064f 100644 --- a/billing/src/main/java/com/farasource/billing/Payment.java +++ b/billing/src/main/java/com/farasource/billing/Payment.java @@ -4,6 +4,7 @@ import android.content.pm.PackageManager; import androidx.activity.result.ActivityResultRegistry; + import com.farasource.billing.util.IABLogger; import com.farasource.billing.util.IabResult; import com.farasource.billing.util.Inventory; @@ -20,7 +21,7 @@ public class Payment { PaymentHelper mHelper; private String SKU = null; private final String RSA; - private boolean canAutoConsume, disposed, hasLaunch, startedSetup; + private boolean globalAutoConsume, autoConsume, disposed, hasLaunch, startedSetup; private OnPaymentResultListener onPaymentResultListener; // Called when consumption is complete PaymentHelper.OnConsumeFinishedListener mConsumeFinishedListener = new PaymentHelper.OnConsumeFinishedListener() { @@ -61,7 +62,7 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) { return; } else { - if (canAutoConsume) consume(purchase); + if (autoConsume) consume(purchase); if (onPaymentResultListener != null) onPaymentResultListener.onBillingSuccess(purchase); @@ -110,7 +111,7 @@ public Payment(ActivityResultRegistry registry, Context context, String rsa) { public void setOnPaymentResultListener(OnPaymentResultListener onPaymentResultListener) { this.onPaymentResultListener = onPaymentResultListener; mHelper = new PaymentHelper(activityResultRegistry, context, RSA); - if (!isMarketInstalled()) { + if (isMarketNotInstalled()) { onBillingStatus(TableCodes.MARKET_NOT_INSTALLED); return; } else if (startedSetup) { @@ -148,33 +149,33 @@ public void rebuildActivityResultRegistry(ActivityResultRegistry registry) { } public void launchPayment(String sku) { - launchPayment(sku, PaymentHelper.ITEM_TYPE_INAPP, "", false); + launchPayment(sku, PaymentHelper.ITEM_TYPE_INAPP, "", globalAutoConsume); } - public void launchPayment(String sku, boolean canAutoConsume) { - launchPayment(sku, PaymentHelper.ITEM_TYPE_INAPP, "", canAutoConsume); + public void launchPayment(String sku, boolean autoConsume) { + launchPayment(sku, PaymentHelper.ITEM_TYPE_INAPP, "", autoConsume); } public void launchPayment(String sku, String type) { - launchPayment(sku, type, "", false); + launchPayment(sku, type, "", globalAutoConsume); } - public void launchPayment(String sku, String type, boolean canAutoConsume) { - launchPayment(sku, type, "", canAutoConsume); + public void launchPayment(String sku, String type, boolean autoConsume) { + launchPayment(sku, type, "", autoConsume); } public void launchPayment(String sku, String type, String payload) { - launchPayment(sku, type, payload, false); + launchPayment(sku, type, payload, globalAutoConsume); } - public void launchPayment(String sku, String type, String payload, boolean canAutoConsume) { + public void launchPayment(String sku, String type, String payload, boolean autoConsume) { if (disposed) { onBillingStatus(TableCodes.PAYMENT_DISPOSED); return; } else if (hasLaunch) { onBillingStatus(TableCodes.PAYMENT_IS_IN_PROGRESS); return; - } else if (!isMarketInstalled()) { + } else if (isMarketNotInstalled()) { onBillingStatus(TableCodes.MARKET_NOT_INSTALLED); return; } else if (!com.farasource.billing.NetworkCheck.isOnline(context)) { @@ -182,7 +183,7 @@ public void launchPayment(String sku, String type, String payload, boolean canAu return; } this.SKU = sku; - this.canAutoConsume = canAutoConsume; + this.autoConsume = autoConsume; if (PaymentHelper.ITEM_TYPE_SUBS.equals(type) && !mHelper.subscriptionsSupported()) { logger.logDebug("Subscriptions not supported on your device yet. Sorry!"); onBillingStatus(TableCodes.SUBSCRIPTIONS_NOT_SUPPORTED); @@ -198,12 +199,12 @@ public void launchPayment(String sku, String type, String payload, boolean canAu } } - public void setCanAutoConsume(boolean canAutoConsume) { + public void setGlobalAutoConsume(boolean autoConsume) { if (hasLaunch) { logger.logDebug("Can't be used while payment is active."); return; } - this.canAutoConsume = canAutoConsume; + this.globalAutoConsume = autoConsume; } public void consume(Purchase purchase) { @@ -234,12 +235,12 @@ public void dispose() { mConsumeFinishedListener = null; } - private boolean isMarketInstalled() { + private boolean isMarketNotInstalled() { try { - context.getPackageManager().getPackageInfo( mHelper.getMarketId(), PackageManager.GET_ACTIVITIES); - return true; - } catch (PackageManager.NameNotFoundException e) { + context.getPackageManager().getPackageInfo(mHelper.getMarketId(), PackageManager.GET_ACTIVITIES); return false; + } catch (PackageManager.NameNotFoundException e) { + return true; } } diff --git a/sample/src/main/java/ir/farasource/inapp/payment/sample/MainActivity.java b/sample/src/main/java/ir/farasource/inapp/payment/sample/MainActivity.java index 1009d10..c9fd810 100644 --- a/sample/src/main/java/ir/farasource/inapp/payment/sample/MainActivity.java +++ b/sample/src/main/java/ir/farasource/inapp/payment/sample/MainActivity.java @@ -129,7 +129,7 @@ public void onCreate(Bundle savedInstanceState) { // Create the helper, passing it our context and the public key to verify signatures with Log.d(TAG, "Creating IAB helper."); payment = new Payment(getActivityResultRegistry(), this, "PUBLIC_KEY"); - payment.setCanAutoConsume(false); + payment.setGlobalAutoConsume(false); payment.setOnPaymentResultListener(new OnPaymentResultListener() { @Override public void onBillingSuccess(Purchase purchase) {