type Stripe = {
token: string;
};
/**
* Post invoices invoice
* Draft invoices are fully editable. Once an invoice is finalized,
monetary values, as well as collection_method, become uneditable.
If you would like to stop the Stripe Billing engine from automatically finalizing, reattempting payments on,
sending reminders for, or automatically reconciling invoices, pass
auto_advance=false.
*/
export async function main(
auth: Stripe,
invoice: string,
body: {
account_tax_ids?: string[] | "";
application_fee_amount?: number;
auto_advance?: boolean;
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
collection_method?: "charge_automatically" | "send_invoice";
custom_fields?:
| { name: string; value: string; [k: string]: unknown }[]
| "";
days_until_due?: number;
default_payment_method?: string;
default_source?: string | "";
default_tax_rates?: string[] | "";
description?: string;
discounts?:
| { coupon?: string; discount?: string; [k: string]: unknown }[]
| "";
due_date?: number;
effective_at?: number | "";
expand?: string[];
footer?: string;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
metadata?: { [k: string]: string } | "";
number?: string | "";
on_behalf_of?: string | "";
payment_settings?: {
default_mandate?: string | "";
payment_method_options?: {
acss_debit?:
| {
mandate_options?: {
transaction_type?: "business" | "personal";
[k: string]: unknown;
};
verification_method?: "automatic" | "instant" | "microdeposits";
[k: string]: unknown;
}
| "";
bancontact?:
| {
preferred_language?: "de" | "en" | "fr" | "nl";
[k: string]: unknown;
}
| "";
card?:
| {
installments?: {
enabled?: boolean;
plan?:
| {
count: number;
interval: "month";
type: "fixed_count";
[k: string]: unknown;
}
| "";
[k: string]: unknown;
};
request_three_d_secure?: "any" | "automatic" | "challenge";
[k: string]: unknown;
}
| "";
customer_balance?:
| {
bank_transfer?: {
eu_bank_transfer?: { country: string; [k: string]: unknown };
type?: string;
[k: string]: unknown;
};
funding_type?: string;
[k: string]: unknown;
}
| "";
konbini?: { [k: string]: unknown } | "";
us_bank_account?:
| {
financial_connections?: {
permissions?: (
| "balances"
| "ownership"
| "payment_method"
| "transactions"
)[];
prefetch?: ("balances" | "transactions")[];
[k: string]: unknown;
};
verification_method?: "automatic" | "instant" | "microdeposits";
[k: string]: unknown;
}
| "";
[k: string]: unknown;
};
payment_method_types?:
| (
| "ach_credit_transfer"
| "ach_debit"
| "acss_debit"
| "au_becs_debit"
| "bacs_debit"
| "bancontact"
| "boleto"
| "card"
| "cashapp"
| "customer_balance"
| "eps"
| "fpx"
| "giropay"
| "grabpay"
| "ideal"
| "konbini"
| "link"
| "p24"
| "paynow"
| "paypal"
| "promptpay"
| "sepa_debit"
| "sofort"
| "us_bank_account"
| "wechat_pay"
)[]
| "";
[k: string]: unknown;
};
rendering?: {
amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
pdf?: { page_size?: "a4" | "auto" | "letter"; [k: string]: unknown };
[k: string]: unknown;
};
shipping_cost?:
| {
shipping_rate?: string;
shipping_rate_data?: {
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;
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";
[k: string]: unknown;
};
[k: string]: unknown;
}
| "";
shipping_details?:
| {
address: {
city?: string;
country?: string;
line1?: string;
line2?: string;
postal_code?: string;
state?: string;
[k: string]: unknown;
};
name: string;
phone?: string | "";
[k: string]: unknown;
}
| "";
statement_descriptor?: string;
transfer_data?:
| { amount?: number; destination: string; [k: string]: unknown }
| "";
}
) {
const url = new URL(`https://api.stripe.com/v1/invoices/${invoice}`);
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 invoices invoice
* Draft invoices are fully editable. Once an invoice is finalized,
monetary values, as well as collection_method, become uneditable.
If you would like to stop the Stripe Billing engine from automatically finalizing, reattempting payments on,
sending reminders for, or automatically reconciling invoices, pass
auto_advance=false.
*/
export async function main(
auth: Stripe,
invoice: string,
body: {
account_tax_ids?: string[] | "";
application_fee_amount?: number;
auto_advance?: boolean;
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
collection_method?: "charge_automatically" | "send_invoice";
custom_fields?:
| { name: string; value: string; [k: string]: unknown }[]
| "";
days_until_due?: number;
default_payment_method?: string;
default_source?: string | "";
default_tax_rates?: string[] | "";
description?: string;
discounts?:
| { coupon?: string; discount?: string; [k: string]: unknown }[]
| "";
due_date?: number;
effective_at?: number | "";
expand?: string[];
footer?: string;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
metadata?: { [k: string]: string } | "";
number?: string | "";
on_behalf_of?: string | "";
payment_settings?: {
default_mandate?: string | "";
payment_method_options?: {
acss_debit?:
| {
mandate_options?: {
transaction_type?: "business" | "personal";
[k: string]: unknown;
};
verification_method?: "automatic" | "instant" | "microdeposits";
[k: string]: unknown;
}
| "";
bancontact?:
| {
preferred_language?: "de" | "en" | "fr" | "nl";
[k: string]: unknown;
}
| "";
card?:
| {
installments?: {
enabled?: boolean;
plan?:
| {
count: number;
interval: "month";
type: "fixed_count";
[k: string]: unknown;
}
| "";
[k: string]: unknown;
};
request_three_d_secure?: "any" | "automatic" | "challenge";
[k: string]: unknown;
}
| "";
customer_balance?:
| {
bank_transfer?: {
eu_bank_transfer?: { country: string; [k: string]: unknown };
type?: string;
[k: string]: unknown;
};
funding_type?: string;
[k: string]: unknown;
}
| "";
konbini?: { [k: string]: unknown } | "";
us_bank_account?:
| {
financial_connections?: {
permissions?: (
| "balances"
| "ownership"
| "payment_method"
| "transactions"
)[];
prefetch?: ("balances" | "transactions")[];
[k: string]: unknown;
};
verification_method?: "automatic" | "instant" | "microdeposits";
[k: string]: unknown;
}
| "";
[k: string]: unknown;
};
payment_method_types?:
| (
| "ach_credit_transfer"
| "ach_debit"
| "acss_debit"
| "au_becs_debit"
| "bacs_debit"
| "bancontact"
| "boleto"
| "card"
| "cashapp"
| "customer_balance"
| "eps"
| "fpx"
| "giropay"
| "grabpay"
| "ideal"
| "konbini"
| "link"
| "p24"
| "paynow"
| "paypal"
| "promptpay"
| "sepa_debit"
| "sofort"
| "us_bank_account"
| "wechat_pay"
)[]
| "";
[k: string]: unknown;
};
rendering?: {
amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
pdf?: { page_size?: "a4" | "auto" | "letter"; [k: string]: unknown };
[k: string]: unknown;
};
shipping_cost?:
| {
shipping_rate?: string;
shipping_rate_data?: {
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;
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";
[k: string]: unknown;
};
[k: string]: unknown;
}
| "";
shipping_details?:
| {
address: {
city?: string;
country?: string;
line1?: string;
line2?: string;
postal_code?: string;
state?: string;
[k: string]: unknown;
};
name: string;
phone?: string | "";
[k: string]: unknown;
}
| "";
statement_descriptor?: string;
transfer_data?:
| { amount?: number; destination: string; [k: string]: unknown }
| "";
}
) {
const url = new URL(`https://api.stripe.com/v1/invoices/${invoice}`);
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 invoices invoice
* <p>Draft invoices are fully editable. Once an invoice is <a href="/docs/billing/invoices/workflow#finalized">finalized</a>,
monetary values, as well as <code>collection_method</code>, become uneditable.</p>
<p>If you would like to stop the Stripe Billing engine from automatically finalizing, reattempting payments on,
sending reminders for, or <a href="/docs/billing/invoices/reconciliation">automatically reconciling</a> invoices, pass
<code>auto_advance=false</code>.</p>
*/
export async function main(
auth: Stripe,
invoice: string,
body: {
account_tax_ids?: string[] | "";
application_fee_amount?: number;
auto_advance?: boolean;
automatic_tax?: { enabled: boolean; [k: string]: unknown };
collection_method?: "charge_automatically" | "send_invoice";
custom_fields?:
| { name: string; value: string; [k: string]: unknown }[]
| "";
days_until_due?: number;
default_payment_method?: string;
default_source?: string | "";
default_tax_rates?: string[] | "";
description?: string;
discounts?:
| { coupon?: string; discount?: string; [k: string]: unknown }[]
| "";
due_date?: number;
effective_at?: number | "";
expand?: string[];
footer?: string;
metadata?: { [k: string]: string } | "";
on_behalf_of?: string | "";
payment_settings?: {
default_mandate?: string | "";
payment_method_options?: {
acss_debit?:
| {
mandate_options?: {
transaction_type?: "business" | "personal";
[k: string]: unknown;
};
verification_method?: "automatic" | "instant" | "microdeposits";
[k: string]: unknown;
}
| "";
bancontact?:
| {
preferred_language?: "de" | "en" | "fr" | "nl";
[k: string]: unknown;
}
| "";
card?:
| {
installments?: {
enabled?: boolean;
plan?:
| {
count: number;
interval: "month";
type: "fixed_count";
[k: string]: unknown;
}
| "";
[k: string]: unknown;
};
request_three_d_secure?: "any" | "automatic";
[k: string]: unknown;
}
| "";
customer_balance?:
| {
bank_transfer?: {
eu_bank_transfer?: { country: string; [k: string]: unknown };
type?: string;
[k: string]: unknown;
};
funding_type?: string;
[k: string]: unknown;
}
| "";
konbini?: { [k: string]: unknown } | "";
us_bank_account?:
| {
financial_connections?: {
permissions?: (
| "balances"
| "ownership"
| "payment_method"
| "transactions"
)[];
prefetch?: "balances"[];
[k: string]: unknown;
};
verification_method?: "automatic" | "instant" | "microdeposits";
[k: string]: unknown;
}
| "";
[k: string]: unknown;
};
payment_method_types?:
| (
| "ach_credit_transfer"
| "ach_debit"
| "acss_debit"
| "au_becs_debit"
| "bacs_debit"
| "bancontact"
| "boleto"
| "card"
| "cashapp"
| "customer_balance"
| "fpx"
| "giropay"
| "grabpay"
| "ideal"
| "konbini"
| "link"
| "paynow"
| "paypal"
| "promptpay"
| "sepa_debit"
| "sofort"
| "us_bank_account"
| "wechat_pay"
)[]
| "";
[k: string]: unknown;
};
rendering?: {
amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
pdf?: { page_size?: "a4" | "auto" | "letter"; [k: string]: unknown };
[k: string]: unknown;
};
shipping_cost?:
| {
shipping_rate?: string;
shipping_rate_data?: {
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;
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";
[k: string]: unknown;
};
[k: string]: unknown;
}
| "";
shipping_details?:
| {
address: {
city?: string;
country?: string;
line1?: string;
line2?: string;
postal_code?: string;
state?: string;
[k: string]: unknown;
};
name: string;
phone?: string | "";
[k: string]: unknown;
}
| "";
statement_descriptor?: string;
transfer_data?:
| { amount?: number; destination: string; [k: string]: unknown }
| "";
}
) {
const url = new URL(`https://api.stripe.com/v1/invoices/${invoice}`);
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