diff --git a/app/build.gradle b/app/build.gradle index d7b827c..8554183 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,13 +33,12 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'androidx.core:core-ktx:1.5.0' + implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.gridlayout:gridlayout:1.0.0' - implementation 'com.google.android.material:material:1.4.0-rc01' + implementation 'com.google.android.material:material:1.5.0-alpha01' implementation 'com.intuit.sdp:sdp-android:1.0.6' implementation project(':iap') implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation 'com.android.billingclient:billing-ktx:4.0.0' } diff --git a/app/src/main/java/com/limerse/iapsample/JavaSampleActivity.java b/app/src/main/java/com/limerse/iapsample/JavaSampleActivity.java index d623002..4a28f83 100644 --- a/app/src/main/java/com/limerse/iapsample/JavaSampleActivity.java +++ b/app/src/main/java/com/limerse/iapsample/JavaSampleActivity.java @@ -20,11 +20,9 @@ class JavaSampleActivity extends AppCompatActivity { - private ActivityMainBinding binding; - protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - binding = ActivityMainBinding.inflate(getLayoutInflater()); + ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); List nonConsumablesList = Collections.singletonList("lifetime"); diff --git a/app/src/main/java/com/limerse/iapsample/KotlinSampleActivity.kt b/app/src/main/java/com/limerse/iapsample/KotlinSampleActivity.kt index 69546c9..a6f03bb 100644 --- a/app/src/main/java/com/limerse/iapsample/KotlinSampleActivity.kt +++ b/app/src/main/java/com/limerse/iapsample/KotlinSampleActivity.kt @@ -40,7 +40,7 @@ class KotlinSampleActivity : AppCompatActivity() { override fun onProductPurchased(purchaseInfo: DataWrappers.PurchaseInfo) { when (purchaseInfo.sku) { "base" -> { - + purchaseInfo.orderId } "moderate" -> { diff --git a/build.gradle b/build.gradle index 0605678..ea6ee92 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.5.10' - ext.kotlin_coroutines_version = '1.5.0-native-mt' + ext.kotlin_version = '1.5.21' + ext.kotlin_coroutines_version = '1.5.1-native-mt' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/iap/build.gradle b/iap/build.gradle index 4deed52..c9b52a3 100644 --- a/iap/build.gradle +++ b/iap/build.gradle @@ -7,9 +7,9 @@ android { compileSdkVersion 30 defaultConfig { - minSdkVersion 17 + minSdkVersion 16 targetSdkVersion 30 - versionCode 17 + versionCode 16 versionName "1.1.6" } @@ -32,5 +32,5 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version" testImplementation 'junit:junit:4.13.2' - testImplementation 'org.mockito:mockito-core:3.10.0' + testImplementation 'org.mockito:mockito-core:3.11.2' } diff --git a/iap/src/main/java/com/limerse/iap/BillingService.kt b/iap/src/main/java/com/limerse/iap/BillingService.kt index 42e0856..dbb41c5 100644 --- a/iap/src/main/java/com/limerse/iap/BillingService.kt +++ b/iap/src/main/java/com/limerse/iap/BillingService.kt @@ -10,11 +10,12 @@ import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -class BillingService(private val context: Context, - private val nonConsumableKeys: List, - private val consumableKeys: List, - private val subscriptionSkuKeys: List) - : IBillingService(), PurchasesUpdatedListener, BillingClientStateListener, AcknowledgePurchaseResponseListener { +class BillingService( + private val context: Context, + private val nonConsumableKeys: List, + private val consumableKeys: List, + private val subscriptionSkuKeys: List +) : IBillingService(), PurchasesUpdatedListener, BillingClientStateListener, AcknowledgePurchaseResponseListener { private lateinit var mBillingClient: BillingClient private var decodedKey: String? = null @@ -80,7 +81,7 @@ class BillingService(private val context: Context, sku.toSkuDetails(type) { skuDetails -> if (skuDetails != null) { val purchaseParams = BillingFlowParams.newBuilder() - .setSkuDetails(skuDetails).build() + .setSkuDetails(skuDetails).build() mBillingClient.launchBillingFlow(activity, purchaseParams) } } @@ -130,10 +131,10 @@ class BillingService(private val context: Context, BillingClient.BillingResponseCode.DEVELOPER_ERROR -> Log.e( TAG, "onPurchasesUpdated: Developer error means that Google Play " + - "does not recognize the configuration. If you are just getting started, " + - "make sure you have configured the application correctly in the " + - "Google Play Console. The SKU product ID must match and the APK you " + - "are using must be signed with release keys." + "does not recognize the configuration. If you are just getting started, " + + "make sure you have configured the application correctly in the " + + "Google Play Console. The SKU product ID must match and the APK you " + + "are using must be signed with release keys." ) } } @@ -169,7 +170,7 @@ class BillingService(private val context: Context, } } } - else{ + else{ productOwned(getPurchaseInfo(purchase), isRestore) } } @@ -181,13 +182,13 @@ class BillingService(private val context: Context, // Acknowledge the purchase if it hasn't already been acknowledged. if (!purchase.isAcknowledged) { val acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder() - .setPurchaseToken(purchase.purchaseToken).build() + .setPurchaseToken(purchase.purchaseToken).build() mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, this) } } else { Log.e( TAG, "processPurchases failed. purchase: $purchase " + - "purchaseState: ${purchase.purchaseState} isSkuReady: ${purchase.skus[0].isSkuReady()}") + "purchaseState: ${purchase.purchaseState} isSkuReady: ${purchase.skus[0].isSkuReady()}") } } } else { diff --git a/iap/src/test/java/com/limerse/iap/BillingTest.kt b/iap/src/test/java/com/limerse/iap/BillingTest.kt index 3e4adb5..fc1f8d1 100644 --- a/iap/src/test/java/com/limerse/iap/BillingTest.kt +++ b/iap/src/test/java/com/limerse/iap/BillingTest.kt @@ -1,4 +1,5 @@ import android.content.Context +import com.limerse.iap.DataWrappers import com.limerse.iap.IapConnector import com.limerse.iap.PurchaseServiceListener import com.limerse.iap.SubscriptionServiceListener @@ -26,11 +27,11 @@ class BillingTest { ) iapConnector.addPurchaseListener(secondListener) iapConnector.getBillingService() - .productOwnedInternal(TestConstants.TEST_SKU, false) + .productOwnedInternal(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU), false) Mockito.verify(firstListener, Mockito.times(1)) - .onProductPurchased(TestConstants.TEST_SKU) + .onProductPurchased(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU)) Mockito.verify(secondListener, Mockito.times(1)) - .onProductPurchased(TestConstants.TEST_SKU) + .onProductPurchased(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU)) } @Test @@ -64,10 +65,10 @@ class BillingTest { ) iapConnector.addPurchaseListener(secondListener) iapConnector.removePurchaseListener(firstListener) - iapConnector.getBillingService().productOwnedInternal(TestConstants.Companion.TEST_SKU, false) - Mockito.verify(firstListener, Mockito.never()).onProductPurchased(Mockito.anyString()) + iapConnector.getBillingService().productOwnedInternal(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU), false) + Mockito.verify(firstListener, Mockito.never()).onProductPurchased(Mockito.any()) Mockito.verify(secondListener, Mockito.times(1)) - .onProductPurchased(TestConstants.Companion.TEST_SKU) + .onProductPurchased(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU)) } @Test @@ -77,9 +78,9 @@ class BillingTest { PurchaseServiceListener::class.java ) iapConnector.addPurchaseListener(listener) - iapConnector.getBillingService().productOwnedInternal(TestConstants.Companion.TEST_SKU, false) + iapConnector.getBillingService().productOwnedInternal(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU), false) Mockito.verify(listener, Mockito.times(1)) - .onProductPurchased(TestConstants.Companion.TEST_SKU) + .onProductPurchased(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU)) } @Test @@ -89,9 +90,9 @@ class BillingTest { PurchaseServiceListener::class.java ) iapConnector.addPurchaseListener(listener) - iapConnector.getBillingService().productOwnedInternal(TestConstants.TEST_SKU, true) + iapConnector.getBillingService().productOwnedInternal(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU), true) Mockito.verify(listener, Mockito.times(1)) - .onProductRestored(TestConstants.TEST_SKU) + .onProductRestored(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU)) } @Test @@ -102,9 +103,9 @@ class BillingTest { ) iapConnector.addSubscriptionListener(listener) iapConnector.getBillingService() - .subscriptionOwnedInternal(TestConstants.TEST_SKU, false) + .subscriptionOwnedInternal(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU), false) Mockito.verify(listener, Mockito.times(1)) - .onSubscriptionPurchased(TestConstants.TEST_SKU) + .onSubscriptionPurchased(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU)) } @Test @@ -115,8 +116,8 @@ class BillingTest { ) iapConnector.addSubscriptionListener(listener) iapConnector.getBillingService() - .subscriptionOwnedInternal(TestConstants.TEST_SKU, true) + .subscriptionOwnedInternal(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU), true) Mockito.verify(listener, Mockito.times(1)) - .onSubscriptionRestored(TestConstants.TEST_SKU) + .onSubscriptionRestored(DataWrappers.PurchaseInfo(sku = TestConstants.TEST_SKU)) } } \ No newline at end of file