Skip to content

Add support for SK2 discounts#1038

Merged
NachoSoto merged 13 commits into
mainfrom
product-discount
Dec 10, 2021
Merged

Add support for SK2 discounts#1038
NachoSoto merged 13 commits into
mainfrom
product-discount

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Dec 7, 2021

Copy link
Copy Markdown
Contributor

Fixes #848 and [sc-11617].

Changes:

  • IntroDurationType: moved inside PromotionalOffer
  • PaymentMode: moved inside PromotionalOffer
  • Changed PromotionalOffer.price to Decimal and using Decimal in more places
  • Added constructor for PromotionalOffer.PaymentMode with SK2's Product.SubscriptionOffer.PaymentMode
  • PromotionalOffer: added constructor with SK2's Product.SubscriptionOffer
  • Added introductoryPrice and discounts to StoreProduct
  • Added SubscriptionPeriod to PromotionalOffer

TODO:

Figure out why expect(offers[1].subscriptionPeriod) == SubscriptionPeriod(value: 10, unit: .month) fails:
Screen Shot 2021-12-07 at 17 55 17

Looks like this only fails with PromotionalOffer.PaymentMode.payAsYouGo. It could be just a problem with .storekit files, but for now I've updated the tests to use multi-month .freeTrial to have a test that covers values higher than 1.

- [ ] From #848: "Move discount logic from Purchases to a new class". Which logic?

Questions:

  • I’ve added SubscriptionPeriod to PromotionalOffer, which gets encoded inside of ProductInfo. I’m surprised that wasn’t there already, and that the backend doesn’t need it?`
  • PaymentMode and IntroDurationType seem to be almost the same, the latter only used by ProductInfo. Do we need it?
  • Can we replace the 3 properties in ProductInfo (introDuration, introDurationType, introPrice) with a single `PromotionalOffer?

Answers:

@shortcut-integration

Copy link
Copy Markdown

This pull request has been linked to Shortcut Story #11617: Create abstraction for SKProductDiscount.

NachoSoto added a commit that referenced this pull request Dec 7, 2021
NFC (not functional change)
Just a small refactor while working on #1038, separating here for easier review. Simplifying these will help when adding some new types to `ProductInfo`.

I'm guessing some of these things are leftovers from the Swift migration.

## Changes:

- Refactored `ProductInfoExtractorTests`, moved duplicated code into `setUp`
- `ProductInfoExtractor` and `ISOPeriodFormatter`: replaced method with static function: these types contain no data, and there is only one possible implementation that we can have. For that reason, we're not mocking them or injecting them anywhere, so they're simpler as static functions. As an example, we had `lazy var isoPeriodFormatter = ISOPeriodFormatter()`, but again `ISOPeriodFormatter` contains no data, only logic, so there's no point having a `lazy` variable for it.
@NachoSoto NachoSoto force-pushed the product-discount branch 4 times, most recently from 57b9079 to 5d1f5e4 Compare December 8, 2021 02:08
@NachoSoto NachoSoto requested review from a team, aboedo, taquitos and vegaro and removed request for vegaro December 8, 2021 02:11

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 isn't compiled in release mode, but I think it's useful for debugging?
Not sure if we should check that it's also not 0.

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.

Sounds good. I can't think of a use case where it'd be valid to have 0, so we might as well check for that too

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.

Will do 👍

@NachoSoto

Copy link
Copy Markdown
Contributor Author

This is ready for review, and hoping to get some answers to the questions 🙏

@NachoSoto NachoSoto marked this pull request as ready for review December 8, 2021 22:57

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.

Previously SubscriptionPeriod.PeriodUnit. Now SubscriptionPeriod.Unit.

@aboedo aboedo 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.

looks great!

Comment thread Purchases/Purchasing/StoreKitAbstractions/StoreProduct.swift

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.

Sounds good. I can't think of a use case where it'd be valid to have 0, so we might as well check for that too

Comment thread StoreKitUnitTests/StoreProductTests.swift
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.

Add support for SK2 discounts

2 participants