Skip to content

Commit

Permalink
embed: Use profile_settings to customize subscribe embed
Browse files Browse the repository at this point in the history
  • Loading branch information
birkjernstrom committed Jul 16, 2024
1 parent f659489 commit 240e1d7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions clients/apps/web/src/app/embed/subscribe.svg/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { getServerURL } from '@/utils/api'
import {
ListResourceOrganizationCustomer,
OrganizationCustomer,
OrganizationSubscribePromoteSettings,
OrganizationCustomerType
} from '@polar-sh/sdk'
const { default: satori } = require('satori')

Expand All @@ -12,14 +14,29 @@ const getCustomers = async (
org: string,
limit: number = 3,
): Promise<[OrganizationCustomer[], number]> => {
const { id: orgId } = await fetch(
const { id: orgId, profile_settings } = await fetch(
`${getServerURL()}/v1/organizations/lookup?organization_name=${org}&platform=github`,
{ method: 'GET' },
).then((res) => res.json())

let url = `${getServerURL()}/v1/organizations/${orgId}/customers?customer_types=subscription&limit=${limit}`
const settings: OrganizationSubscribePromoteSettings = profile_settings?.subscribe ?? {
promote: true,
show_count: true,
count_free: true,
}
if (!settings.show_count) {
return [[], 0]
}

const apiBase = `${getServerURL()}/v1`
const requestURL = new URL(`${apiBase}/organizations/${orgId}/customers`)
requestURL.searchParams.append('customer_types', OrganizationCustomerType.PAID_SUBSCRIPTION)
if (settings.count_free) {
requestURL.searchParams.append('customer_types', OrganizationCustomerType.FREE_SUBSCRIPTION)
}
requestURL.searchParams.set('limit', limit.toString())

const response = await fetch(url, {
const response = await fetch(requestURL.toString(), {
method: 'GET',
})
const data = (await response.json()) as ListResourceOrganizationCustomer
Expand Down

0 comments on commit 240e1d7

Please sign in to comment.