type Stripe = {
token: string;
};
/**
* Post tax rates
* Creates a new tax rate.
*/
export async function main(
auth: Stripe,
body: {
active?: boolean;
country?: string;
description?: string;
display_name: string;
expand?: string[];
inclusive: boolean;
jurisdiction?: string;
metadata?: { [k: string]: string };
percentage: number;
state?: string;
tax_type?:
| "amusement_tax"
| "communications_tax"
| "gst"
| "hst"
| "igst"
| "jct"
| "lease_tax"
| "pst"
| "qst"
| "rst"
| "sales_tax"
| "vat";
}
) {
const url = new URL(`https://api.stripe.com/v1/tax_rates`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: encodeParams(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
function encodeParams(o: any) {
function iter(o: any, path: string) {
if (Array.isArray(o)) {
o.forEach(function (a) {
iter(a, path + "[]");
});
return;
}
if (o !== null && typeof o === "object") {
Object.keys(o).forEach(function (k) {
iter(o[k], path + "[" + k + "]");
});
return;
}
data.push(path + "=" + o);
}
const data: string[] = [];
Object.keys(o).forEach(function (k) {
if (o[k] !== undefined) {
iter(o[k], k);
}
});
return new URLSearchParams(data.join("&"));
}
Submitted by hugo697 368 days ago
type Stripe = {
token: string;
};
/**
* Post tax rates
* Creates a new tax rate.
*/
export async function main(
auth: Stripe,
body: {
active?: boolean;
country?: string;
description?: string;
display_name: string;
expand?: string[];
inclusive: boolean;
jurisdiction?: string;
metadata?: { [k: string]: string };
percentage: number;
state?: string;
tax_type?:
| "amusement_tax"
| "communications_tax"
| "gst"
| "hst"
| "igst"
| "jct"
| "lease_tax"
| "pst"
| "qst"
| "rst"
| "sales_tax"
| "vat";
}
) {
const url = new URL(`https://api.stripe.com/v1/tax_rates`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: encodeParams(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
function encodeParams(o: any) {
function iter(o: any, path: string) {
if (Array.isArray(o)) {
o.forEach(function (a) {
iter(a, path + "[]");
});
return;
}
if (o !== null && typeof o === "object") {
Object.keys(o).forEach(function (k) {
iter(o[k], path + "[" + k + "]");
});
return;
}
data.push(path + "=" + o);
}
const data: string[] = [];
Object.keys(o).forEach(function (k) {
if (o[k] !== undefined) {
iter(o[k], k);
}
});
return new URLSearchParams(data.join("&"));
}
Submitted by hugo697 795 days ago
type Stripe = {
token: string;
};
/**
* Post tax rates
* <p>Creates a new tax rate.</p>
*/
export async function main(
auth: Stripe,
body: {
active?: boolean;
country?: string;
description?: string;
display_name: string;
expand?: string[];
inclusive: boolean;
jurisdiction?: string;
metadata?: { [k: string]: string };
percentage: number;
state?: string;
tax_type?:
| "amusement_tax"
| "communications_tax"
| "gst"
| "hst"
| "igst"
| "jct"
| "lease_tax"
| "pst"
| "qst"
| "rst"
| "sales_tax"
| "service_tax"
| "vat";
}
) {
const url = new URL(`https://api.stripe.com/v1/tax_rates`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: encodeParams(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
function encodeParams(o: any) {
function iter(o: any, path: string) {
if (Array.isArray(o)) {
o.forEach(function (a) {
iter(a, path + "[]");
});
return;
}
if (o !== null && typeof o === "object") {
Object.keys(o).forEach(function (k) {
iter(o[k], path + "[" + k + "]");
});
return;
}
data.push(path + "=" + o);
}
const data: string[] = [];
Object.keys(o).forEach(function (k) {
if (o[k] !== undefined) {
iter(o[k], k);
}
});
return new URLSearchParams(data.join("&"));
}
Submitted by hugo697 922 days ago