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

Use SK2 RenewalInfo to get renewal prices & currency #4608

Merged
merged 23 commits into from
Dec 20, 2024

Conversation

fire-at-will
Copy link
Contributor

@fire-at-will fire-at-will commented Dec 17, 2024

Motivation

We were previously showing all renewal prices as the product's price in the Customer Center. This is usually accurate, but doesn't cover several edge cases, including product changes, price increase/decreases, and various offers.

This PR addresses this by getting the renewal price directly from StoreKit 2.

Description

  • Get renewal price and currency directly from StoreKit 2. If this fails for any reason, we fall back to showing the product's regular price like we were before this PR
  • Updates the currentPrice default string value from "Current price" to "Price"

Manual Testing

I tested the following flows manually on a physical device in sandbox:

  • Product change
  • Price Increase
  • Purchasing with SK1, the price still shows correctly in the Customer Center

@fire-at-will fire-at-will marked this pull request as ready for review December 18, 2024 23:16
if let renewalPrice {
self.price = renewalPrice
} else {
self.price = entitlement.priceBestEffort(product: subscribedProduct)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fall back to our old calculation method if the RenewalInfo method failed for some reason

@fire-at-will fire-at-will requested review from vegaro and a team and removed request for a team and vegaro December 18, 2024 23:23
@fire-at-will fire-at-will marked this pull request as draft December 18, 2024 23:29
@fire-at-will fire-at-will marked this pull request as ready for review December 19, 2024 01:08
@fire-at-will fire-at-will requested review from vegaro and a team December 19, 2024 01:08
@fire-at-will fire-at-will changed the title Use SK2 RenewalInfo to get renewal prices Use SK2 RenewalInfo to get renewal prices & currency Dec 19, 2024
RevenueCatUI/CustomerCenter/Data/PurchaseInformation.swift Outdated Show resolved Hide resolved
RevenueCatUI/CustomerCenter/Data/PurchaseInformation.swift Outdated Show resolved Hide resolved
// to make sure that this is being built with an Xcode version >=15.0.
#if compiler(>=6.0)
guard let currency = renewalInfo.currency else { return nil }
if currency.isISOCurrency {
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, what's the other option if it's not ISO? just curious

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 honestly not sure, but NumberFormatter.currencyCode depends on the currency code being a ISO 4217 currency code, so I figured it was worth a check here

transaction: Transaction,
customerCenterStoreKitUtilities: CustomerCenterStoreKitUtilitiesType
) async -> PurchaseInformation {
let renewalPriceDetails = await Self.extractPriceDetailsFromRenwalInfo(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need to extract the date from the RenewalInfo?

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 don't think we have to since we're already calculating it accurately from the transaction today, so I think we can keep doing that to keep the size of the change down. Even in the scenario where you switch product durations (say you switch from a monthly product to a yearly), the new product won't be active until the the renewal at the end of the current subscription period.

Do you know of any edge cases where the current renewal date calculation is inaccurate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right I was thinking of cases where the product change would happen before the end of the period, but in that case, it would be immediate and it would be showing the new product. So I think this makes sense!

@fire-at-will fire-at-will requested a review from vegaro December 19, 2024 20:30
@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will fire-at-will merged commit 6c4256a into main Dec 20, 2024
38 checks passed
@fire-at-will fire-at-will deleted the use-renewal-info-for-renewal-price branch December 20, 2024 13:50
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.

2 participants