Surface interval at a top level
This commit is contained in:
+22
-4
@@ -102,7 +102,6 @@ export type Entitlement = {
|
|||||||
|
|
||||||
export type SubscriptionState = {
|
export type SubscriptionState = {
|
||||||
active: boolean
|
active: boolean
|
||||||
interval: 'monthly' | 'annual'
|
|
||||||
entitlements: {id: EntitlementId}[]
|
entitlements: {id: EntitlementId}[]
|
||||||
status:
|
status:
|
||||||
| 'trialing'
|
| 'trialing'
|
||||||
@@ -129,6 +128,7 @@ export type Subscription =
|
|||||||
| {
|
| {
|
||||||
id: SubscriptionId
|
id: SubscriptionId
|
||||||
platform: 'android' | 'ios'
|
platform: 'android' | 'ios'
|
||||||
|
interval: 'monthly' | 'annual'
|
||||||
state?: SubscriptionState
|
state?: SubscriptionState
|
||||||
store: {
|
store: {
|
||||||
type: 'play_store' | 'app_store'
|
type: 'play_store' | 'app_store'
|
||||||
@@ -139,6 +139,7 @@ export type Subscription =
|
|||||||
| {
|
| {
|
||||||
id: SubscriptionId
|
id: SubscriptionId
|
||||||
platform: 'web'
|
platform: 'web'
|
||||||
|
interval: 'monthly' | 'annual'
|
||||||
state: undefined
|
state: undefined
|
||||||
store: {
|
store: {
|
||||||
type: 'stripe'
|
type: 'stripe'
|
||||||
@@ -151,6 +152,7 @@ export type Subscription =
|
|||||||
| {
|
| {
|
||||||
id: SubscriptionId
|
id: SubscriptionId
|
||||||
platform: 'web'
|
platform: 'web'
|
||||||
|
interval: 'monthly' | 'annual'
|
||||||
state: SubscriptionState
|
state: SubscriptionState
|
||||||
store: {
|
store: {
|
||||||
type: 'stripe'
|
type: 'stripe'
|
||||||
@@ -185,12 +187,14 @@ export function normalizeSubscriptions(
|
|||||||
if (!id) continue
|
if (!id) continue
|
||||||
const platform = getSubscriptionPlatform(product.store_identifier)
|
const platform = getSubscriptionPlatform(product.store_identifier)
|
||||||
const state = subscription ? getSubscriptionState(subscription) : undefined
|
const state = subscription ? getSubscriptionState(subscription) : undefined
|
||||||
|
const interval = getSubscriptionInterval(id)
|
||||||
|
|
||||||
if (platform === 'web') {
|
if (platform === 'web') {
|
||||||
if (state) {
|
if (state) {
|
||||||
normalized.push({
|
normalized.push({
|
||||||
id,
|
id,
|
||||||
platform,
|
platform,
|
||||||
|
interval,
|
||||||
state,
|
state,
|
||||||
store: {
|
store: {
|
||||||
type: 'stripe',
|
type: 'stripe',
|
||||||
@@ -204,6 +208,7 @@ export function normalizeSubscriptions(
|
|||||||
normalized.push({
|
normalized.push({
|
||||||
id,
|
id,
|
||||||
platform,
|
platform,
|
||||||
|
interval,
|
||||||
state,
|
state,
|
||||||
store: {
|
store: {
|
||||||
type: 'stripe',
|
type: 'stripe',
|
||||||
@@ -218,6 +223,7 @@ export function normalizeSubscriptions(
|
|||||||
normalized.push({
|
normalized.push({
|
||||||
id,
|
id,
|
||||||
platform,
|
platform,
|
||||||
|
interval,
|
||||||
state,
|
state,
|
||||||
store: {
|
store: {
|
||||||
type: 'play_store',
|
type: 'play_store',
|
||||||
@@ -231,14 +237,26 @@ export function normalizeSubscriptions(
|
|||||||
return normalized
|
return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSubscriptionInterval(
|
||||||
|
id: SubscriptionId,
|
||||||
|
): 'monthly' | 'annual' {
|
||||||
|
switch (id) {
|
||||||
|
case SubscriptionId.Main0MonthlyAuto:
|
||||||
|
case SubscriptionId.Main1MonthlyAuto:
|
||||||
|
case SubscriptionId.Main2MonthlyAuto:
|
||||||
|
return 'monthly'
|
||||||
|
case SubscriptionId.Main0AnnualAuto:
|
||||||
|
case SubscriptionId.Main1AnnualAuto:
|
||||||
|
case SubscriptionId.Main2AnnualAuto:
|
||||||
|
return 'annual'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getSubscriptionState(
|
export function getSubscriptionState(
|
||||||
subscription: RevenueCatSubscription,
|
subscription: RevenueCatSubscription,
|
||||||
): SubscriptionState {
|
): SubscriptionState {
|
||||||
return {
|
return {
|
||||||
active: subscription.gives_access,
|
active: subscription.gives_access,
|
||||||
interval: subscription.store_subscription_identifier.includes('monthly')
|
|
||||||
? 'monthly'
|
|
||||||
: 'annual',
|
|
||||||
status: subscription.status,
|
status: subscription.status,
|
||||||
renewalStatus: subscription.auto_renewal_status,
|
renewalStatus: subscription.auto_renewal_status,
|
||||||
entitlements: normalizeEntitlements(subscription.entitlements.items),
|
entitlements: normalizeEntitlements(subscription.entitlements.items),
|
||||||
|
|||||||
Reference in New Issue
Block a user