Fix logic

This commit is contained in:
Eric Bailey
2024-10-30 09:46:39 -05:00
parent 987b073b79
commit 3713ad399f
2 changed files with 38 additions and 40 deletions
+31 -31
View File
@@ -59,6 +59,37 @@ export default new Hono<{Bindings: Bindings; Variables: Variables}>()
await next()
})
/**
* Update a subscription (web only)
*/
.post(`/subscriptions/update`, async c => {
const stripe = c.get('stripe')
const {stripeSubscriptionId, newPriceId} = await c.req.json()
const subscriptionItem = await stripe.subscriptionItems.retrieve(
stripeSubscriptionId,
)
// TODO get customer and compare DID to auth state to ensure it's legit
const subscription = await stripe.subscriptions.update(
subscriptionItem.subscription,
{
items: [
{
id: stripeSubscriptionId,
deleted: true,
},
{
price: newPriceId,
},
],
},
)
return c.json({
oldItem: subscriptionItem,
subscription,
})
})
/**
* Get subscription products for a given offering
*/
@@ -155,37 +186,6 @@ export default new Hono<{Bindings: Bindings; Variables: Variables}>()
})
})
/**
* Update a subscription (web only)
*/
.post(`/subscriptions/update`, async c => {
const stripe = c.get('stripe')
const {stripeSubscriptionItemId, newPriceId} = await c.req.json()
const subscriptionItem = await stripe.subscriptionItems.retrieve(
stripeSubscriptionItemId,
)
// TODO get customer and compare DID to auth state to ensure it's legit
const subscription = await stripe.subscriptions.update(
subscriptionItem.subscription,
{
items: [
{
id: stripeSubscriptionItemId,
deleted: true,
},
{
price: newPriceId,
},
],
},
)
return c.json({
oldItem: subscriptionItem,
subscription,
})
})
/**
* Get entitlements for a user
*/
+7 -9
View File
@@ -246,14 +246,13 @@ export function mergeSubscriptions(
): Subscription[] {
const merged: Subscription[] = []
for (const a of active) {
for (const s of all) {
if (a.id === s.id) {
// @ts-ignore
merged.push({...s, state: a.state})
} else {
merged.push(s)
}
for (const s of all) {
const a = active.find(p => p.id === s.id)
if (a) {
// @ts-ignore
merged.push({...s, state: a.state})
} else {
merged.push(s)
}
}
@@ -294,7 +293,6 @@ export function getSubscriptionState(
}
export function getSubscriptionPlatform(id: string): 'web' | 'android' | 'ios' {
console.log(id)
switch (id) {
case 'prod_R2eNjNa6mB1Jlu':
case 'prod_R37Zg28EeQ9XAz':