From 500aaed310556dd7a8b736bd362c50ceacff78ea Mon Sep 17 00:00:00 2001 From: Alex Dibrivnyi Date: Sat, 30 May 2020 18:53:46 +0300 Subject: [PATCH 1/6] Convert IAPManager to Kotlin --- .../inapppayments/IAPManager.java | 87 ------------------- .../eggheadgames/inapppayments/IAPManager.kt | 85 ++++++++++++++++++ 2 files changed, 85 insertions(+), 87 deletions(-) delete mode 100644 library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java create mode 100644 library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt diff --git a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java deleted file mode 100644 index 5833b71..0000000 --- a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.eggheadgames.inapppayments; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Context; - -import com.billing.BillingService; -import com.billing.PurchaseServiceListener; -import com.billing.SubscriptionServiceListener; -import com.billing.amazon.AmazonBillingService; -import com.billing.google.GoogleBillingService2; - -import java.util.ArrayList; -import java.util.List; - -//Public front-end for IAP functionality. - -public class IAPManager { - - public static final int BUILD_TARGET_GOOGLE = 0; - public static final int BUILD_TARGET_AMAZON = 1; - - @SuppressLint("StaticFieldLeak") - private static BillingService billingService; - - /** - * @param context - application context - * @param buildTarget - IAPManager.BUILD_TARGET_GOOGLE or IAPManager.BUILD_TARGET_AMAZON - * @param iapKeys - list of sku for purchases - * @param subscriptionKeys - list of sku for subscriptions - */ - public static void build(Context context, int buildTarget, List iapKeys, List subscriptionKeys) { - Context applicationContext = context.getApplicationContext(); - Context contextLocal = applicationContext == null ? context : applicationContext; - - //Build-specific initializations - if (buildTarget == BUILD_TARGET_GOOGLE) { - billingService = new GoogleBillingService2(contextLocal, iapKeys, subscriptionKeys); - } else if (buildTarget == BUILD_TARGET_AMAZON) { - List keys = new ArrayList<>(); - keys.addAll(iapKeys); - keys.addAll(subscriptionKeys); - billingService = new AmazonBillingService(contextLocal, keys); - } - } - - public static void init(String key, boolean enableLogging) { - billingService.init(key); - billingService.enableDebugLogging(enableLogging); - } - - public static void addPurchaseListener(PurchaseServiceListener purchaseServiceListener) { - billingService.addPurchaseListener(purchaseServiceListener); - } - - public static void removePurchaseListener(PurchaseServiceListener purchaseServiceListener) { - billingService.removePurchaseListener(purchaseServiceListener); - } - - public static void addSubscriptionListener(SubscriptionServiceListener subscriptionServiceListener) { - billingService.addSubscriptionListener(subscriptionServiceListener); - } - - public static void removeSubscriptionListener(SubscriptionServiceListener subscriptionServiceListener) { - billingService.removeSubscriptionListener(subscriptionServiceListener); - } - - public static void buy(Activity activity, String sku, int id) { - billingService.buy(activity, sku, id); - } - - public static void subscribe(Activity activity, String sku, int id) { - billingService.subscribe(activity, sku, id); - } - - public static void unsubscribe(Activity activity, String sku, int id) { - billingService.unsubscribe(activity, sku, id); - } - - public static void destroy() { - billingService.close(); - } - - public static BillingService getBillingService() { - return billingService; - } -} diff --git a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt new file mode 100644 index 0000000..0efe1aa --- /dev/null +++ b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt @@ -0,0 +1,85 @@ +package com.eggheadgames.inapppayments + +import android.annotation.SuppressLint +import android.app.Activity +import android.content.Context +import com.billing.BillingService +import com.billing.PurchaseServiceListener +import com.billing.SubscriptionServiceListener +import com.billing.amazon.AmazonBillingService +import com.billing.google.GoogleBillingService2 +import java.util.* + +//Public front-end for IAP functionality. +object IAPManager { + const val BUILD_TARGET_GOOGLE = 0 + const val BUILD_TARGET_AMAZON = 1 + + @JvmStatic + @SuppressLint("StaticFieldLeak") + var billingService: BillingService? = null + private set + + /** + * @param context - application context + * @param buildTarget - IAPManager.BUILD_TARGET_GOOGLE or IAPManager.BUILD_TARGET_AMAZON + * @param iapKeys - list of sku for purchases + * @param subscriptionKeys - list of sku for subscriptions + */ + @JvmStatic + fun build(context: Context, buildTarget: Int, iapKeys: List?, subscriptionKeys: List?) { + val applicationContext = context.applicationContext + val contextLocal = applicationContext ?: context + + //Build-specific initializations + if (buildTarget == BUILD_TARGET_GOOGLE) { + billingService = GoogleBillingService2(contextLocal, iapKeys!!, subscriptionKeys!!) + } else if (buildTarget == BUILD_TARGET_AMAZON) { + val keys: MutableList = ArrayList() + keys.addAll(iapKeys!!) + keys.addAll(subscriptionKeys!!) + billingService = AmazonBillingService(contextLocal, keys) + } + } + + fun init(key: String?, enableLogging: Boolean) { + billingService!!.init(key) + billingService!!.enableDebugLogging(enableLogging) + } + + @JvmStatic + fun addPurchaseListener(purchaseServiceListener: PurchaseServiceListener?) { + billingService!!.addPurchaseListener(purchaseServiceListener) + } + + @JvmStatic + fun removePurchaseListener(purchaseServiceListener: PurchaseServiceListener?) { + billingService!!.removePurchaseListener(purchaseServiceListener) + } + + @JvmStatic + fun addSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener?) { + billingService!!.addSubscriptionListener(subscriptionServiceListener) + } + + fun removeSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener?) { + billingService!!.removeSubscriptionListener(subscriptionServiceListener) + } + + fun buy(activity: Activity?, sku: String?, id: Int) { + billingService!!.buy(activity, sku, id) + } + + fun subscribe(activity: Activity?, sku: String?, id: Int) { + billingService!!.subscribe(activity, sku, id) + } + + fun unsubscribe(activity: Activity?, sku: String?, id: Int) { + billingService!!.unsubscribe(activity, sku, id) + } + + fun destroy() { + billingService!!.close() + } + +} \ No newline at end of file From 61208aae0c21602d9871803d9b7408a4d41e2439 Mon Sep 17 00:00:00 2001 From: Alex Dibrivnyi Date: Sat, 30 May 2020 19:45:43 +0300 Subject: [PATCH 2/6] Refactor IAPManager after converting to Kotlin --- .../eggheadgames/inapppayments/IAPManager.kt | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt index 0efe1aa..15b3828 100644 --- a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt +++ b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt @@ -15,10 +15,8 @@ object IAPManager { const val BUILD_TARGET_GOOGLE = 0 const val BUILD_TARGET_AMAZON = 1 - @JvmStatic @SuppressLint("StaticFieldLeak") - var billingService: BillingService? = null - private set + private var mBillingService: BillingService? = null /** * @param context - application context @@ -27,59 +25,69 @@ object IAPManager { * @param subscriptionKeys - list of sku for subscriptions */ @JvmStatic - fun build(context: Context, buildTarget: Int, iapKeys: List?, subscriptionKeys: List?) { - val applicationContext = context.applicationContext - val contextLocal = applicationContext ?: context + fun build(context: Context, buildTarget: Int, iapKeys: List, subscriptionKeys: List = emptyList()) { + val contextLocal = context.applicationContext ?: context //Build-specific initializations if (buildTarget == BUILD_TARGET_GOOGLE) { - billingService = GoogleBillingService2(contextLocal, iapKeys!!, subscriptionKeys!!) + mBillingService = GoogleBillingService2(contextLocal, iapKeys, subscriptionKeys) + } else if (buildTarget == BUILD_TARGET_AMAZON) { val keys: MutableList = ArrayList() - keys.addAll(iapKeys!!) - keys.addAll(subscriptionKeys!!) - billingService = AmazonBillingService(contextLocal, keys) + keys.addAll(iapKeys) + keys.addAll(subscriptionKeys) + mBillingService = AmazonBillingService(contextLocal, keys) } } - fun init(key: String?, enableLogging: Boolean) { - billingService!!.init(key) - billingService!!.enableDebugLogging(enableLogging) + fun init(key: String? = null, enableLogging: Boolean) { + getBillingService().init(key) + getBillingService().enableDebugLogging(enableLogging) } @JvmStatic - fun addPurchaseListener(purchaseServiceListener: PurchaseServiceListener?) { - billingService!!.addPurchaseListener(purchaseServiceListener) + fun addPurchaseListener(purchaseServiceListener: PurchaseServiceListener) { + getBillingService().addPurchaseListener(purchaseServiceListener) } @JvmStatic - fun removePurchaseListener(purchaseServiceListener: PurchaseServiceListener?) { - billingService!!.removePurchaseListener(purchaseServiceListener) + fun removePurchaseListener(purchaseServiceListener: PurchaseServiceListener) { + getBillingService().removePurchaseListener(purchaseServiceListener) } @JvmStatic - fun addSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener?) { - billingService!!.addSubscriptionListener(subscriptionServiceListener) + fun addSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener) { + getBillingService().addSubscriptionListener(subscriptionServiceListener) } - fun removeSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener?) { - billingService!!.removeSubscriptionListener(subscriptionServiceListener) + @JvmStatic + fun removeSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener) { + getBillingService().removeSubscriptionListener(subscriptionServiceListener) } - fun buy(activity: Activity?, sku: String?, id: Int) { - billingService!!.buy(activity, sku, id) + @JvmStatic + fun buy(activity: Activity, sku: String, id: Int) { + getBillingService().buy(activity, sku, id) } - fun subscribe(activity: Activity?, sku: String?, id: Int) { - billingService!!.subscribe(activity, sku, id) + @JvmStatic + fun subscribe(activity: Activity, sku: String, id: Int) { + getBillingService().subscribe(activity, sku, id) } - fun unsubscribe(activity: Activity?, sku: String?, id: Int) { - billingService!!.unsubscribe(activity, sku, id) + fun unsubscribe(activity: Activity, sku: String, id: Int) { + getBillingService().unsubscribe(activity, sku, id) } + @JvmStatic fun destroy() { - billingService!!.close() + getBillingService().close() } + @JvmStatic + fun getBillingService(): BillingService { + return mBillingService ?: let { + throw RuntimeException("Call IAPManager.build to initialize billing service") + } + } } \ No newline at end of file From 19d42954884cdd82af578f3505c20844e66cc7dd Mon Sep 17 00:00:00 2001 From: Alex Dibrivnyi Date: Sat, 30 May 2020 20:14:36 +0300 Subject: [PATCH 3/6] Close #11; Allow blank validation key, blank will always mean valid --- .../main/java/com/billing/amazon/AmazonBillingService.kt | 2 +- .../main/java/com/billing/google/GoogleBillingService2.kt | 7 ++++--- .../main/java/com/eggheadgames/inapppayments/IAPManager.kt | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/billing/amazon/AmazonBillingService.kt b/library/src/main/java/com/billing/amazon/AmazonBillingService.kt index 5f156b7..6cb9274 100644 --- a/library/src/main/java/com/billing/amazon/AmazonBillingService.kt +++ b/library/src/main/java/com/billing/amazon/AmazonBillingService.kt @@ -11,7 +11,7 @@ class AmazonBillingService(val context: Context, private val iapKeys: List() - override fun init(key: String) { + override fun init(key: String?) { decodedKey = key mBillingClient = BillingClient.newBuilder(context).setListener(this).enablePendingPurchases().build() @@ -165,7 +165,8 @@ class GoogleBillingService2(val context: Context, private val inAppSkuKeys: List } private fun isSignatureValid(purchase: Purchase): Boolean { - return Security.verifyPurchase(decodedKey, purchase.originalJson, purchase.signature) + val key = decodedKey ?: return true + return Security.verifyPurchase(key, purchase.originalJson, purchase.signature) } /** diff --git a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt index 15b3828..e274227 100644 --- a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt +++ b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.kt @@ -40,7 +40,12 @@ object IAPManager { } } - fun init(key: String? = null, enableLogging: Boolean) { + /** + * Initialize billing service. + * + * @param key - key to verify purchase messages. Currently valid only for Google Billing. Leave empty if you want to skip verification + */ + fun init(key: String? = null, enableLogging: Boolean = false) { getBillingService().init(key) getBillingService().enableDebugLogging(enableLogging) } From 3c0c34b8df0b3fa9ede82f9e7b32db9238e87736 Mon Sep 17 00:00:00 2001 From: Alex Dibrivnyi Date: Sat, 30 May 2020 20:19:22 +0300 Subject: [PATCH 4/6] Remove id (requestCode) field which is no longer used --- .../src/main/java/com/billing/BillingService.java | 6 +++--- .../java/com/billing/amazon/AmazonBillingService.kt | 6 +++--- .../java/com/billing/google/GoogleBillingService2.kt | 6 +++--- .../com/eggheadgames/inapppayments/IAPManager.kt | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/library/src/main/java/com/billing/BillingService.java b/library/src/main/java/com/billing/BillingService.java index ac50395..e4e1d4b 100644 --- a/library/src/main/java/com/billing/BillingService.java +++ b/library/src/main/java/com/billing/BillingService.java @@ -75,11 +75,11 @@ public void updatePrices(Map iapkeyPrices) { public abstract void init(String key); - public abstract void buy(Activity activity, String sku, int id); + public abstract void buy(Activity activity, String sku); - public abstract void subscribe(Activity activity, String sku, int id); + public abstract void subscribe(Activity activity, String sku); - public abstract void unsubscribe(Activity activity, String sku, int id); + public abstract void unsubscribe(Activity activity, String sku); public abstract void enableDebugLogging(boolean enable); diff --git a/library/src/main/java/com/billing/amazon/AmazonBillingService.kt b/library/src/main/java/com/billing/amazon/AmazonBillingService.kt index 6cb9274..87addec 100644 --- a/library/src/main/java/com/billing/amazon/AmazonBillingService.kt +++ b/library/src/main/java/com/billing/amazon/AmazonBillingService.kt @@ -22,15 +22,15 @@ class AmazonBillingService(val context: Context, private val iapKeys: List Date: Sat, 30 May 2020 20:41:25 +0300 Subject: [PATCH 5/6] Convert BillingService to Kotlin --- .../main/java/com/billing/BillingService.java | 91 ------------------- .../main/java/com/billing/BillingService.kt | 75 +++++++++++++++ 2 files changed, 75 insertions(+), 91 deletions(-) delete mode 100644 library/src/main/java/com/billing/BillingService.java create mode 100644 library/src/main/java/com/billing/BillingService.kt diff --git a/library/src/main/java/com/billing/BillingService.java b/library/src/main/java/com/billing/BillingService.java deleted file mode 100644 index e4e1d4b..0000000 --- a/library/src/main/java/com/billing/BillingService.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.billing; - -import android.app.Activity; - -import androidx.annotation.CallSuper; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public abstract class BillingService { - - private List purchaseServiceListeners; - private List subscriptionServiceListeners; - - @SuppressWarnings("WeakerAccess") - public BillingService() { - purchaseServiceListeners = new ArrayList<>(); - subscriptionServiceListeners = new ArrayList<>(); - } - - public void addPurchaseListener(PurchaseServiceListener purchaseServiceListener) { - purchaseServiceListeners.add(purchaseServiceListener); - } - - public void removePurchaseListener(PurchaseServiceListener purchaseServiceListener) { - purchaseServiceListeners.remove(purchaseServiceListener); - } - - public void addSubscriptionListener(SubscriptionServiceListener subscriptionServiceListener) { - subscriptionServiceListeners.add(subscriptionServiceListener); - } - - public void removeSubscriptionListener(SubscriptionServiceListener subscriptionServiceListener) { - subscriptionServiceListeners.remove(subscriptionServiceListener); - } - - /** - * @param sku - product specificator - * @param isRestore - a flag indicating whether it's a fresh purchase or restored product - */ - public void productOwned(String sku, boolean isRestore) { - for (PurchaseServiceListener purchaseServiceListener : purchaseServiceListeners) { - if (isRestore) { - purchaseServiceListener.onProductRestored(sku); - } else { - purchaseServiceListener.onProductPurchased(sku); - } - } - } - - /** - * @param sku - subscription specificator - * @param isRestore - a flag indicating whether it's a fresh purchase or restored subscription - */ - public void subscriptionOwned(String sku, boolean isRestore) { - for (SubscriptionServiceListener subscriptionServiceListener : subscriptionServiceListeners) { - if (isRestore) { - subscriptionServiceListener.onSubscriptionRestored(sku); - } else { - subscriptionServiceListener.onSubscriptionPurchased(sku); - } - } - } - - public void updatePrices(Map iapkeyPrices) { - for (BillingServiceListener billingServiceListener : purchaseServiceListeners) { - billingServiceListener.onPricesUpdated(iapkeyPrices); - } - - for (BillingServiceListener billingServiceListener : subscriptionServiceListeners) { - billingServiceListener.onPricesUpdated(iapkeyPrices); - } - } - - public abstract void init(String key); - - public abstract void buy(Activity activity, String sku); - - public abstract void subscribe(Activity activity, String sku); - - public abstract void unsubscribe(Activity activity, String sku); - - public abstract void enableDebugLogging(boolean enable); - - @CallSuper - public void close() { - subscriptionServiceListeners.clear(); - purchaseServiceListeners.clear(); - } -} diff --git a/library/src/main/java/com/billing/BillingService.kt b/library/src/main/java/com/billing/BillingService.kt new file mode 100644 index 0000000..dd181d4 --- /dev/null +++ b/library/src/main/java/com/billing/BillingService.kt @@ -0,0 +1,75 @@ +package com.billing + +import android.app.Activity +import androidx.annotation.CallSuper + +abstract class BillingService { + + private val purchaseServiceListeners: MutableList = mutableListOf() + private val subscriptionServiceListeners: MutableList = mutableListOf() + + fun addPurchaseListener(purchaseServiceListener: PurchaseServiceListener) { + purchaseServiceListeners.add(purchaseServiceListener) + } + + fun removePurchaseListener(purchaseServiceListener: PurchaseServiceListener) { + purchaseServiceListeners.remove(purchaseServiceListener) + } + + fun addSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener) { + subscriptionServiceListeners.add(subscriptionServiceListener) + } + + fun removeSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener) { + subscriptionServiceListeners.remove(subscriptionServiceListener) + } + + /** + * @param sku - product specificator + * @param isRestore - a flag indicating whether it's a fresh purchase or restored product + */ + fun productOwned(sku: String?, isRestore: Boolean) { + for (purchaseServiceListener in purchaseServiceListeners) { + if (isRestore) { + purchaseServiceListener.onProductRestored(sku) + } else { + purchaseServiceListener.onProductPurchased(sku) + } + } + } + + /** + * @param sku - subscription specificator + * @param isRestore - a flag indicating whether it's a fresh purchase or restored subscription + */ + fun subscriptionOwned(sku: String, isRestore: Boolean) { + for (subscriptionServiceListener in subscriptionServiceListeners) { + if (isRestore) { + subscriptionServiceListener.onSubscriptionRestored(sku) + } else { + subscriptionServiceListener.onSubscriptionPurchased(sku) + } + } + } + + fun updatePrices(iapkeyPrices: Map) { + for (billingServiceListener in purchaseServiceListeners) { + billingServiceListener.onPricesUpdated(iapkeyPrices) + } + for (billingServiceListener in subscriptionServiceListeners) { + billingServiceListener.onPricesUpdated(iapkeyPrices) + } + } + + abstract fun init(key: String?) + abstract fun buy(activity: Activity, sku: String) + abstract fun subscribe(activity: Activity, sku: String) + abstract fun unsubscribe(activity: Activity, sku: String) + abstract fun enableDebugLogging(enable: Boolean) + + @CallSuper + open fun close() { + subscriptionServiceListeners.clear() + purchaseServiceListeners.clear() + } +} \ No newline at end of file From d6adca2fb0bb358d075ae06f29e78a5ae6bd5d0b Mon Sep 17 00:00:00 2001 From: Alex Dibrivnyi Date: Sat, 30 May 2020 22:11:27 +0300 Subject: [PATCH 6/6] Close 13; Call Billing library listeners on the UI thread --- .../main/java/com/billing/BillingService.kt | 24 +++++++++++++++++++ .../inapppayments/BillingTest.java | 14 +++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/com/billing/BillingService.kt b/library/src/main/java/com/billing/BillingService.kt index dd181d4..fd49e73 100644 --- a/library/src/main/java/com/billing/BillingService.kt +++ b/library/src/main/java/com/billing/BillingService.kt @@ -1,6 +1,8 @@ package com.billing import android.app.Activity +import android.os.Handler +import android.os.Looper import androidx.annotation.CallSuper abstract class BillingService { @@ -29,6 +31,12 @@ abstract class BillingService { * @param isRestore - a flag indicating whether it's a fresh purchase or restored product */ fun productOwned(sku: String?, isRestore: Boolean) { + findUiHandler().post { + productOwnedInternal(sku, isRestore) + } + } + + fun productOwnedInternal(sku: String?, isRestore: Boolean) { for (purchaseServiceListener in purchaseServiceListeners) { if (isRestore) { purchaseServiceListener.onProductRestored(sku) @@ -43,6 +51,12 @@ abstract class BillingService { * @param isRestore - a flag indicating whether it's a fresh purchase or restored subscription */ fun subscriptionOwned(sku: String, isRestore: Boolean) { + findUiHandler().post { + subscriptionOwnedInternal(sku, isRestore) + } + } + + fun subscriptionOwnedInternal(sku: String, isRestore: Boolean) { for (subscriptionServiceListener in subscriptionServiceListeners) { if (isRestore) { subscriptionServiceListener.onSubscriptionRestored(sku) @@ -53,6 +67,12 @@ abstract class BillingService { } fun updatePrices(iapkeyPrices: Map) { + findUiHandler().post { + updatePricesInternal(iapkeyPrices) + } + } + + fun updatePricesInternal(iapkeyPrices: Map) { for (billingServiceListener in purchaseServiceListeners) { billingServiceListener.onPricesUpdated(iapkeyPrices) } @@ -72,4 +92,8 @@ abstract class BillingService { subscriptionServiceListeners.clear() purchaseServiceListeners.clear() } +} + +fun findUiHandler(): Handler { + return Handler(Looper.getMainLooper()) } \ No newline at end of file diff --git a/library/src/test/java/com/eggheadgames/inapppayments/BillingTest.java b/library/src/test/java/com/eggheadgames/inapppayments/BillingTest.java index fa14237..1f802d4 100644 --- a/library/src/test/java/com/eggheadgames/inapppayments/BillingTest.java +++ b/library/src/test/java/com/eggheadgames/inapppayments/BillingTest.java @@ -31,7 +31,7 @@ public void onProductOwnedEvent_eachRegisteredListenerShouldBeTriggered() throws PurchaseServiceListener secondListener = Mockito.spy(PurchaseServiceListener.class); IAPManager.addPurchaseListener(secondListener); - IAPManager.getBillingService().productOwned(TestConstants.TEST_SKU, false); + IAPManager.getBillingService().productOwnedInternal(TestConstants.TEST_SKU, false); Mockito.verify(firstListener, Mockito.times(1)).onProductPurchased(TestConstants.TEST_SKU); Mockito.verify(secondListener, Mockito.times(1)).onProductPurchased(TestConstants.TEST_SKU); @@ -51,7 +51,7 @@ public void onProductDetailsFetched_eachRegisteredListenerShouldBeTriggered() { products.put(TestConstants.TEST_SKU, TestConstants.TEST_PRODUCT); products.put(TestConstants.TEST_SKU_1, TestConstants.TEST_PRODUCT); - IAPManager.getBillingService().updatePrices(products); + IAPManager.getBillingService().updatePricesInternal(products); Mockito.verify(firstListener, Mockito.times(1)).onPricesUpdated(products); Mockito.verify(secondListener, Mockito.times(1)).onPricesUpdated(products); @@ -69,7 +69,7 @@ public void onIapManagerInteraction_onlyRegisteredListenersShouldBeTriggered() { IAPManager.removePurchaseListener(firstListener); - IAPManager.getBillingService().productOwned(TestConstants.TEST_SKU, false); + IAPManager.getBillingService().productOwnedInternal(TestConstants.TEST_SKU, false); Mockito.verify(firstListener, Mockito.never()).onProductPurchased(Mockito.anyString()); Mockito.verify(secondListener, Mockito.times(1)).onProductPurchased(TestConstants.TEST_SKU); @@ -83,7 +83,7 @@ public void onProductPurchase_purchaseCallbackShouldBeTriggered() { PurchaseServiceListener listener = Mockito.spy(PurchaseServiceListener.class); IAPManager.addPurchaseListener(listener); - IAPManager.getBillingService().productOwned(TestConstants.TEST_SKU, false); + IAPManager.getBillingService().productOwnedInternal(TestConstants.TEST_SKU, false); Mockito.verify(listener, Mockito.times(1)).onProductPurchased(TestConstants.TEST_SKU); } @@ -95,7 +95,7 @@ public void onProductRestore_restoreCallbackShouldBeTriggered() { PurchaseServiceListener listener = Mockito.spy(PurchaseServiceListener.class); IAPManager.addPurchaseListener(listener); - IAPManager.getBillingService().productOwned(TestConstants.TEST_SKU, true); + IAPManager.getBillingService().productOwnedInternal(TestConstants.TEST_SKU, true); Mockito.verify(listener, Mockito.times(1)).onProductRestored(TestConstants.TEST_SKU); } @@ -107,7 +107,7 @@ public void onSubscriptionPurchase_purchaseCallbackShouldBeTriggered() { SubscriptionServiceListener listener = Mockito.spy(SubscriptionServiceListener.class); IAPManager.addSubscriptionListener(listener); - IAPManager.getBillingService().subscriptionOwned(TestConstants.TEST_SKU, false); + IAPManager.getBillingService().subscriptionOwnedInternal(TestConstants.TEST_SKU, false); Mockito.verify(listener, Mockito.times(1)).onSubscriptionPurchased(TestConstants.TEST_SKU); } @@ -119,7 +119,7 @@ public void onSubscriptionRestore_restoreCallbackShouldBeTriggered() { SubscriptionServiceListener listener = Mockito.spy(SubscriptionServiceListener.class); IAPManager.addSubscriptionListener(listener); - IAPManager.getBillingService().subscriptionOwned(TestConstants.TEST_SKU, true); + IAPManager.getBillingService().subscriptionOwnedInternal(TestConstants.TEST_SKU, true); Mockito.verify(listener, Mockito.times(1)).onSubscriptionRestored(TestConstants.TEST_SKU); }