Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Branch-SDK/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ dependencies {
compileOnly("store.galaxy.samsung.installreferrer:samsung_galaxystore_install_referrer:4.0.0")
// Xiaomi install referrer
compileOnly("com.miui.referrer:homereferrer:1.0.0.7")
//implementation(project(":BranchGooglePlayBillingV8"))

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

// Google Play Billing library

// In app browser experience
compileOnly("androidx.browser:browser:1.8.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.branch.referral

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.billingclient.api.Purchase
import com.example.branchgoogleplaybillingv8.BillingV8
import io.branch.referral.util.CurrencyType

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

BillingGooglePlay.getInstance().createAndLogEventForPurchase(testContext, mockPurchase, listOf(), CurrencyType.USD, 99.99, "IAP")
BillingV8.getInstance().createAndLogEventForPurchase(testContext, mockPurchase, listOf(), CurrencyType.USD, 99.99, "IAP")

val queue = ServerRequestQueue.getInstance(testContext)
val eventRequest = queue.peekAt(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.branch.interfaces

import android.content.Context

interface GooglePlayBillingWrapper {
fun connect()
fun logEventWithPurchase(context: Context, purchase: Any)
}

29 changes: 19 additions & 10 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static io.branch.referral.Defines.Jsonkey.EXTERNAL_BROWSER;
import static io.branch.referral.Defines.Jsonkey.IN_APP_WEBVIEW;
import static io.branch.referral.PrefHelper.isValidBranchKey;
import static io.branch.referral.util.DependencyUtilsKt.billingGooglePlayClass;
import static io.branch.referral.util.DependencyUtilsKt.classExists;

import android.app.Activity;
Expand Down Expand Up @@ -50,6 +49,7 @@
import java.util.concurrent.TimeoutException;

import io.branch.indexing.BranchUniversalObject;
import io.branch.interfaces.GooglePlayBillingWrapper;
import io.branch.interfaces.IBranchLoggingCallbacks;
import io.branch.referral.Defines.PreinstallKey;
import io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener;
Expand Down Expand Up @@ -2652,16 +2652,25 @@ public static void notifyNativeToInit(){
}
}

private GooglePlayBillingWrapper billingHandler = null;
public void logEventWithPurchase(@NonNull Context context, @NonNull Purchase purchase) {
if (classExists(billingGooglePlayClass)) {
BillingGooglePlay.Companion.getInstance().startBillingClient(succeeded -> {
if (succeeded) {
BillingGooglePlay.Companion.getInstance().logEventWithPurchase(context, purchase);
} else {
BranchLogger.e("Cannot log IAP event. Billing client setup failed"); }
return null;
});
}
// New Code Begins
billingHandler = GooglePlayBillingManager.INSTANCE.getBillingImplementation();

if (billingHandler != null) {
billingHandler.connect();
}
// New Code Ends

// if (classExists(billingGooglePlayClass)) {
// BillingV6.Companion.getInstance().startBillingClient(succeeded -> {
// if (succeeded) {
// BillingV6.Companion.getInstance().logEventWithPurchase(context, purchase);
// } else {
// BranchLogger.e("Cannot log IAP event. Billing client setup failed"); }
// return null;
// });
// }
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package io.branch.referral

import android.content.Context
import com.android.billingclient.api.*
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingResult
import com.android.billingclient.api.ProductDetails
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.BillingClientStateListener
import com.android.billingclient.api.PurchasesUpdatedListener
import com.android.billingclient.api.QueryProductDetailsParams
import io.branch.indexing.BranchUniversalObject
import io.branch.referral.util.*
import io.branch.referral.util.BRANCH_STANDARD_EVENT
import io.branch.referral.util.BranchContentSchema
import io.branch.referral.util.BranchEvent
import io.branch.referral.util.ContentMetadata
import io.branch.referral.util.CurrencyType
import java.math.BigDecimal

class BillingGooglePlay private constructor() {
class GooglePlayBillingLibraryV6 private constructor() {

lateinit var billingClient: BillingClient

companion object {
@Volatile
private lateinit var instance: BillingGooglePlay
private lateinit var instance: GooglePlayBillingLibraryV6

fun getInstance(): BillingGooglePlay {
fun getInstance(): GooglePlayBillingLibraryV6 {
synchronized(this) {
if (!::instance.isInitialized) {
instance = BillingGooglePlay()
instance = GooglePlayBillingLibraryV6()

instance.billingClient =
BillingClient.newBuilder(Branch.getInstance().applicationContext)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.branch.referral

import io.branch.interfaces.GooglePlayBillingWrapper

object GooglePlayBillingManager {
fun getBillingImplementation(): GooglePlayBillingWrapper? {
// Try to load V8 first
try {
val clazz = Class.forName("com.branch.billing.v8.BillingV8Implementation")
return clazz.getConstructor().newInstance() as GooglePlayBillingWrapper
} catch (e: ClassNotFoundException) {
// V8 not found, try V6
}

try {
val clazz = Class.forName("com.branch.billing.v6.BillingV6Implementation")
return clazz.getConstructor().newInstance() as GooglePlayBillingWrapper
} catch (e: ClassNotFoundException) {
// Neither version is linked in the user's app
BranchLogger.e("No Billing Library dependency found!")
return null
}
}
}
1 change: 1 addition & 0 deletions BranchGooglePlayBillingV8/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
48 changes: 48 additions & 0 deletions BranchGooglePlayBillingV8/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "com.example.branchgoogleplaybillingv8"
compileSdk = 34

defaultConfig {
minSdk = 24

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}

dependencies {
implementation("androidx.core:core-ktx:1.17.0")
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation("androidx.appcompat:appcompat:1.7.1")
implementation("com.google.android.material:material:1.13.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.3.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
// Google Play Billing library
compileOnly("com.android.billingclient:billing:8.0.0")

// Branch SDK Implementations
implementation(project(":Branch-SDK"))
}
Empty file.
21 changes: 21 additions & 0 deletions BranchGooglePlayBillingV8/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.branchgoogleplaybillingv8

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.branchgoogleplaybillingv8.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions BranchGooglePlayBillingV8/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading
Loading