Skip to content

Commit 121bd4e

Browse files
First Draft of updated modules and files.
1 parent cc8ae06 commit 121bd4e

File tree

24 files changed

+855
-18
lines changed

24 files changed

+855
-18
lines changed

Branch-SDK/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ dependencies {
3838
compileOnly("store.galaxy.samsung.installreferrer:samsung_galaxystore_install_referrer:4.0.0")
3939
// Xiaomi install referrer
4040
compileOnly("com.miui.referrer:homereferrer:1.0.0.7")
41+
//implementation(project(":BranchGooglePlayBillingV8"))
4142

42-
// Google Play Billing library
4343
compileOnly("com.android.billingclient:billing:6.0.1")
4444

45+
// Google Play Billing library
46+
4547
// In app browser experience
4648
compileOnly("androidx.browser:browser:1.8.0")
4749

Branch-SDK/src/androidTest/java/io/branch/referral/BillingGooglePlayTests.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.branch.referral
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import com.android.billingclient.api.Purchase
5+
import com.example.branchgoogleplaybillingv8.BillingV8
56
import io.branch.referral.util.CurrencyType
67

78
import org.junit.Assert
@@ -25,7 +26,7 @@ class BillingGooglePlayTests : BranchTest() {
2526
"XDFlSNC9Gqs+PPmO3xOFdLMaQ4FbsBEpTxBuOd+6adEEcz5Uovlgep+F5Xbr08+x/xzCEyNzybDYDcNg/PTzwfoK6Aeq44mocW4CPA1w/r1rdmgtwBD8nAdWIr3BbwXmcl6LYEGA6dL0N+/3zzjNzK/VWdqXazSdRyXxtlHnx8wsBFdPCBs1e9LtEwUcganA6ot0ttO2ySCKYNne2pEm2ScU+uuWZqZJ00VM7KH9pT+SKOOlSs6rRuFEvbGsoPUdybZQ0WoiXg6JD2hz9/35mQJF4Lkjh2kVgTh5MV4sCNnbMuUmhX/d09+pK2Fw6xiUng3FClOetFV9MaTtsmbz/g=="
2627
val mockPurchase = Purchase(purchaseJsonString, purchaseSignature)
2728

28-
BillingGooglePlay.getInstance().createAndLogEventForPurchase(testContext, mockPurchase, listOf(), CurrencyType.USD, 99.99, "IAP")
29+
BillingV8.getInstance().createAndLogEventForPurchase(testContext, mockPurchase, listOf(), CurrencyType.USD, 99.99, "IAP")
2930

3031
val queue = ServerRequestQueue.getInstance(testContext)
3132
val eventRequest = queue.peekAt(0)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.branch.interfaces
2+
3+
import android.content.Context
4+
5+
interface GooglePlayBillingWrapper {
6+
fun connect()
7+
fun logEventWithPurchase(context: Context, purchase: Any)
8+
}
9+

Branch-SDK/src/main/java/io/branch/referral/Branch.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static io.branch.referral.Defines.Jsonkey.EXTERNAL_BROWSER;
77
import static io.branch.referral.Defines.Jsonkey.IN_APP_WEBVIEW;
88
import static io.branch.referral.PrefHelper.isValidBranchKey;
9-
import static io.branch.referral.util.DependencyUtilsKt.billingGooglePlayClass;
109
import static io.branch.referral.util.DependencyUtilsKt.classExists;
1110

1211
import android.app.Activity;
@@ -50,6 +49,7 @@
5049
import java.util.concurrent.TimeoutException;
5150

5251
import io.branch.indexing.BranchUniversalObject;
52+
import io.branch.interfaces.GooglePlayBillingWrapper;
5353
import io.branch.interfaces.IBranchLoggingCallbacks;
5454
import io.branch.referral.Defines.PreinstallKey;
5555
import io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener;
@@ -2652,16 +2652,25 @@ public static void notifyNativeToInit(){
26522652
}
26532653
}
26542654

2655+
private GooglePlayBillingWrapper billingHandler = null;
26552656
public void logEventWithPurchase(@NonNull Context context, @NonNull Purchase purchase) {
2656-
if (classExists(billingGooglePlayClass)) {
2657-
BillingGooglePlay.Companion.getInstance().startBillingClient(succeeded -> {
2658-
if (succeeded) {
2659-
BillingGooglePlay.Companion.getInstance().logEventWithPurchase(context, purchase);
2660-
} else {
2661-
BranchLogger.e("Cannot log IAP event. Billing client setup failed"); }
2662-
return null;
2663-
});
2664-
}
2657+
// New Code Begins
2658+
billingHandler = GooglePlayBillingManager.INSTANCE.getBillingImplementation();
2659+
2660+
if (billingHandler != null) {
2661+
billingHandler.connect();
2662+
}
2663+
// New Code Ends
2664+
2665+
// if (classExists(billingGooglePlayClass)) {
2666+
// BillingV6.Companion.getInstance().startBillingClient(succeeded -> {
2667+
// if (succeeded) {
2668+
// BillingV6.Companion.getInstance().logEventWithPurchase(context, purchase);
2669+
// } else {
2670+
// BranchLogger.e("Cannot log IAP event. Billing client setup failed"); }
2671+
// return null;
2672+
// });
2673+
// }
26652674
}
26662675

26672676
/**

Branch-SDK/src/main/java/io/branch/referral/BillingGooglePlay.kt renamed to Branch-SDK/src/main/java/io/branch/referral/GooglePlayBillingLibraryV6.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package io.branch.referral
22

33
import android.content.Context
4-
import com.android.billingclient.api.*
4+
import com.android.billingclient.api.BillingClient
5+
import com.android.billingclient.api.BillingResult
6+
import com.android.billingclient.api.ProductDetails
7+
import com.android.billingclient.api.Purchase
8+
import com.android.billingclient.api.BillingClientStateListener
9+
import com.android.billingclient.api.PurchasesUpdatedListener
10+
import com.android.billingclient.api.QueryProductDetailsParams
511
import io.branch.indexing.BranchUniversalObject
6-
import io.branch.referral.util.*
12+
import io.branch.referral.util.BRANCH_STANDARD_EVENT
13+
import io.branch.referral.util.BranchContentSchema
14+
import io.branch.referral.util.BranchEvent
15+
import io.branch.referral.util.ContentMetadata
16+
import io.branch.referral.util.CurrencyType
717
import java.math.BigDecimal
818

9-
class BillingGooglePlay private constructor() {
19+
class GooglePlayBillingLibraryV6 private constructor() {
1020

1121
lateinit var billingClient: BillingClient
1222

1323
companion object {
1424
@Volatile
15-
private lateinit var instance: BillingGooglePlay
25+
private lateinit var instance: GooglePlayBillingLibraryV6
1626

17-
fun getInstance(): BillingGooglePlay {
27+
fun getInstance(): GooglePlayBillingLibraryV6 {
1828
synchronized(this) {
1929
if (!::instance.isInitialized) {
20-
instance = BillingGooglePlay()
30+
instance = GooglePlayBillingLibraryV6()
2131

2232
instance.billingClient =
2333
BillingClient.newBuilder(Branch.getInstance().applicationContext)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.branch.referral
2+
3+
import io.branch.interfaces.GooglePlayBillingWrapper
4+
5+
object GooglePlayBillingManager {
6+
fun getBillingImplementation(): GooglePlayBillingWrapper? {
7+
// Try to load V8 first
8+
try {
9+
val clazz = Class.forName("com.branch.billing.v8.BillingV8Implementation")
10+
return clazz.getConstructor().newInstance() as GooglePlayBillingWrapper
11+
} catch (e: ClassNotFoundException) {
12+
// V8 not found, try V6
13+
}
14+
15+
try {
16+
val clazz = Class.forName("com.branch.billing.v6.BillingV6Implementation")
17+
return clazz.getConstructor().newInstance() as GooglePlayBillingWrapper
18+
} catch (e: ClassNotFoundException) {
19+
// Neither version is linked in the user's app
20+
BranchLogger.e("No Billing Library dependency found!")
21+
return null
22+
}
23+
}
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
plugins {
2+
id("com.android.library")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "com.example.branchgoogleplaybillingv6"
8+
compileSdk = 34
9+
10+
defaultConfig {
11+
minSdk = 24
12+
13+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
14+
consumerProguardFiles("consumer-rules.pro")
15+
}
16+
17+
buildTypes {
18+
release {
19+
isMinifyEnabled = false
20+
proguardFiles(
21+
getDefaultProguardFile("proguard-android-optimize.txt"),
22+
"proguard-rules.pro"
23+
)
24+
}
25+
}
26+
compileOptions {
27+
sourceCompatibility = JavaVersion.VERSION_11
28+
targetCompatibility = JavaVersion.VERSION_11
29+
}
30+
kotlinOptions {
31+
jvmTarget = "11"
32+
}
33+
}
34+
35+
dependencies {
36+
implementation("androidx.core:core-ktx:1.17.0")
37+
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
38+
implementation("androidx.appcompat:appcompat:1.7.1")
39+
implementation("com.google.android.material:material:1.13.0")
40+
testImplementation("junit:junit:4.13.2")
41+
androidTestImplementation("androidx.test.ext:junit:1.3.0")
42+
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
43+
// Google Play Billing library
44+
compileOnly("com.android.billingclient:billing:6.0.1")
45+
46+
// Branch SDK Implementations
47+
implementation(project(":Branch-SDK"))
48+
}

BranchGooglePlayBillingV6/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

0 commit comments

Comments
 (0)