Skip to content

[CustomerCenter] Add networking layer and models#1859

Merged
tonidero merged 14 commits into
mainfrom
customer-center-add-networking-data
Oct 2, 2024
Merged

[CustomerCenter] Add networking layer and models#1859
tonidero merged 14 commits into
mainfrom
customer-center-add-networking-data

Conversation

@tonidero

@tonidero tonidero commented Sep 27, 2024

Copy link
Copy Markdown
Contributor

Description

  • Adds networking layer and models to RevenueCat to support the new CustomerCenter.
  • Adds a new X-Preferred-Locales header.
  • Adds a new Purchases.getCustomerCenterConfigData method to access the data from RevenueCatUI

val title: String,
val type: PathType,
@SerialName("promotional_offer") val promotionalOffer: PathDetail.PromotionalOffer? = null,
@SerialName("feedback_survey") val feedbackSurvey: PathDetail.FeedbackSurvey? = null,

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.

Note that this is a bit different to iOS. In iOS, there is a single detail field, which makes sense since you can only have either promotional_offer or feedback_survey. But that was trickier to deserialize and I believe it's fine to separate these 2 into separate fields. Lmk if you have concerns.

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.

For my understanding, in Android we could have both?

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.

Not right now since the flow wouldn't make much sense if both are present... Having said that, we're not currently constraining this in the backend, so it's possible to have both.

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.

Alright, yea I think these models should reflect the backend as closely as possible, so this is fine with me.

@Serializable
class PromotionalOffer(
// WIP: Rename this field name to a new android id
@SerialName("ios_offer_id") val androidOfferId: String,

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.

Right now I'm reading the ios_offer_id but we should read the android one before merging this.

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

typealias RCColor = PaywallColor

@tonidero tonidero Sep 27, 2024

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.

Not a big fan of these typealiases, but it's how we have it in iOS, and it kinda made sense now.

Comment thread purchases/src/defaults/kotlin/com/revenuecat/purchases/listenerConversions.kt Outdated
)

@Serializable
class CustomerCenterConfigData(

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.

Need to write API tests for all these.

)

@Serializable
class CustomerCenterConfigData(

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.

Also note that the constructors here are public, so test data can be created more easily from within the RevenueCatUI module.

}

fun commonLocalizedString(key: CommonLocalizedString): String {
return localizedStrings[key.name.lowercase()] ?: key.defaultValue

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 didn't fully like this... It means the enum name must always match the key in uppercase. Want to write a test to make sure this is setup correctly.

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.

Test written in 8cb3f5f

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.

In this case as well I wouldn't be opposed to having the enum just match the JSON key. (Testing would still be good, but the "rule" is simpler.)

@codecov

codecov Bot commented Sep 27, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 65.82915% with 68 lines in your changes missing coverage. Please review.

Project coverage is 82.37%. Comparing base (6e73386) to head (bc0918b).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...rchases/customercenter/CustomerCenterConfigData.kt 62.90% 34 Missing and 12 partials ⚠️
.../kotlin/com/revenuecat/purchases/common/Backend.kt 75.00% 9 Missing and 1 partial ⚠️
...n/com/revenuecat/purchases/coroutinesExtensions.kt 0.00% 5 Missing ⚠️
...at/purchases/customercenter/ScreenMapSerializer.kt 69.23% 3 Missing and 1 partial ⚠️
...in/com/revenuecat/purchases/listenerConversions.kt 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1859      +/-   ##
==========================================
- Coverage   82.83%   82.37%   -0.46%     
==========================================
  Files         222      225       +3     
  Lines        7703     7900     +197     
  Branches     1084     1104      +20     
==========================================
+ Hits         6381     6508     +127     
- Misses        899      953      +54     
- Partials      423      439      +16     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@Serializable
class Appearance(
val light: ColorInformation? = null,
val dark: ColorInformation? = null,

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 is also different to what we have in iOS... In there, we have each color type first and each one has a light/dark color. Here, it's the opposite. This actually reflects the backend response better, and I think we can parse it as needed later, so I didn't want to try to flip it in the model.

@tonidero

Copy link
Copy Markdown
Contributor Author

I expect the new backend integration test to fail until we've given the project access to the customer center. It worked fine for a different project I tested on.

@tonidero tonidero marked this pull request as ready for review September 27, 2024 16:45
@tonidero tonidero requested a review from a team September 27, 2024 16:46
@tonidero tonidero force-pushed the customer-center-add-networking-data branch from c8163c6 to 36695b7 Compare September 30, 2024 09:15

@JayShortway JayShortway left a comment

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.

Nice, I think this is close! I just had some minor comments and suggestions.

Comment thread purchases/src/defaults/kotlin/com/revenuecat/purchases/listenerConversions.kt Outdated

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 for this PR, and maybe not for v0, but could be good to think about some rate limiting at some point? Even something like "once per 5 seconds" could already relieve some potential stress of calling this in a while(true).

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/Backend.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/HTTPClient.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/HTTPClient.kt Outdated
Comment thread purchases/src/defaults/kotlin/com/revenuecat/purchases/listenerConversions.kt Outdated
Comment thread api-tester/src/defaults/java/com/revenuecat/apitester/java/PurchasesAPI.java Outdated
private lateinit var backend: Backend
private lateinit var asyncBackend: Backend

private val expectedCustomerCenterConfigData = CustomerCenterConfigData(

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 have never used it, but Kotest's property test framework can supposedly help with generating these test fixtures. (Not for this PR of course, just something we could look into at some point.)

@tonidero tonidero requested review from a team and JayShortway September 30, 2024 16:06

@JayShortway JayShortway left a comment

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.

LGTM!

Comment on lines +5 to +7
internal interface LocaleProvider {
val currentLocalesLanguageTags: String
}

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.

Nice!

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.

❤️

@tonidero tonidero force-pushed the customer-center-add-networking-data branch from d9f9f57 to 64b023b Compare October 2, 2024 10:27
@tonidero tonidero enabled auto-merge (squash) October 2, 2024 11:04
@tonidero tonidero merged commit 4f8deac into main Oct 2, 2024
@tonidero tonidero deleted the customer-center-add-networking-data branch October 2, 2024 11:18
JayShortway pushed a commit that referenced this pull request Oct 10, 2024
**This is an automatic release.**

## RevenueCat SDK
### 🐞 Bugfixes
* Save SDK configuration on paywall activity so it can reconfigure
automatically (#1872) via Toni Rico (@tonidero)
### 📦 Dependency Updates
* Bump fastlane from 2.223.1 to 2.224.0 (#1870) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-revenuecat_internal from `5b2e35c` to `3b1e7cf`
(#1865) via dependabot[bot] (@dependabot[bot])
* Bump fastlane from 2.222.0 to 2.223.1 (#1860) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-revenuecat_internal from `55a0455` to `5b2e35c`
(#1858) via dependabot[bot] (@dependabot[bot])

### 🔄 Other Changes
* [CustomerCenter] Fix help path deserializing when unknown type (#1869)
via Toni Rico (@tonidero)
* [CustomerCenter] Create `CustomerCenter` composable and view model
with some initial UI (#1867) via Toni Rico (@tonidero)
* [CustomerCenter] Add networking layer and models (#1859) via Toni Rico
(@tonidero)
* [CustomerCenter] Adds SubscriptionDetailsView (#1863) via JayShortway
(@JayShortway)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants