-
Notifications
You must be signed in to change notification settings - Fork 51
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: Create different PurchasesConfiguration that requires an appUserId parameter #1154
CustomEntitlementComputation: Create different PurchasesConfiguration that requires an appUserId parameter #1154
Conversation
import com.revenuecat.purchases.PurchasesConfiguration | ||
import com.revenuecat.purchases.Store | ||
|
||
class AmazonConfiguration(builder: Builder) : PurchasesConfiguration(builder) { |
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.
Also had to create amazon classes for each flavor... Not sure if it's needed but adding it for now
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.
I'd be more inclined to keep Amazon only in the main flavor, unless there's a technical limitation that forces us to have it
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.
Hmm I thought of a way to do that, but will do it in a separate PR. For now, I'm just failing when using this in customEntitlementComputation mode.
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.
Done in #1158
* This information will be anonymized so it can't be traced back to the end-user. | ||
* The default value is false. | ||
*/ | ||
fun diagnosticsEnabled(diagnosticsEnabled: Boolean) = apply { |
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.
I'm wondering, should we disable diagnostics in customEntitlementComputation
mode, @aboedo?
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.
let's keep it disabled on v1 and we can take it from there
...s/src/customEntitlementComputation/kotlin/com/revenuecat/purchases/PurchasesConfiguration.kt
Outdated
Show resolved
Hide resolved
val builder = PurchasesConfiguration.Builder(mockContext, "api").store(Store.PLAY_STORE) | ||
Purchases.configure(builder.build()) | ||
assertThat(Purchases.sharedInstance.store).isEqualTo(Store.PLAY_STORE) | ||
} |
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.
Had to separate these tests per flavor, now that the purchases configuration is different.
every { apiKey } returns testApiKey | ||
every { appUserID } returns "appUserID" | ||
every { store } returns Store.PLAY_STORE | ||
} |
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.
I could have split these tests... But I decided to just use a mock to not have to do that.
Codecov Report
@@ Coverage Diff @@
## main #1154 +/- ##
==========================================
+ Coverage 85.40% 85.69% +0.29%
==========================================
Files 177 176 -1
Lines 6275 6095 -180
Branches 921 915 -6
==========================================
- Hits 5359 5223 -136
+ Misses 571 531 -40
+ Partials 345 341 -4
|
36d9eab
to
4e590d0
Compare
33341fa
to
ca42170
Compare
4e590d0
to
c0e8cee
Compare
import android.content.Context | ||
import java.util.concurrent.ExecutorService | ||
|
||
open class PurchasesConfiguration(builder: Builder) { |
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.
Originally I wasn't planning to copy the whole PurchasesConfiguration
... But I didn't know how to have the Builder
have a different constructor per flavor without duplicating everything like 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.
Could it just be a public extension declared in each flavor?
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.
I don't think kotlin allows to declare an inner class or a constructor as an extension :(
* Only use a Dangerous Setting if suggested by RevenueCat support team. | ||
*/ | ||
fun dangerousSettings(dangerousSettings: DangerousSettings) = apply { | ||
this.dangerousSettings = dangerousSettings.copy(customEntitlementComputation = true) |
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.
Note how I'm doing this, so in case somone using this package changes dangerous settings, we still enable customEntitlementComputation.
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.
Hmm this makes me think why do we even have the setter in DangerousSettings? If someone in the defaults flavor enables it, they won't access the same API, and if someone in the custom entitlements flavor disables it and sets it here, it will be re-enabled
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.
Hmm the customEntitlementComputation
in DangerousSettings
is internal, so devs won't be able to set it up themselves. So it should always be false
in the defaults
flavor and true in the customEntitlementComputation
flavor. Not sure if I'm missing something?
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.
Oh then nevermind, I had missed that point
20e21e8
to
36ee010
Compare
* Only use a Dangerous Setting if suggested by RevenueCat support team. | ||
*/ | ||
fun dangerousSettings(dangerousSettings: DangerousSettings) = apply { | ||
this.dangerousSettings = dangerousSettings.copy(customEntitlementComputation = true) |
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.
Hmm this makes me think why do we even have the setter in DangerousSettings? If someone in the defaults flavor enables it, they won't access the same API, and if someone in the custom entitlements flavor disables it and sets it here, it will be re-enabled
purchases/src/testCustomEntitlementComputation/kotlin/com/revenuecat/purchases/PurchasesTest.kt
Outdated
Show resolved
Hide resolved
bf5776f
to
85d6dc5
Compare
2c28c0c
to
10f6340
Compare
) : PurchasesConfiguration.Builder(context, apiKey, appUserId) { | ||
|
||
init { | ||
error("AmazonConfiguration is not currently supported in the custom entitlement computation package.") |
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.
Will remove this class (and the customEntitlementComputation flavor) in a followup PR
this.dangerousSettings = builder.dangerousSettings | ||
} | ||
|
||
open class Builder( |
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.
Note that I removed the observerMode
setter as well, so it won't be available in the customEntitlementComputation package. CC @aboedo
10f6340
to
5a3529b
Compare
/** | ||
* Sets the [EntitlementVerificationMode] to perform signature verification of requests to the | ||
* RevenueCat backend. | ||
* | ||
* When changing from [EntitlementVerificationMode.DISABLED] to other modes, the SDK will clear the | ||
* CustomerInfo cache. | ||
* This means users will need to connect to the internet to get their entitlements back. | ||
* | ||
* The result of the verification can be obtained from [EntitlementInfos.verification] or | ||
* [EntitlementInfo.verification]. | ||
* | ||
* Default mode is disabled. Please see https://rev.cat/trusted-entitlements for more info. | ||
*/ | ||
fun entitlementVerificationMode(verificationMode: EntitlementVerificationMode) = apply { | ||
this.verificationMode = verificationMode | ||
} |
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.
this shouldn't be added here, it's not a part of this mode
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.
I see you're already removing it in #1167
**This is an automatic release.** ### New Features Introduced Custom Entitlements Computation mode. This is new library intended for apps that will do their own entitlement computation separate from RevenueCat. It's distributed as a separate artifact in Maven. Apps using this mode rely on webhooks to signal their backends to refresh entitlements with RevenueCat. See the [demo app for an example and usage instructions](https://github.com/RevenueCat/purchases-android/tree/main/examples/CustomEntitlementComputationSample). * Custom entitlements: add README and other improvements (#1167) via Andy Boedo (@aboedo) * Update Custom Entitlements Sample app (#1166) via Andy Boedo (@aboedo) * purchase coroutine (#1142) via Andy Boedo (@aboedo) * Add switchUser (#1156) via Cesar de la Vega (@vegaro) * CustomEntitlementsComputation: disable first listener callback when set (#1152) via Andy Boedo (@aboedo) * CustomEntitlementsComputation: Prevent posting subscriber attributes in post receipt (#1151) via Andy Boedo (@aboedo) * Fix `customEntitlementComputation` library deployment (#1169) via Toni Rico (@tonidero) * CustomEntitlementComputation: Configure method for customEntitlementComputation mode (#1168) via Toni Rico (@tonidero) * Add publish system for customEntitlementComputation package (#1149) via Cesar de la Vega (@vegaro) * Use purchase coroutine in CustomEntitlementComputationSample (#1162) via Cesar de la Vega (@vegaro) * Adds CustomEntitlementComputationSample (#1160) via Cesar de la Vega (@vegaro) * Fix tests in customEntitlementComputation after merges (#1161) via Toni Rico (@tonidero) * CustomEntitlementComputation: Remove custom entitlement computation flavor for amazon module (#1158) via Toni Rico (@tonidero) * CustomEntitlementComputation: Generate dokka docs only for defaults flavor (#1159) via Toni Rico (@tonidero) * CustomEntitlementComputation: Create different PurchasesConfiguration that requires an appUserId parameter (#1154) via Toni Rico (@tonidero) * CustomEntitlementComputation: New Purchases class (#1153) via Toni Rico (@tonidero) * CustomEntitlementComputation: Disable automatic cache refresh (#1157) via Toni Rico (@tonidero) * Add `customEntitlementComputation` flavor (#1147) via Toni Rico (@tonidero) * Make `customEntitlementComputation` singular (#1148) via Toni Rico (@tonidero) * Disable offline entitlements in custom entitlements computation mode (#1146) via Toni Rico (@tonidero) * Remove integration test flavor (#1143) via Toni Rico (@tonidero) * Add header to requests when in custom entitlement computation mode (#1145) via Toni Rico (@tonidero) * Add internal customEntitlementsComputation mode to app config (#1141) via Toni Rico (@tonidero) ### New Coroutines * `awaitPurchase` is available as a coroutine-friendly alternative to `purchase()`. (#1142) via Andy Boedo (@aboedo) ### Dependency Updates * Bump fastlane from 2.213.0 to 2.214.0 (#1140) via dependabot[bot] (@dependabot[bot]) ### Other changes * CI: make all Codecov jobs informational (#1155) via Cesar de la Vega (@vegaro) * Creates PurchasesOrchestrator (#1144) via Cesar de la Vega (@vegaro) --------- Co-authored-by: revenuecat-ops <ops@revenuecat.com> Co-authored-by: Andy Boedo <andresboedo@gmail.com>
### New Features Introduced Custom Entitlements Computation mode. This is new library intended for apps that will do their own entitlement computation separate from RevenueCat. It's distributed as a separate artifact in Maven. Apps using this mode rely on webhooks to signal their backends to refresh entitlements with RevenueCat. See the [demo app for an example and usage instructions](https://github.com/RevenueCat/purchases-android/tree/main/examples/CustomEntitlementComputationSample). * Custom entitlements: add README and other improvements (#1167) via Andy Boedo (@aboedo) * Update Custom Entitlements Sample app (#1166) via Andy Boedo (@aboedo) * purchase coroutine (#1142) via Andy Boedo (@aboedo) * Add switchUser (#1156) via Cesar de la Vega (@vegaro) * CustomEntitlementsComputation: disable first listener callback when set (#1152) via Andy Boedo (@aboedo) * CustomEntitlementsComputation: Prevent posting subscriber attributes in post receipt (#1151) via Andy Boedo (@aboedo) * Fix `customEntitlementComputation` library deployment (#1169) via Toni Rico (@tonidero) * CustomEntitlementComputation: Configure method for customEntitlementComputation mode (#1168) via Toni Rico (@tonidero) * Add publish system for customEntitlementComputation package (#1149) via Cesar de la Vega (@vegaro) * Use purchase coroutine in CustomEntitlementComputationSample (#1162) via Cesar de la Vega (@vegaro) * Adds CustomEntitlementComputationSample (#1160) via Cesar de la Vega (@vegaro) * Fix tests in customEntitlementComputation after merges (#1161) via Toni Rico (@tonidero) * CustomEntitlementComputation: Remove custom entitlement computation flavor for amazon module (#1158) via Toni Rico (@tonidero) * CustomEntitlementComputation: Generate dokka docs only for defaults flavor (#1159) via Toni Rico (@tonidero) * CustomEntitlementComputation: Create different PurchasesConfiguration that requires an appUserId parameter (#1154) via Toni Rico (@tonidero) * CustomEntitlementComputation: New Purchases class (#1153) via Toni Rico (@tonidero) * CustomEntitlementComputation: Disable automatic cache refresh (#1157) via Toni Rico (@tonidero) * Add `customEntitlementComputation` flavor (#1147) via Toni Rico (@tonidero) * Make `customEntitlementComputation` singular (#1148) via Toni Rico (@tonidero) * Disable offline entitlements in custom entitlements computation mode (#1146) via Toni Rico (@tonidero) * Remove integration test flavor (#1143) via Toni Rico (@tonidero) * Add header to requests when in custom entitlement computation mode (#1145) via Toni Rico (@tonidero) * Add internal customEntitlementsComputation mode to app config (#1141) via Toni Rico (@tonidero) ### New Coroutines * `awaitPurchase` is available as a coroutine-friendly alternative to `purchase()`. (#1142) via Andy Boedo (@aboedo) ### Dependency Updates * Bump fastlane from 2.213.0 to 2.214.0 (#1140) via dependabot[bot] (@dependabot[bot]) ### Other changes * CI: make all Codecov jobs informational (#1155) via Cesar de la Vega (@vegaro) * Creates PurchasesOrchestrator (#1144) via Cesar de la Vega (@vegaro) --------- Co-authored-by: revenuecat-ops <ops@revenuecat.com> Co-authored-by: Andy Boedo <andresboedo@gmail.com>
Description
This PR separates
PurchasesConfiguration
in 2 for thedefaults
andcustomEntitlementComputation
flavor. The one incustomEntitlementComputation
will require an app user id, avoiding initializing the sdk with anonymous users.