Skip to content

Commit 3e022d5

Browse files
committed
Add Galaxy Store wrapper dependency for hybrid SDKs
1 parent 091f902 commit 3e022d5

12 files changed

Lines changed: 156 additions & 0 deletions

File tree

android/api-tests/src/test/java/com/revenuecat/apitests/kotlin/CommonApiTests.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ private class CommonApiTests {
418418
diagnosticsEnabled: Boolean?,
419419
automaticDeviceIdentifierCollectionEnabled: Boolean?,
420420
preferredLocale: String?,
421+
galaxyBillingMode: String?,
421422
) {
422423
configure(context, apiKey, appUserID, purchasesAreCompletedBy, platformInfo)
423424
configure(context, apiKey, appUserID, purchasesAreCompletedBy, platformInfo, store, dangerousSettings)
@@ -472,6 +473,7 @@ private class CommonApiTests {
472473
diagnosticsEnabled = diagnosticsEnabled,
473474
automaticDeviceIdentifierCollectionEnabled = automaticDeviceIdentifierCollectionEnabled,
474475
preferredLocale = preferredLocale,
476+
galaxyBillingMode = galaxyBillingMode,
475477
)
476478
}
477479

android/gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
2727
purchases-bc8 = { module = "com.revenuecat.purchases:purchases", version.ref = "purchases" }
2828
purchases-ui-bc8 = { module = "com.revenuecat.purchases:purchases-ui", version.ref = "purchases" }
2929
purchases-amazon-bc8 = { module = "com.revenuecat.purchases:purchases-store-amazon", version.ref = "purchases" }
30+
purchases-galaxy-bc8 = { module = "com.revenuecat.purchases:purchases-store-galaxy", version.ref = "purchases" }
3031
purchases-bc7 = { module = "com.revenuecat.purchases:purchases-bc7", version.ref = "purchases" }
3132
purchases-ui-bc7 = { module = "com.revenuecat.purchases:purchases-ui-bc7", version.ref = "purchases" }
3233
purchases-amazon-bc7 = { module = "com.revenuecat.purchases:purchases-store-amazon-bc7", version.ref = "purchases" }
34+
purchases-galaxy-bc7 = { module = "com.revenuecat.purchases:purchases-store-galaxy-bc7", version.ref = "purchases" }
3335
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
3436

3537
[plugins]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
2+
plugins {
3+
alias(libs.plugins.androidLibrary)
4+
alias(libs.plugins.kotlinAndroid)
5+
alias(libs.plugins.mavenPublish)
6+
alias(libs.plugins.detekt)
7+
}
8+
9+
dependencies {
10+
detektPlugins(libs.detekt.formatting)
11+
}
12+
13+
detekt {
14+
buildUponDefaultConfig = true
15+
autoCorrect = true
16+
}
17+
18+
android {
19+
namespace = "com.revenuecat.purchases.hybridcommon.galaxy"
20+
compileSdk = 34
21+
22+
flavorDimensions += "billingclient"
23+
24+
productFlavors {
25+
create("bc8") {
26+
dimension = "billingclient"
27+
isDefault = true
28+
}
29+
create("bc7") {
30+
dimension = "billingclient"
31+
}
32+
}
33+
34+
defaultConfig {
35+
minSdk = 23
36+
37+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
38+
consumerProguardFiles("consumer-rules.pro")
39+
}
40+
41+
buildTypes {
42+
release {
43+
isMinifyEnabled = false
44+
proguardFiles(
45+
getDefaultProguardFile("proguard-android-optimize.txt"),
46+
"proguard-rules.pro"
47+
)
48+
}
49+
}
50+
compileOptions {
51+
sourceCompatibility = JavaVersion.VERSION_1_8
52+
targetCompatibility = JavaVersion.VERSION_1_8
53+
}
54+
kotlinOptions {
55+
jvmTarget = "1.8"
56+
languageVersion = libs.versions.kotlinLanguage.get()
57+
apiVersion = libs.versions.kotlinLanguage.get()
58+
}
59+
}
60+
61+
dependencies {
62+
api(project(":hybridcommon"))
63+
"bc8Api"(libs.purchases.galaxy.bc8)
64+
"bc7Api"(libs.purchases.galaxy.bc7)
65+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
POM_NAME=purchases-hybrid-common-store-galaxy
2+
POM_ARTIFACT_ID=purchases-hybrid-common-store-galaxy
3+
POM_PACKAGING=aar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />

android/hybridcommon/src/main/java/com/revenuecat/purchases/hybridcommon/common.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import com.revenuecat.purchases.ads.events.types.AdOpenedData
3737
import com.revenuecat.purchases.ads.events.types.AdRevenueData
3838
import com.revenuecat.purchases.ads.events.types.AdRevenuePrecision
3939
import com.revenuecat.purchases.common.PlatformInfo
40+
import com.revenuecat.purchases.galaxy.GalaxyBillingMode
4041
import com.revenuecat.purchases.getAmazonLWAConsentStatusWith
4142
import com.revenuecat.purchases.getCustomerInfoWith
4243
import com.revenuecat.purchases.getOfferingsWith
@@ -980,6 +981,7 @@ fun showInAppMessagesIfNeeded(activity: Activity?, inAppMessageTypes: List<InApp
980981
}
981982
}
982983

984+
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
983985
@Suppress("LongParameterList")
984986
@JvmOverloads
985987
fun configure(
@@ -996,6 +998,7 @@ fun configure(
996998
diagnosticsEnabled: Boolean? = null,
997999
automaticDeviceIdentifierCollectionEnabled: Boolean? = null,
9981000
preferredLocale: String? = null,
1001+
galaxyBillingMode: String? = null,
9991002
) {
10001003
Purchases.platformInfo = platformInfo
10011004

@@ -1017,6 +1020,16 @@ fun configure(
10171020
diagnosticsEnabled?.let { diagnosticsEnabled(it) }
10181021
automaticDeviceIdentifierCollectionEnabled?.let { automaticDeviceIdentifierCollectionEnabled(it) }
10191022
preferredLocale?.let { preferredUILocaleOverride(it) }
1023+
if (store == Store.GALAXY) {
1024+
when (galaxyBillingMode) {
1025+
null, "PRODUCTION" -> galaxyBillingMode(GalaxyBillingMode.PRODUCTION)
1026+
"TEST" -> galaxyBillingMode(GalaxyBillingMode.TEST)
1027+
"ALWAYS_FAIL" -> galaxyBillingMode(GalaxyBillingMode.ALWAYS_FAIL)
1028+
else -> {
1029+
warnLog("Attempted to configure with unknown Galaxy billing mode: $galaxyBillingMode.")
1030+
}
1031+
}
1032+
}
10201033
}.also { Purchases.configure(it.build()) }
10211034
}
10221035

android/hybridcommon/src/test/java/com/revenuecat/purchases/hybridcommon/ConfiguringUnitTests.kt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import android.app.Application
44
import android.content.Context
55
import com.revenuecat.purchases.DangerousSettings
66
import com.revenuecat.purchases.EntitlementVerificationMode
7+
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI
78
import com.revenuecat.purchases.Purchases
89
import com.revenuecat.purchases.PurchasesAreCompletedBy
910
import com.revenuecat.purchases.PurchasesConfiguration
1011
import com.revenuecat.purchases.Store
1112
import com.revenuecat.purchases.common.PlatformInfo
13+
import com.revenuecat.purchases.galaxy.GalaxyBillingMode
1214
import io.mockk.CapturingSlot
1315
import io.mockk.every
1416
import io.mockk.mockk
@@ -19,6 +21,7 @@ import org.junit.jupiter.api.Test
1921
import kotlin.test.assertEquals
2022
import kotlin.test.assertTrue
2123

24+
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
2225
internal class ConfiguringUnitTests {
2326
private val mockPurchases = mockk<Purchases>()
2427
private val mockContext = mockk<Context>(relaxed = true)
@@ -226,6 +229,60 @@ internal class ConfiguringUnitTests {
226229
assertEquals(expectedLocale, purchasesConfigurationSlot.captured.preferredUILocaleOverride)
227230
}
228231

232+
@Test
233+
fun `calling configure with Galaxy store configures the Android SDK with Galaxy store`() {
234+
configure(
235+
context = mockContext,
236+
apiKey = "api_key",
237+
appUserID = "appUserID",
238+
purchasesAreCompletedBy = PurchasesAreCompletedBy.REVENUECAT.name,
239+
platformInfo = expectedPlatformInfo,
240+
store = Store.GALAXY,
241+
)
242+
assertEquals(Store.GALAXY, purchasesConfigurationSlot.captured.store)
243+
}
244+
245+
@Test
246+
fun `calling configure with Galaxy store defaults Galaxy billing mode to production`() {
247+
configure(
248+
context = mockContext,
249+
apiKey = "api_key",
250+
appUserID = "appUserID",
251+
purchasesAreCompletedBy = PurchasesAreCompletedBy.REVENUECAT.name,
252+
platformInfo = expectedPlatformInfo,
253+
store = Store.GALAXY,
254+
)
255+
assertEquals(GalaxyBillingMode.PRODUCTION, purchasesConfigurationSlot.captured.galaxyBillingMode)
256+
}
257+
258+
@Test
259+
fun `calling configure with Galaxy billing mode test forwards it to Android SDK`() {
260+
configure(
261+
context = mockContext,
262+
apiKey = "api_key",
263+
appUserID = "appUserID",
264+
purchasesAreCompletedBy = PurchasesAreCompletedBy.REVENUECAT.name,
265+
platformInfo = expectedPlatformInfo,
266+
store = Store.GALAXY,
267+
galaxyBillingMode = "TEST",
268+
)
269+
assertEquals(GalaxyBillingMode.TEST, purchasesConfigurationSlot.captured.galaxyBillingMode)
270+
}
271+
272+
@Test
273+
fun `calling configure with Galaxy billing mode always fail forwards it to Android SDK`() {
274+
configure(
275+
context = mockContext,
276+
apiKey = "api_key",
277+
appUserID = "appUserID",
278+
purchasesAreCompletedBy = PurchasesAreCompletedBy.REVENUECAT.name,
279+
platformInfo = expectedPlatformInfo,
280+
store = Store.GALAXY,
281+
galaxyBillingMode = "ALWAYS_FAIL",
282+
)
283+
assertEquals(GalaxyBillingMode.ALWAYS_FAIL, purchasesConfigurationSlot.captured.galaxyBillingMode)
284+
}
285+
229286
private fun assertConfiguration(
230287
purchasesConfigurationSlot: CapturingSlot<PurchasesConfiguration>,
231288
expectedContext: Context,

0 commit comments

Comments
 (0)