type Stripe = {
token: string;
};
/**
* Post subscription schedules schedule
* Updates an existing subscription schedule.
*/
export async function main(
auth: Stripe,
schedule: string,
body: {
default_settings?: {
application_fee_percent?: number;
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
billing_cycle_anchor?: "automatic" | "phase_start";
billing_thresholds?:
| {
amount_gte?: number;
reset_billing_cycle_anchor?: boolean;
[k: string]: unknown;
}
| "";
collection_method?: "charge_automatically" | "send_invoice";
default_payment_method?: string;
description?: string | "";
invoice_settings?: {
account_tax_ids?: string[] | "";
days_until_due?: number;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
on_behalf_of?: string | "";
transfer_data?:
| { amount_percent?: number; destination: string; [k: string]: unknown }
| "";
[k: string]: unknown;
};
end_behavior?: "cancel" | "none" | "release" | "renew";
expand?: string[];
metadata?: { [k: string]: string } | "";
phases?: {
add_invoice_items?: {
price?: string;
price_data?: {
currency: string;
product: string;
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
unit_amount?: number;
unit_amount_decimal?: string;
[k: string]: unknown;
};
quantity?: number;
tax_rates?: string[] | "";
[k: string]: unknown;
}[];
application_fee_percent?: number;
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
billing_cycle_anchor?: "automatic" | "phase_start";
billing_thresholds?:
| {
amount_gte?: number;
reset_billing_cycle_anchor?: boolean;
[k: string]: unknown;
}
| "";
collection_method?: "charge_automatically" | "send_invoice";
coupon?: string;
default_payment_method?: string;
default_tax_rates?: string[] | "";
description?: string | "";
end_date?: number | "now";
invoice_settings?: {
account_tax_ids?: string[] | "";
days_until_due?: number;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
items: {
billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
metadata?: { [k: string]: 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;
}[];
iterations?: number;
metadata?: { [k: string]: string };
on_behalf_of?: string;
proration_behavior?: "always_invoice" | "create_prorations" | "none";
start_date?: number | "now";
transfer_data?: {
amount_percent?: number;
destination: string;
[k: string]: unknown;
};
trial?: boolean;
trial_end?: number | "now";
[k: string]: unknown;
}[];
proration_behavior?: "always_invoice" | "create_prorations" | "none";
}
) {
const url = new URL(
`https://api.stripe.com/v1/subscription_schedules/${schedule}`
);
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 subscription schedules schedule
* Updates an existing subscription schedule.
*/
export async function main(
auth: Stripe,
schedule: string,
body: {
default_settings?: {
application_fee_percent?: number;
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
billing_cycle_anchor?: "automatic" | "phase_start";
billing_thresholds?:
| {
amount_gte?: number;
reset_billing_cycle_anchor?: boolean;
[k: string]: unknown;
}
| "";
collection_method?: "charge_automatically" | "send_invoice";
default_payment_method?: string;
description?: string | "";
invoice_settings?: {
account_tax_ids?: string[] | "";
days_until_due?: number;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
on_behalf_of?: string | "";
transfer_data?:
| { amount_percent?: number; destination: string; [k: string]: unknown }
| "";
[k: string]: unknown;
};
end_behavior?: "cancel" | "none" | "release" | "renew";
expand?: string[];
metadata?: { [k: string]: string } | "";
phases?: {
add_invoice_items?: {
price?: string;
price_data?: {
currency: string;
product: string;
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
unit_amount?: number;
unit_amount_decimal?: string;
[k: string]: unknown;
};
quantity?: number;
tax_rates?: string[] | "";
[k: string]: unknown;
}[];
application_fee_percent?: number;
automatic_tax?: {
enabled: boolean;
liability?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
billing_cycle_anchor?: "automatic" | "phase_start";
billing_thresholds?:
| {
amount_gte?: number;
reset_billing_cycle_anchor?: boolean;
[k: string]: unknown;
}
| "";
collection_method?: "charge_automatically" | "send_invoice";
coupon?: string;
default_payment_method?: string;
default_tax_rates?: string[] | "";
description?: string | "";
end_date?: number | "now";
invoice_settings?: {
account_tax_ids?: string[] | "";
days_until_due?: number;
issuer?: {
account?: string;
type: "account" | "self";
[k: string]: unknown;
};
[k: string]: unknown;
};
items: {
billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
metadata?: { [k: string]: 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;
}[];
iterations?: number;
metadata?: { [k: string]: string };
on_behalf_of?: string;
proration_behavior?: "always_invoice" | "create_prorations" | "none";
start_date?: number | "now";
transfer_data?: {
amount_percent?: number;
destination: string;
[k: string]: unknown;
};
trial?: boolean;
trial_end?: number | "now";
[k: string]: unknown;
}[];
proration_behavior?: "always_invoice" | "create_prorations" | "none";
}
) {
const url = new URL(
`https://api.stripe.com/v1/subscription_schedules/${schedule}`
);
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 subscription schedules schedule
* <p>Updates an existing subscription schedule.</p>
*/
export async function main(
auth: Stripe,
schedule: string,
body: {
default_settings?: {
application_fee_percent?: number;
automatic_tax?: { enabled: boolean; [k: string]: unknown };
billing_cycle_anchor?: "automatic" | "phase_start";
billing_thresholds?:
| {
amount_gte?: number;
reset_billing_cycle_anchor?: boolean;
[k: string]: unknown;
}
| "";
collection_method?: "charge_automatically" | "send_invoice";
default_payment_method?: string;
description?: string | "";
invoice_settings?: { days_until_due?: number; [k: string]: unknown };
on_behalf_of?: string | "";
transfer_data?:
| { amount_percent?: number; destination: string; [k: string]: unknown }
| "";
[k: string]: unknown;
};
end_behavior?: "cancel" | "none" | "release" | "renew";
expand?: string[];
metadata?: { [k: string]: string } | "";
phases?: {
add_invoice_items?: {
price?: string;
price_data?: {
currency: string;
product: string;
tax_behavior?: "exclusive" | "inclusive" | "unspecified";
unit_amount?: number;
unit_amount_decimal?: string;
[k: string]: unknown;
};
quantity?: number;
tax_rates?: string[] | "";
[k: string]: unknown;
}[];
application_fee_percent?: number;
automatic_tax?: { enabled: boolean; [k: string]: unknown };
billing_cycle_anchor?: "automatic" | "phase_start";
billing_thresholds?:
| {
amount_gte?: number;
reset_billing_cycle_anchor?: boolean;
[k: string]: unknown;
}
| "";
collection_method?: "charge_automatically" | "send_invoice";
coupon?: string;
default_payment_method?: string;
default_tax_rates?: string[] | "";
description?: string | "";
end_date?: number | "now";
invoice_settings?: { days_until_due?: number; [k: string]: unknown };
items: {
billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
metadata?: { [k: string]: 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;
}[];
iterations?: number;
metadata?: { [k: string]: string };
on_behalf_of?: string;
proration_behavior?: "always_invoice" | "create_prorations" | "none";
start_date?: number | "now";
transfer_data?: {
amount_percent?: number;
destination: string;
[k: string]: unknown;
};
trial?: boolean;
trial_end?: number | "now";
[k: string]: unknown;
}[];
proration_behavior?: "always_invoice" | "create_prorations" | "none";
}
) {
const url = new URL(
`https://api.stripe.com/v1/subscription_schedules/${schedule}`
);
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