Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abbasghasemi committed Dec 21, 2023
1 parent d1c092a commit 98c0dc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
39 changes: 20 additions & 19 deletions billing/src/main/java/com/farasource/billing/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -148,41 +149,41 @@ 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)) {
onBillingStatus(TableCodes.NO_NETWORK);
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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 98c0dc7

Please sign in to comment.