Bunch of UI
This commit is contained in:
@@ -4,27 +4,27 @@ import {Entitlement} from '#/state/purchases/subscriptions/types'
|
||||
export async function getMainSubscriptions({
|
||||
did,
|
||||
platform,
|
||||
currency,
|
||||
}: {
|
||||
did: string
|
||||
platform: 'web' | 'ios' | 'android'
|
||||
currency: string
|
||||
}) {
|
||||
const res = await fetch(
|
||||
`https://bsky-purchases.ngrok.io/subscriptions/main?user=${did}&platform=${platform}`,
|
||||
`https://bsky-purchases.ngrok.io/subscriptions/main?user=${did}&platform=${platform}¤cy=${currency}`,
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
console.error('error fetching subscriptions', res.status, await res.text())
|
||||
return {
|
||||
active: [],
|
||||
available: [],
|
||||
subscriptions: [],
|
||||
}
|
||||
}
|
||||
|
||||
const json = await res.json()
|
||||
|
||||
return json as {
|
||||
active: Subscription[]
|
||||
available: Subscription[]
|
||||
subscriptions: Subscription[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,3 +42,39 @@ export async function getEntitlements({did}: {did: string}) {
|
||||
|
||||
return entitlements as Entitlement[]
|
||||
}
|
||||
|
||||
export async function updateSubscription({subscriptionId, newPriceId}: {subscriptionId: string, newPriceId: string}) {
|
||||
const res = await fetch(
|
||||
`https://bsky-purchases.ngrok.io/subscriptions/update`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({stripeSubscriptionId: subscriptionId, newPriceId}),
|
||||
}
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
console.error('error updating subscription', res.status, await res.text())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelSubscription({subscriptionId}: {subscriptionId: string}) {
|
||||
const res = await fetch(
|
||||
`https://bsky-purchases.ngrok.io/subscriptions/cancel`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({stripeSubscriptionId: subscriptionId}),
|
||||
}
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
console.error('error cancelling subscription', res.status, await res.text())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user