type Abstractapi = {
apiKey: string
}
export async function main(
resource: Abstractapi,
amount: number,
countryCode: string,
vatCategory?: string
) {
const queryParams = new URLSearchParams({
api_key: resource.apiKey,
amount: amount.toString(),
country_code: countryCode
})
if (vatCategory) {
queryParams.append('vat_category', vatCategory)
}
const endpoint = `https://vat.abstractapi.com/v1/calculate?${queryParams.toString()}`
const response = await fetch(endpoint, {
method: 'GET'
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 77 days ago