Skip to content

Commit

Permalink
CustomEntitlementComputation: Configure method for customEntitlementC…
Browse files Browse the repository at this point in the history
…omputation mode (#1168)

### Description
Add new `configureInCustomEntitlementsComputationMode` method to
configure the SDK in this mode. This will replace configuring the SDK
with a special `PurchasesConfiguration` object simplifying configuration
for this mode
  • Loading branch information
tonidero authored Jul 24, 2023
1 parent 3a43a81 commit 9d3e882
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import android.content.Context;

import com.revenuecat.purchases.EntitlementVerificationMode;
import com.revenuecat.purchases.Purchases;
import com.revenuecat.purchases.PurchasesConfiguration;

import java.util.concurrent.ExecutorService;

Expand All @@ -13,12 +11,7 @@ final class PurchasesAPI {

static void checkConfiguration(final Context context,
final ExecutorService executorService) {
PurchasesConfiguration build = new PurchasesConfiguration.Builder(context, "", "")
.service(executorService)
.entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)
.build();

Purchases.configure(build);
Purchases.configureInCustomEntitlementsComputationMode(context, "", "");
}

static void check(final Purchases purchases) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package com.revenuecat.apitester.kotlin

import android.content.Context
import com.revenuecat.purchases.EntitlementVerificationMode
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesConfiguration
import com.revenuecat.purchases.models.BillingFeature
import java.util.concurrent.ExecutorService

@Suppress("unused", "UNUSED_VARIABLE", "EmptyFunctionBlock")
private class PurchasesAPI {

@Suppress("ForbiddenComment")
fun checkConfiguration(context: Context, executorService: ExecutorService) {
val features: List<BillingFeature> = ArrayList()
fun checkConfiguration(context: Context) {
val configured: Boolean = Purchases.isConfigured

val build = PurchasesConfiguration.Builder(context, apiKey = "", appUserID = "")
.service(executorService)
.entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)
.build()

Purchases.configure(build)
Purchases.configureInCustomEntitlementsComputationMode(context, apiKey = "", appUserID = "")
}

fun check(purchases: Purchases) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,11 @@ static void check(final Purchases purchases, final Map<String, String> attribute
}

static void checkConfiguration(final Context context,
final ExecutorService executorService) {
final ExecutorService executorService,
final PurchasesConfiguration purchasesConfiguration) {
final boolean configured = Purchases.isConfigured();

PurchasesConfiguration build = new PurchasesConfiguration.Builder(context, "")
.appUserID("")
.observerMode(true)
.observerMode(false)
.service(executorService)
.diagnosticsEnabled(true)
.entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)
.build();

Purchases.configure(build);
Purchases.configure(purchasesConfiguration);

final boolean debugLogs = Purchases.getDebugLogsEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.revenuecat.apitester.kotlin
import android.content.Context
import com.revenuecat.purchases.CacheFetchPolicy
import com.revenuecat.purchases.CustomerInfo
import com.revenuecat.purchases.EntitlementVerificationMode
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesConfiguration
Expand Down Expand Up @@ -135,21 +134,15 @@ private class PurchasesAPI {
}

@Suppress("ForbiddenComment")
fun checkConfiguration(context: Context, executorService: ExecutorService) {
fun checkConfiguration(
context: Context,
executorService: ExecutorService,
purchasesConfiguration: PurchasesConfiguration,
) {
val features: List<BillingFeature> = ArrayList()
val configured: Boolean = Purchases.isConfigured

val build = PurchasesConfiguration.Builder(context, apiKey = "")
.appUserID("")
.observerMode(true)
.observerMode(false)
.service(executorService)
.diagnosticsEnabled(true)
.entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)
.informationalVerificationModeAndDiagnosticsEnabled(true)
.build()

Purchases.configure(build)
Purchases.configure(purchasesConfiguration)

Purchases.debugLogsEnabled = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ static void checkConfiguration(final Context context,
Purchases.setProxyURL(new URL(""));
final URL proxyURL = Purchases.getProxyURL();

PurchasesConfiguration build = new PurchasesConfiguration.Builder(context, "")
.appUserID("")
.observerMode(true)
.observerMode(false)
.service(executorService)
.diagnosticsEnabled(true)
.entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)
.build();

final Purchases instance = Purchases.getSharedInstance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.revenuecat.apitester.kotlin
import android.app.Activity
import android.content.Context
import com.revenuecat.purchases.CustomerInfo
import com.revenuecat.purchases.EntitlementVerificationMode
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI
import com.revenuecat.purchases.LogHandler
import com.revenuecat.purchases.LogLevel
Expand All @@ -12,6 +13,7 @@ import com.revenuecat.purchases.ProductType
import com.revenuecat.purchases.PurchaseParams
import com.revenuecat.purchases.PurchaseResult
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesConfiguration
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.awaitOfferings
import com.revenuecat.purchases.awaitPurchase
Expand All @@ -28,6 +30,7 @@ import com.revenuecat.purchases.models.StoreTransaction
import com.revenuecat.purchases.models.SubscriptionOption
import com.revenuecat.purchases.purchaseWith
import java.net.URL
import java.util.concurrent.ExecutorService

@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
@Suppress("unused", "UNUSED_VARIABLE", "EmptyFunctionBlock")
Expand Down Expand Up @@ -136,7 +139,7 @@ private class PurchasesCommonAPI {
}

@Suppress("ForbiddenComment")
fun checkConfiguration(context: Context) {
fun checkConfiguration(context: Context, executorService: ExecutorService) {
val features: List<BillingFeature> = ArrayList()
val configured: Boolean = Purchases.isConfigured

Expand All @@ -149,6 +152,16 @@ private class PurchasesCommonAPI {
Purchases.proxyURL = URL("")
val url: URL? = Purchases.proxyURL

val build: PurchasesConfiguration = PurchasesConfiguration.Builder(context, apiKey = "")
.appUserID("")
.observerMode(true)
.observerMode(false)
.service(executorService)
.diagnosticsEnabled(true)
.entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)
.informationalVerificationModeAndDiagnosticsEnabled(true)
.build()

val instance: Purchases = Purchases.sharedInstance
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.revenuecat.sample
import android.app.Application
import com.revenuecat.purchases.LogLevel
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesConfiguration
import com.revenuecat.sample.data.Constants

class MainApplication : Application() {
Expand All @@ -26,12 +25,10 @@ class MainApplication : Application() {
- An appUserID is required when doing a custom entitlement computation implementation.
Read more about Identifying Users here: https://docs.revenuecat.com/docs/user-ids
*/
val builder = PurchasesConfiguration.Builder(
Purchases.configureInCustomEntitlementsComputationMode(
this,
Constants.GOOGLE_API_KEY,
Constants.defaultAppUserID
)

Purchases.configure(builder.build())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,24 @@ class Purchases internal constructor(
/**
* Configures an instance of the Purchases SDK with a specified API key. The instance will
* be set as a singleton. You should access the singleton instance using [Purchases.sharedInstance]
* @param configuration: the [PurchasesConfiguration] object you wish to use to configure [Purchases].
* @param context: the Application context object of your Application.
* @param apiKey: the API Key for your app. Obtained from the RevenueCat dashboard.
* @param appUserID: a unique id for identifying the user.
* @return An instantiated `[Purchases] object that has been set as a singleton.
*/
@JvmStatic
fun configure(
configuration: PurchasesConfiguration,
fun configureInCustomEntitlementsComputationMode(
context: Context,
apiKey: String,
appUserID: String,
): Purchases {
if (isConfigured) {
infoLog(ConfigureStrings.INSTANCE_ALREADY_EXISTS)
}
val configuration = PurchasesConfiguration.Builder(context, apiKey)
.appUserID(appUserID)
.dangerousSettings(DangerousSettings(customEntitlementComputation = true))
.build()
return PurchasesFactory().createPurchases(
configuration,
platformInfo,
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9d3e882

Please sign in to comment.