Period.fromAppStore constructor

Period.fromAppStore(
  1. SKProductSubscriptionPeriodWrapper subscriptionPeriod
)

Apple already splits the response to numbers and Units.

Implementation

factory Period.fromAppStore(SKProductSubscriptionPeriodWrapper subscriptionPeriod) {
  return Period._(
      amount: subscriptionPeriod.numberOfUnits,
      periodUnit: switch (subscriptionPeriod.unit) {
        SKSubscriptionPeriodUnit.year => PeriodUnit.YEARS,
        SKSubscriptionPeriodUnit.month => PeriodUnit.MONTH,
        SKSubscriptionPeriodUnit.week => PeriodUnit.WEEKS,
        SKSubscriptionPeriodUnit.day => PeriodUnit.DAYS,
      });
}