Fix logic
This commit is contained in:
+31
-31
@@ -59,6 +59,37 @@ export default new Hono<{Bindings: Bindings; Variables: Variables}>()
|
|||||||
await next()
|
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
|
* 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
|
* Get entitlements for a user
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -246,14 +246,13 @@ export function mergeSubscriptions(
|
|||||||
): Subscription[] {
|
): Subscription[] {
|
||||||
const merged: Subscription[] = []
|
const merged: Subscription[] = []
|
||||||
|
|
||||||
for (const a of active) {
|
for (const s of all) {
|
||||||
for (const s of all) {
|
const a = active.find(p => p.id === s.id)
|
||||||
if (a.id === s.id) {
|
if (a) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
merged.push({...s, state: a.state})
|
merged.push({...s, state: a.state})
|
||||||
} else {
|
} else {
|
||||||
merged.push(s)
|
merged.push(s)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +293,6 @@ export function getSubscriptionState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getSubscriptionPlatform(id: string): 'web' | 'android' | 'ios' {
|
export function getSubscriptionPlatform(id: string): 'web' | 'android' | 'ios' {
|
||||||
console.log(id)
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 'prod_R2eNjNa6mB1Jlu':
|
case 'prod_R2eNjNa6mB1Jlu':
|
||||||
case 'prod_R37Zg28EeQ9XAz':
|
case 'prod_R37Zg28EeQ9XAz':
|
||||||
|
|||||||
Reference in New Issue
Block a user