type Stripe = {
token: string;
};
/**
* Post shipping rates
* Creates a new shipping rate object.
*/
export async function main(
auth: Stripe,
body: {
delivery_estimate?: {
maximum?: {
unit: "business_day" | "day" | "hour" | "month" | "week";
value: number;
[k: string]: unknown;
};
minimum?: {
unit: "business_day" | "day" | "hour" | "month" | "week";
value: number;
[k: string]: unknown;
};
[k: string]: unknown;
};
display_name: string;
expand?: string[];
fixed_amount?: {
amount: number;
currency: string;
currency_options?: {
[k: string]: {
amount: number;
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
[k: string]: unknown;
};
};
[k: string]: unknown;
};
metadata?: { [k: string]: string };
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
tax_code?: string;
type?: "fixed_amount";
}
) {
const url = new URL(`https://api.stripe.com/v1/shipping_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 shipping rates
* Creates a new shipping rate object.
*/
export async function main(
auth: Stripe,
body: {
delivery_estimate?: {
maximum?: {
unit: "business_day" | "day" | "hour" | "month" | "week";
value: number;
[k: string]: unknown;
};
minimum?: {
unit: "business_day" | "day" | "hour" | "month" | "week";
value: number;
[k: string]: unknown;
};
[k: string]: unknown;
};
display_name: string;
expand?: string[];
fixed_amount?: {
amount: number;
currency: string;
currency_options?: {
[k: string]: {
amount: number;
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
[k: string]: unknown;
};
};
[k: string]: unknown;
};
metadata?: { [k: string]: string };
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
tax_code?: string;
type?: "fixed_amount";
}
) {
const url = new URL(`https://api.stripe.com/v1/shipping_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 shipping rates
* <p>Creates a new shipping rate object.</p>
*/
export async function main(
auth: Stripe,
body: {
delivery_estimate?: {
maximum?: {
unit: "business_day" | "day" | "hour" | "month" | "week";
value: number;
[k: string]: unknown;
};
minimum?: {
unit: "business_day" | "day" | "hour" | "month" | "week";
value: number;
[k: string]: unknown;
};
[k: string]: unknown;
};
display_name: string;
expand?: string[];
fixed_amount?: {
amount: number;
currency: string;
currency_options?: {
[k: string]: {
amount: number;
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
[k: string]: unknown;
};
};
[k: string]: unknown;
};
metadata?: { [k: string]: string };
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
tax_code?: string;
type?: "fixed_amount";
}
) {
const url = new URL(`https://api.stripe.com/v1/shipping_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