Taxes
The tax service calculates applicable taxes for a transaction. Use it to determine tax amounts before creating a payment or to display tax breakdowns to your customers.
import { createOakClient, createTaxService } from '@oaknetwork/payments-sdk';
const client = createOakClient({ ... });
const taxes = createTaxService(client);
Methods
| Method | Description |
|---|---|
calculate(request) | Calculate taxes for a transaction |
Calculate taxes
const result = await taxes.calculate({
amount: 10000,
currency: 'usd',
customer_id: 'cus_abc123',
});
if (result.ok) {
const tax = result.value.data;
console.log('Tax amount:', tax.tax_amount);
console.log('Total with tax:', tax.total_amount);
console.log('Tax rate:', tax.tax_rate);
}
Request fields
| Field | Type | Required | Description |
|---|---|---|---|
amount | number | Yes | Transaction amount in smallest currency unit |
currency | string | Yes | Currency code |
customer_id | string | Yes | Customer ID (used to determine tax jurisdiction) |
Response data
CalculateResponse
| Field | Type | Description |
|---|---|---|
tax_amount | number | Calculated tax amount |
total_amount | number | Amount including tax |
tax_rate | number | Applied tax rate |
jurisdiction | string | Tax jurisdiction |
breakdown | array | Itemized tax breakdown |