type Baremetrics = {
apiKey: string
}
export async function main(
resource: Baremetrics,
sourceId: string,
body: {
oid: string
name: string
currency: string
amount: number
interval: 'day' | 'month' | 'year'
interval_count: number
trial_duration?: number
trial_duration_unit?: 'day' | 'month' | 'year'
}
) {
const endpoint = `https://api.baremetrics.com/v1/${sourceId}/plans`
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${resource.apiKey}`
},
body: JSON.stringify(body)
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data.plan
}
Submitted by hugo697 118 days ago