type Stripe = {
token: string;
};
/**
* Post quotes quote
* A quote models prices and services for a customer.
*/
export async function main(
auth: Stripe,
quote: string,
body: {
application_fee_amount?: number | "";
application_fee_percent?: number | "";
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
collection_method?: "charge_automatically" | "send_invoice";
customer?: string;
default_tax_rates?: string[] | "";
description?: string | "";
discounts?:
| { coupon?: string; discount?: string; [k: string]: unknown }[]
| "";
expand?: string[];
expires_at?: number;
footer?: string | "";
header?: string | "";
invoice_settings?: {
days_until_due?: number;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
line_items?: {
id?: string;
price?: string;
price_data?: {
currency: string;
product: string;
recurring?: {
interval: "day" | "month" | "week" | "year";
interval_count?: number;
[k: string]: unknown;
};
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
unit_amount?: number;
unit_amount_decimal?: string;
[k: string]: unknown;
};
quantity?: number;
tax_rates?: string[] | "";
[k: string]: unknown;
}[];
metadata?: { [k: string]: string };
on_behalf_of?: string | "";
subscription_data?: {
description?: string | "";
effective_date?: "current_period_end" | number | "";
metadata?: { [k: string]: string };
trial_period_days?: number | "";
[k: string]: unknown;
};
transfer_data?:
| {
amount?: number;
amount_percent?: number;
destination: string;
[k: string]: unknown;
}
| "";
}
) {
const url = new URL(`https://api.stripe.com/v1/quotes/${quote}`);
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 quotes quote
* A quote models prices and services for a customer.
*/
export async function main(
auth: Stripe,
quote: string,
body: {
application_fee_amount?: number | "";
application_fee_percent?: number | "";
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
collection_method?: "charge_automatically" | "send_invoice";
customer?: string;
default_tax_rates?: string[] | "";
description?: string | "";
discounts?:
| { coupon?: string; discount?: string; [k: string]: unknown }[]
| "";
expand?: string[];
expires_at?: number;
footer?: string | "";
header?: string | "";
invoice_settings?: {
days_until_due?: number;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
line_items?: {
id?: string;
price?: string;
price_data?: {
currency: string;
product: string;
recurring?: {
interval: "day" | "month" | "week" | "year";
interval_count?: number;
[k: string]: unknown;
};
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
unit_amount?: number;
unit_amount_decimal?: string;
[k: string]: unknown;
};
quantity?: number;
tax_rates?: string[] | "";
[k: string]: unknown;
}[];
metadata?: { [k: string]: string };
on_behalf_of?: string | "";
subscription_data?: {
description?: string | "";
effective_date?: "current_period_end" | number | "";
metadata?: { [k: string]: string };
trial_period_days?: number | "";
[k: string]: unknown;
};
transfer_data?:
| {
amount?: number;
amount_percent?: number;
destination: string;
[k: string]: unknown;
}
| "";
}
) {
const url = new URL(`https://api.stripe.com/v1/quotes/${quote}`);
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 quotes quote
* <p>A quote models prices and services for a customer.</p>
*/
export async function main(
auth: Stripe,
quote: string,
body: {
application_fee_amount?: number | "";
application_fee_percent?: number | "";
automatic_tax?: { enabled: boolean; [k: string]: unknown };
collection_method?: "charge_automatically" | "send_invoice";
customer?: string;
default_tax_rates?: string[] | "";
description?: string | "";
discounts?:
| { coupon?: string; discount?: string; [k: string]: unknown }[]
| "";
expand?: string[];
expires_at?: number;
footer?: string | "";
header?: string | "";
invoice_settings?: { days_until_due?: number; [k: string]: unknown };
line_items?: {
id?: string;
price?: string;
price_data?: {
currency: string;
product: string;
recurring?: {
interval: "day" | "month" | "week" | "year";
interval_count?: number;
[k: string]: unknown;
};
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
unit_amount?: number;
unit_amount_decimal?: string;
[k: string]: unknown;
};
quantity?: number;
tax_rates?: string[] | "";
[k: string]: unknown;
}[];
metadata?: { [k: string]: string };
on_behalf_of?: string | "";
subscription_data?: {
description?: string | "";
effective_date?: "current_period_end" | number | "";
trial_period_days?: number | "";
[k: string]: unknown;
};
transfer_data?:
| {
amount?: number;
amount_percent?: number;
destination: string;
[k: string]: unknown;
}
| "";
}
) {
const url = new URL(`https://api.stripe.com/v1/quotes/${quote}`);
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