Skip to content

CustomEntitlementComputation: New Purchases class#1153

Merged
tonidero merged 16 commits into
mainfrom
toniricodiez/sdk-3223-new-custom-entitlements-purchases-class
Jul 21, 2023
Merged

CustomEntitlementComputation: New Purchases class#1153
tonidero merged 16 commits into
mainfrom
toniricodiez/sdk-3223-new-custom-entitlements-purchases-class

Conversation

@tonidero

@tonidero tonidero commented Jul 20, 2023

Copy link
Copy Markdown
Contributor

Description

This PR moves the existing Purchases class into the defaults flavor and creates a new Purchases class in the customEntitlementComputation flavor. It also moves some of the extension functions to the defaults flavor since they aren't possible in the customEntitlementComputation flavor. It also splits the tests and api tests to run some tests on the defaults flavor only

@codecov

codecov Bot commented Jul 20, 2023

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 58.82353% with 14 lines in your changes missing coverage. Please review.

Project coverage is 85.64%. Comparing base (46321d2) to head (d4886aa).
Report is 575 commits behind head on main.

Files with missing lines Patch % Lines
.../revenuecat/purchases/ListenerConversionsCommon.kt 54.54% 8 Missing and 2 partials ⚠️
...in/com/revenuecat/purchases/listenerConversions.kt 40.00% 3 Missing ⚠️
...n/com/revenuecat/purchases/coroutinesExtensions.kt 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1153      +/-   ##
==========================================
+ Coverage   85.40%   85.64%   +0.24%     
==========================================
  Files         177      178       +1     
  Lines        6275     6160     -115     
  Branches      921      916       -5     
==========================================
- Hits         5359     5276      -83     
+ Misses        571      543      -28     
+ Partials      345      341       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread build.gradle Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I would like to run the linter in the tests as well... But there were a bunch of issues and didn't want to make this PR even bigger, so I'm just excluding this for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I renamed this file to ListenerConversionsCommon, this is technically a breaking change in Java, since users in Java would need to upgrade from using ListenerConversionsKt to ListenerConversionsCommonKt for this... I would say people shouldn't be using these extension functions in Java, but they "can".

An alternative to this is to just not have a "common" file and duplicate all functions in both flavors... I wanted to try to reduce the duplication, but might be worth it... Thoughts?

(Note that this doesn't affect the CoroutinesConversionCommon since those functions are marked as @JvmSynthetic so they shouldn't be available in Java.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, probably worth asking the rest of the team, but I think we can rename, imo

@tonidero tonidero Jul 20, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I only added the functions that were needed looking at the API in iOS, but please confirm the API is what we expect. Also, I didn't add any deprecated functions. No need to add those to a new package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's also annoying that we have to duplicate the docs 😢

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd actually argue that it's not that bad, given that the docs could be different - for one, the configuration in custom entitlements mode has a non-nullable app user id, so its usage is slightly different, copy can accommodate for that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kept these in the main source set... I don't think these should be public, but we use them internally, so they would need to be public in defaults to not cause a breaking change but internal in customEntitlementComputation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to split the tests in "Common" for those that should be run in both flavors, and flavor specific ones.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went back to using the purchaseOrchestrator for these... the one in Purchases is deprecated in the defaults flavor and it doesn't exist in the customEntitlementComputation flavor, so this allowed me to share the test between both flavors and use non-deprecated functions.

@tonidero tonidero force-pushed the toniricodiez/sdk-3223-new-custom-entitlements-purchases-class branch from 5148d25 to 58592a5 Compare July 20, 2023 07:54
Base automatically changed from cesar/sdk-3222-custom-entitlements-purchases-internal-class to main July 20, 2023 09:41
@tonidero tonidero force-pushed the toniricodiez/sdk-3223-new-custom-entitlements-purchases-class branch from 33341fa to ca42170 Compare July 20, 2023 09:47
@tonidero tonidero marked this pull request as ready for review July 20, 2023 10:11
@tonidero tonidero requested a review from a team July 20, 2023 10:12

@tonidero tonidero Jul 20, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was missed from #1144. Made the change here to avoid conflicts later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess this doesn't really matter since we use these 2 only when configuring the SDK, and we use the value from Purchases, not PurchasesOrchestrator... We might be able to remove the ones in PurchasesOrchestrator. But for now, this seems more secure.

@tonidero tonidero marked this pull request as draft July 20, 2023 12:26
@tonidero

Copy link
Copy Markdown
Contributor Author

Moving back to draft. Exploring using a public base class instead to try to share more code

@tonidero tonidero marked this pull request as ready for review July 20, 2023 13:36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick

We have typically lowercased these files since they are files and not classes. Not sure if that's what we should be doing, but that's what they other files look like.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, detekt was complaining with the lowercase... I think we should try to move toward this instead. Lmk if you think otherwise!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh ok! yeah, I don't care, if we go with uppercase, let's make sure we start moving towards that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick

Same comment about lowercasing the file

@tonidero tonidero force-pushed the toniricodiez/sdk-3223-new-custom-entitlements-purchases-class branch from bf5776f to 85d6dc5 Compare July 20, 2023 14:39

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd actually argue that it's not that bad, given that the docs could be different - for one, the configuration in custom entitlements mode has a non-nullable app user id, so its usage is slightly different, copy can accommodate for that

Comment on lines +216 to +227
/**
* Invalidates the cache for customer information.
*
* Most apps will not need to use this method; invalidating the cache can leave your app in an invalid state.
* Refer to https://rev.cat/customer-info-cache for more information on
* using the cache properly.
*
* This is useful for cases where purchaser information might have been updated outside of the
* app, like if a promotional subscription is granted through the RevenueCat dashboard.
*/
fun invalidateCustomerInfoCache() {
purchasesOrchestrator.invalidateCustomerInfoCache()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe this one is available in iOS. But yeah, I think it's probably ok to remove it. CC @NachoSoto

@NachoSoto NachoSoto Jul 21, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just asked to see if it's being used 👀

@tonidero tonidero requested review from aboedo and vegaro July 21, 2023 06:56
@tonidero

Copy link
Copy Markdown
Contributor Author

Removed some extra methods from the custom entitlement computation flavor here, so asking for a rereview, 🙏

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/ListenerConversionsCommon.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/ListenerConversionsCommon.kt Outdated
@tonidero tonidero merged commit a81f73a into main Jul 21, 2023
@tonidero tonidero deleted the toniricodiez/sdk-3223-new-custom-entitlements-purchases-class branch July 21, 2023 14:17
tonidero added a commit that referenced this pull request Jul 21, 2023
…lavor (#1159)

### Description
After #1153, docs were generated with multiple `Purchases` classes and
it was very confusing. For the public docs, we only need the defaults
flavor, so we can remove docs for the customEntitlementComputation
package
This was referenced Jul 21, 2023
aboedo added a commit that referenced this pull request Jul 24, 2023
**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>
tonidero pushed a commit that referenced this pull request Jul 25, 2023
### 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants