-
Notifications
You must be signed in to change notification settings - Fork 160
Emt 2431 - Draft PR #1323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Emt 2431 - Draft PR #1323
Changes from 4 commits
9856981
a6fc3ca
6d1a11a
9299092
02fdb12
f05eac3
dfcdcf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,12 @@ jacoco { | |
| toolVersion = "0.8.10" | ||
| } | ||
|
|
||
| //configurations.all { | ||
| // resolutionStrategy { | ||
| // force("com.android.billingclient:billing:8.0.0") | ||
| // } | ||
| //} | ||
|
|
||
| dependencies { | ||
| implementation(fileTree(mapOf("dir" to "libs", "include" to "*.jar"))) | ||
| implementation(kotlin("stdlib")) | ||
|
|
@@ -41,7 +47,6 @@ dependencies { | |
|
|
||
| // Google Play Billing library | ||
| compileOnly("com.android.billingclient:billing:6.0.1") | ||
|
|
||
| // In app browser experience | ||
| compileOnly("androidx.browser:browser:1.8.0") | ||
|
|
||
|
|
@@ -136,6 +141,18 @@ android { | |
| signing { | ||
| isRequired = isReleaseBuild() | ||
| } | ||
|
|
||
| flavorDimensions.add("billing") | ||
|
||
|
|
||
| productFlavors { | ||
| create("billing_v6v7") { | ||
| dimension = "billing" | ||
| } | ||
| create("billing_v8") { | ||
| dimension = "billing" | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| fun getRepositoryUsername(): String { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| package io.branch.referral | ||
|
|
||
| import android.content.Context | ||
| import com.android.billingclient.api.* | ||
| import io.branch.indexing.BranchUniversalObject | ||
| import io.branch.referral.util.* | ||
| import java.math.BigDecimal | ||
|
|
||
| class BillingGooglePlayV6V7 : BillingGooglePlayInterface { | ||
| lateinit var billingClient: BillingClient | ||
|
|
||
| companion object { | ||
| @Volatile | ||
| private lateinit var instance: BillingGooglePlay | ||
|
|
||
| fun getInstance(): BillingGooglePlay { | ||
| synchronized(this) { | ||
| if (!::instance.isInitialized) { | ||
| instance = BillingGooglePlay() | ||
|
|
||
| instance.billingClient = | ||
| BillingClient.newBuilder(Branch.getInstance().applicationContext) | ||
| .setListener(instance.purchasesUpdatedListener) | ||
| .enablePendingPurchases() | ||
| .build() | ||
| } | ||
| return instance | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| override fun startBillingClient(callback: (Boolean) -> Unit) { | ||
| if (billingClient.isReady) { | ||
| BranchLogger.v("Billing Client has already been started..") | ||
| callback(true) | ||
| } else { | ||
| billingClient.startConnection(object : BillingClientStateListener { | ||
| override fun onBillingSetupFinished(billingResult: BillingResult) { | ||
| if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { | ||
| BranchLogger.v("Billing Client setup finished.") | ||
| callback(true) | ||
| } else { | ||
| val errorMessage = | ||
| "Billing Client setup failed with error: ${billingResult.debugMessage}" | ||
| BranchLogger.e(errorMessage) | ||
| callback(false) | ||
| } | ||
| } | ||
|
|
||
| override fun onBillingServiceDisconnected() { | ||
| BranchLogger.w("Billing Client disconnected") | ||
| callback(false) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| override fun logEventWithPurchase( | ||
| context: Context, | ||
| purchase: Purchase | ||
| ) { | ||
| val productIds = purchase.products | ||
| val productList: MutableList<QueryProductDetailsParams.Product> = ArrayList() | ||
| val subsList: MutableList<QueryProductDetailsParams.Product> = ArrayList() | ||
|
|
||
| for (productId: String? in productIds) { | ||
| val inAppProduct = QueryProductDetailsParams.Product.newBuilder() | ||
| .setProductId(productId!!) | ||
| .setProductType(BillingClient.ProductType.INAPP) | ||
| .build() | ||
| productList.add(inAppProduct) | ||
|
|
||
| val subsProduct = QueryProductDetailsParams.Product.newBuilder() | ||
| .setProductId(productId) | ||
| .setProductType(BillingClient.ProductType.SUBS) | ||
| .build() | ||
| subsList.add(subsProduct) | ||
| } | ||
|
|
||
| val queryProductDetailsParams = QueryProductDetailsParams.newBuilder() | ||
| .setProductList(productList) | ||
| .build() | ||
|
|
||
| val querySubsProductDetailsParams = QueryProductDetailsParams.newBuilder() | ||
| .setProductList(subsList) | ||
| .build() | ||
|
|
||
| billingClient.queryProductDetailsAsync( | ||
| querySubsProductDetailsParams | ||
| ) { billingResult: BillingResult, subsProductDetailsList: List<ProductDetails?> -> | ||
| if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { | ||
| val contentItemBUOs: MutableList<BranchUniversalObject> = | ||
| ArrayList() | ||
| var currency: CurrencyType = CurrencyType.USD | ||
| var revenue = 0.00 | ||
|
|
||
| for (product: ProductDetails? in subsProductDetailsList) { | ||
| val buo: BranchUniversalObject = createBUOWithSubsProductDetails(product) | ||
| contentItemBUOs.add(buo) | ||
|
|
||
| revenue += buo.contentMetadata.price | ||
| currency = buo.contentMetadata.currencyType | ||
| } | ||
|
|
||
| if (contentItemBUOs.isNotEmpty()) { | ||
| createAndLogEventForPurchase( | ||
| context, | ||
| purchase, | ||
| contentItemBUOs, | ||
| currency, | ||
| revenue, | ||
| BillingClient.ProductType.SUBS | ||
| ) | ||
| } | ||
| } | ||
| else { | ||
| BranchLogger.e("Failed to query subscriptions. Error: " + billingResult.debugMessage) | ||
| } | ||
| } | ||
|
|
||
| billingClient.queryProductDetailsAsync( | ||
| queryProductDetailsParams | ||
| ) { billingResult: BillingResult, productDetailsList: List<ProductDetails?> -> | ||
| if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { | ||
|
|
||
| val contentItemBUOs: MutableList<BranchUniversalObject> = | ||
| ArrayList() | ||
| var currency: CurrencyType = CurrencyType.USD | ||
| var revenue = 0.00 | ||
| val quantity: Int = purchase.quantity | ||
|
|
||
| for (product: ProductDetails? in productDetailsList) { | ||
| val buo: BranchUniversalObject = | ||
| createBUOWithInAppProductDetails(product, quantity) | ||
| contentItemBUOs.add(buo) | ||
|
|
||
| revenue += (BigDecimal(buo.contentMetadata.price.toString()) * BigDecimal( | ||
| quantity.toString() | ||
| )).toDouble() | ||
| currency = buo.contentMetadata.currencyType | ||
| } | ||
|
|
||
| if (contentItemBUOs.isNotEmpty()) { | ||
| createAndLogEventForPurchase( | ||
| context, | ||
| purchase, | ||
| contentItemBUOs, | ||
| currency, | ||
| revenue, | ||
| BillingClient.ProductType.INAPP | ||
| ) | ||
| } | ||
| } | ||
| else { | ||
| BranchLogger.e("Failed to query subscriptions. Error: " + billingResult.debugMessage) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| plugins { | ||
|
||
| id 'com.android.library' | ||
| id 'org.jetbrains.kotlin.android' | ||
| } | ||
|
|
||
| android { | ||
| compileSdk ANDROID_BUILD_SDK_VERSION_COMPILE.toInt() // Or your project's compile SDK version | ||
|
|
||
| defaultConfig { | ||
| minSdk = ANDROID_BUILD_SDK_VERSION_MINIMUM.toInt() | ||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| consumerProguardFiles("proguard-consumer.txt") | ||
| } | ||
|
|
||
| // This section is for library-specific configurations | ||
| buildTypes { | ||
| fun String.wrapInQuotes(): String { | ||
| return "\"$this\"" | ||
| } | ||
|
|
||
| debug { | ||
| enableUnitTestCoverage = true | ||
| enableAndroidTestCoverage = true | ||
| buildConfigField("long", "VERSION_CODE", VERSION_CODE) | ||
| buildConfigField("String", "VERSION_NAME", VERSION_NAME.wrapInQuotes()) | ||
| } | ||
| release { | ||
| buildConfigField("long", "VERSION_CODE", VERSION_CODE) | ||
| buildConfigField("String", "VERSION_NAME", VERSION_NAME.wrapInQuotes()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| // This is the older V6 version of the billing library | ||
| implementation 'com.android.billingclient:billing:6.0.1' | ||
|
|
||
| // Add any other dependencies specific to this module | ||
| implementation 'androidx.core:core-ktx:1.9.0' | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package io.branch.referral | ||
|
|
||
| import android.content.Context | ||
| import com.android.billingclient.api.* | ||
|
|
||
| class BillingGooglePlayV8 : BillingGooglePlayInterface{ | ||
| override fun startBillingClient(context: Context?) { | ||
| TODO("Not yet implemented") | ||
| } | ||
|
|
||
| override fun logEventWithPurchase( | ||
| context: Context?, | ||
| purchase: Purchase? | ||
| ) { | ||
| TODO("Not yet implemented") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| plugins { | ||
| id 'com.android.library' | ||
| id 'org.jetbrains.kotlin.android' | ||
| } | ||
|
|
||
| android { | ||
| compileSdk ANDROID_BUILD_SDK_VERSION_COMPILE.toInt() // Or your project's compile SDK version | ||
|
|
||
| defaultConfig { | ||
| minSdk = ANDROID_BUILD_SDK_VERSION_MINIMUM.toInt() | ||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| consumerProguardFiles("proguard-consumer.txt") | ||
| } | ||
|
|
||
| // This section is for library-specific configurations | ||
| buildTypes { | ||
| fun String.wrapInQuotes(): String { | ||
| return "\"$this\"" | ||
| } | ||
|
|
||
| debug { | ||
| enableUnitTestCoverage = true | ||
| enableAndroidTestCoverage = true | ||
| buildConfigField("long", "VERSION_CODE", VERSION_CODE) | ||
| buildConfigField("String", "VERSION_NAME", VERSION_NAME.wrapInQuotes()) | ||
| } | ||
| release { | ||
| buildConfigField("long", "VERSION_CODE", VERSION_CODE) | ||
| buildConfigField("String", "VERSION_NAME", VERSION_NAME.wrapInQuotes()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| // This is the older V6 version of the billing library | ||
| implementation 'com.android.billingclient:billing:8.0.0' | ||
|
|
||
| // Add any other dependencies specific to this module | ||
| implementation 'androidx.core:core-ktx:1.9.0' | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.branch.referral; | ||
|
|
||
| import io.branch.referral.BillingGooglePlayV6V7; | ||
| import java.lang.ClassNotFoundException; | ||
|
|
||
| public class BillingGooglePlayReflection { | ||
| public static BillingGooglePlayInterface getBillingLibraryVersion() { | ||
| return new BillingGooglePlayV6V7(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.branch.referral; | ||
|
|
||
| import io.branch.referral.BillingGooglePlayV8; | ||
| import java.lang.ClassNotFoundException; | ||
|
|
||
| public class BillingGooglePlayReflection { | ||
| public static BillingGooglePlayInterface getBillingLibraryVersion() { | ||
| return new BillingGooglePlayV8(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package io.branch.referral; | ||
|
|
||
| import android.content.Context; | ||
| import io.branch.referral.util.*; | ||
|
|
||
| import com.android.billingclient.api.Purchase; | ||
|
|
||
| public interface BillingGooglePlayInterface { | ||
| fun logEventWithPurchase(context: Context, purchase: Purchase); | ||
| fun startBillingClient(callback: (Boolean) -> Unit); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted