Skip to content
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

CustomEntitlementComputation: Configure method for customEntitlementComputation mode #1168

Merged
Merged
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
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, "", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

}

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner since this is already tested 👍🏻

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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really needed for the customEntitlementComputation flavor, but moving api tests to the main source set since now this class will be common for both.


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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that in this mode, anything else that can be enabled in PurchasesConfiguration won't be available, like setting a custom executorService for requests, observer mode, entitlement verification mode.... This is ok for now, but I wanted to mention it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup we want to be very opinionated for this mode 👍🏻

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