Add active subscriptions to response
This commit is contained in:
@@ -80,6 +80,7 @@ export default new Hono<{Bindings: Bindings; Variables: Variables}>()
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
let products = getMainSubscriptionProducts(allProducts.items, subscriptions)
|
let products = getMainSubscriptionProducts(allProducts.items, subscriptions)
|
||||||
|
const activeProducts = products.filter(p => p.active)
|
||||||
|
|
||||||
if (platform === 'web') {
|
if (platform === 'web') {
|
||||||
const stripe = c.get('stripe')
|
const stripe = c.get('stripe')
|
||||||
@@ -116,7 +117,7 @@ export default new Hono<{Bindings: Bindings; Variables: Variables}>()
|
|||||||
products = products.filter(p => p.provider === 'play_store')
|
products = products.filter(p => p.provider === 'play_store')
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.json({subscriptions: products})
|
return c.json({active: activeProducts, subscriptions: products})
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ export type Subscription =
|
|||||||
* The rest of this is pretty generic
|
* The rest of this is pretty generic
|
||||||
*/
|
*/
|
||||||
interval: 'monthly' | 'annual'
|
interval: 'monthly' | 'annual'
|
||||||
|
active: boolean
|
||||||
autoRenew: boolean
|
autoRenew: boolean
|
||||||
provider: RevenueCatSubscription['store']
|
provider: RevenueCatSubscription['store']
|
||||||
status: RevenueCatSubscription['status'] | null
|
status: RevenueCatSubscription['status'] | null
|
||||||
@@ -146,6 +147,7 @@ export type Subscription =
|
|||||||
lookupKey: string
|
lookupKey: string
|
||||||
checkoutId: string
|
checkoutId: string
|
||||||
interval: 'monthly' | 'annual'
|
interval: 'monthly' | 'annual'
|
||||||
|
active: boolean
|
||||||
autoRenew: boolean
|
autoRenew: boolean
|
||||||
storeSubscriptionIdentifier: string | null
|
storeSubscriptionIdentifier: string | null
|
||||||
provider: RevenueCatSubscription['store']
|
provider: RevenueCatSubscription['store']
|
||||||
@@ -191,6 +193,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: 'bsky_tier_0',
|
lookupKey: 'bsky_tier_0',
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'monthly',
|
interval: 'monthly',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'android',
|
platform: 'android',
|
||||||
provider: 'play_store',
|
provider: 'play_store',
|
||||||
@@ -212,6 +215,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: 'bsky_tier_0',
|
lookupKey: 'bsky_tier_0',
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'annual',
|
interval: 'annual',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'android',
|
platform: 'android',
|
||||||
provider: 'play_store',
|
provider: 'play_store',
|
||||||
@@ -233,6 +237,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: 'bsky_tier_1',
|
lookupKey: 'bsky_tier_1',
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'monthly',
|
interval: 'monthly',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'android',
|
platform: 'android',
|
||||||
provider: 'play_store',
|
provider: 'play_store',
|
||||||
@@ -254,6 +259,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: 'bsky_tier_1',
|
lookupKey: 'bsky_tier_1',
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'annual',
|
interval: 'annual',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'android',
|
platform: 'android',
|
||||||
provider: 'play_store',
|
provider: 'play_store',
|
||||||
@@ -275,6 +281,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: 'bsky_tier_2',
|
lookupKey: 'bsky_tier_2',
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'monthly',
|
interval: 'monthly',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'android',
|
platform: 'android',
|
||||||
provider: 'play_store',
|
provider: 'play_store',
|
||||||
@@ -296,6 +303,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: 'bsky_tier_2',
|
lookupKey: 'bsky_tier_2',
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'annual',
|
interval: 'annual',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'android',
|
platform: 'android',
|
||||||
provider: 'play_store',
|
provider: 'play_store',
|
||||||
@@ -321,6 +329,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: product.store_identifier,
|
lookupKey: product.store_identifier,
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'monthly',
|
interval: 'monthly',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'web',
|
platform: 'web',
|
||||||
provider: 'stripe',
|
provider: 'stripe',
|
||||||
@@ -343,6 +352,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: product.store_identifier,
|
lookupKey: product.store_identifier,
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'annual',
|
interval: 'annual',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'web',
|
platform: 'web',
|
||||||
provider: 'stripe',
|
provider: 'stripe',
|
||||||
@@ -365,6 +375,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: product.store_identifier,
|
lookupKey: product.store_identifier,
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'monthly',
|
interval: 'monthly',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'web',
|
platform: 'web',
|
||||||
provider: 'stripe',
|
provider: 'stripe',
|
||||||
@@ -387,6 +398,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: product.store_identifier,
|
lookupKey: product.store_identifier,
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'annual',
|
interval: 'annual',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'web',
|
platform: 'web',
|
||||||
provider: 'stripe',
|
provider: 'stripe',
|
||||||
@@ -409,6 +421,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: product.store_identifier,
|
lookupKey: product.store_identifier,
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'monthly',
|
interval: 'monthly',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'web',
|
platform: 'web',
|
||||||
provider: 'stripe',
|
provider: 'stripe',
|
||||||
@@ -431,6 +444,7 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
lookupKey: product.store_identifier,
|
lookupKey: product.store_identifier,
|
||||||
checkoutId: product.store_identifier,
|
checkoutId: product.store_identifier,
|
||||||
interval: 'annual',
|
interval: 'annual',
|
||||||
|
active: subscription?.gives_access ?? false,
|
||||||
autoRenew: true,
|
autoRenew: true,
|
||||||
platform: 'web',
|
platform: 'web',
|
||||||
provider: 'stripe',
|
provider: 'stripe',
|
||||||
|
|||||||
Reference in New Issue
Block a user