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

Update product entitlement mapping request to new format #976

Merged
merged 3 commits into from
Apr 27, 2023

Conversation

tonidero
Copy link
Contributor

@tonidero tonidero commented Apr 19, 2023

Description

We are changing the format of the request to get the product entitlement mapping. This is safe to change since this is still not being used in production.

TODO

  • Test with actual backend

@tonidero tonidero added the refactor A code change that neither fixes a bug nor adds a feature label Apr 19, 2023
errorLog(OfflineEntitlementsStrings.ERROR_PARSING_PRODUCT_ENTITLEMENT_MAPPING.format(jsonString), e)
preferences.edit().remove(productEntitlementMappingCacheKey).apply()
null
}
Copy link
Contributor Author

@tonidero tonidero Apr 19, 2023

Choose a reason for hiding this comment

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

Found this small edge case, without this, we would have crashed later when trying to get the cached mappings if there was an invalid format (which should never happen)

val productObject = productsArray.getJSONObject(productIndex)
val productsObject = json.getJSONObject(PRODUCT_ENTITLEMENT_MAPPING_KEY)
val mappings = mutableMapOf<String, Mapping>()
for (mappingIdentifier in productsObject.keys()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what to call this, since it would be productId:basePlanId or productId. In StoreProduct, this would be the id...

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively I can suggest productsObjectKey, but mappingIdentifier works fine imo

val entitlements: List<String>
)

fun toMap(): Map<String, List<String>> {
return mappings.associateBy({ it.identifier }, { it.entitlements })
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't really use this now that it's not a simple mapping anymore, so I removed it

return PurchasedProduct(
productIdentifier,
mapping?.basePlanId,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that this will be used to create the offline customer info, but that part is not done yet. @vegaro started this in a different PR #959

@@ -57,11 +57,13 @@ class PurchasedProductsFetcher(
val purchaseAssociatedToProduct = allPurchases.first { it.skus[0] == productIdentifier }
val isActive = activeProducts.contains(productIdentifier)
val expirationDate = getExpirationDate(isActive, purchaseAssociatedToProduct)
val mapping = productEntitlementMapping?.mappings?.get(productIdentifier)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently productIdentifier will never include the basePlanId, so currently we will always grant the entitlements that the backwards compatible plan would give us... We can probably improve this though. @vegaro has a TODO for this in #959

@tonidero tonidero marked this pull request as ready for review April 24, 2023 09:50
@tonidero tonidero requested a review from a team April 24, 2023 09:50
val productObject = productsArray.getJSONObject(productIndex)
val productsObject = json.getJSONObject(PRODUCT_ENTITLEMENT_MAPPING_KEY)
val mappings = mutableMapOf<String, Mapping>()
for (mappingIdentifier in productsObject.keys()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively I can suggest productsObjectKey, but mappingIdentifier works fine imo

Base automatically changed from toniricodiez/sdk-2992-write-flow-to-use-locally-computed-2 to main April 27, 2023 07:10
@tonidero tonidero force-pushed the update-product-entitlement-mapping-request-format branch from 893ac77 to d197ce3 Compare April 27, 2023 07:15
@tonidero tonidero enabled auto-merge (squash) April 27, 2023 07:16
@tonidero tonidero merged commit 2b96421 into main Apr 27, 2023
4 checks passed
@tonidero tonidero deleted the update-product-entitlement-mapping-request-format branch April 27, 2023 07:31
tonidero added a commit that referenced this pull request May 18, 2023
**This is an automatic release.**

### New Features
* CAT-859 Expose whether or not a SubscriptionOption is Prepaid in the
SDK (#1005) via Deema AlShamaa (@dalshamaa)
### Bugfixes
* [CF-1324] Fix personalizedPrice defaulting to false (#952) via beylmk
(@beylmk)
### Performance Improvements
* Store and return ETag last refresh time header (#978) via Toni Rico
(@tonidero)
### Dependency Updates
* Bump fastlane-plugin-revenuecat_internal from `3b03efa` to `fe45299`
(#991) via dependabot[bot] (@dependabot[bot])
* Bump danger from 9.2.0 to 9.3.0 (#981) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-revenuecat_internal from `8482a43` to `3b03efa`
(#974) via dependabot[bot] (@dependabot[bot])
* Bump fastlane from 2.212.1 to 2.212.2 (#973) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-revenuecat_internal from `9255366` to `8482a43`
(#961) via dependabot[bot] (@dependabot[bot])
### Other Changes
* Add proration modes to post to backend (#977) via swehner (@swehner)
* Added ENTITLEMENTS_COMPUTED_ON_DEVICE (#939) via Cesar de la Vega
(@vegaro)
* Fix flaky test in OfflineCustomerInfoCalculatorTest (#997) via Cesar
de la Vega (@vegaro)
* Fix `OfflineCustomerInfoCalculatorTest` `Unresolved reference:
ProducType` (#995) via Cesar de la Vega (@vegaro)
* Add support for product_plan_identifier for offline customer info
(#959) via Cesar de la Vega (@vegaro)
* Add non-subscriptions support to offline customer info (#958) via
Cesar de la Vega (@vegaro)
* Query only active purchases when generating offline entitlements
customer info (#1003) via Toni Rico (@tonidero)
* Fix `PurchasesIntegrationTest` building issue (#996 into main) (#998)
via Cesar de la Vega (@vegaro)
* Fail offline entitlements computation if product entitlement mapping
not available (#999) via Toni Rico (@tonidero)
* Fix  build_magic_weather lane (#993) via Cesar de la Vega (@vegaro)
* Add backend integration tests and test product entitlement mapping
endpoint (#988) via Toni Rico (@tonidero)
* Fix purchases integration tests (#980) via Toni Rico (@tonidero)
* Disable offline entitlements if active inapp purchases exist (#983)
via Toni Rico (@tonidero)
* Clear cached customer info upon entering offline entitlements mode
(#989) via Toni Rico (@tonidero)
* Update product entitlement mapping request to new format (#976) via
Toni Rico (@tonidero)
* Support enabling/disabling offline entitlements (#964) via Toni Rico
(@tonidero)
* Add back integration tests automation (#972) via Toni Rico (@tonidero)
* Upgrade to AGP 8.0 (#975) via Toni Rico (@tonidero)
* Extract post receipt logic to PostReceiptHelper (#967) via Toni Rico
(@tonidero)
* Add isServerDown to error callback for postReceipt and getCustomerInfo
requests (#963) via Toni Rico (@tonidero)
* Add back integration test flavors (#962) via Toni Rico (@tonidero)
* Fix storing test results (#966) via Cesar de la Vega (@vegaro)
* Extract detekt job from test job (#965) via Cesar de la Vega (@vegaro)


[CF-1324]:
https://revenuecats.atlassian.net/browse/CF-1324?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor A code change that neither fixes a bug nor adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants