type Stripe = {
token: string;
};
/**
* Get subscriptions
* By default, returns a list of subscriptions that have not been canceled. In order to list canceled subscriptions, specify status=canceled.
*/
export async function main(
auth: Stripe,
automatic_tax: any,
collection_method: "charge_automatically" | "send_invoice" | undefined,
created: any,
current_period_end: any,
current_period_start: any,
customer: string | undefined,
ending_before: string | undefined,
expand: any,
limit: string | undefined,
price: string | undefined,
starting_after: string | undefined,
status:
| "active"
| "all"
| "canceled"
| "ended"
| "incomplete"
| "incomplete_expired"
| "past_due"
| "paused"
| "trialing"
| "unpaid"
| undefined,
test_clock: string | undefined
) {
const url = new URL(`https://api.stripe.com/v1/subscriptions`);
for (const [k, v] of [
["collection_method", collection_method],
["customer", customer],
["ending_before", ending_before],
["limit", limit],
["price", price],
["starting_after", starting_after],
["status", status],
["test_clock", test_clock],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
encodeParams({
automatic_tax,
created,
current_period_end,
current_period_start,
expand,
}).forEach((v, k) => {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
});
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
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 291 days ago
type Stripe = {
token: string;
};
/**
* Get subscriptions
* <p>By default, returns a list of subscriptions that have not been canceled. In order to list canceled subscriptions, specify <code>status=canceled</code>.</p>
*/
export async function main(
auth: Stripe,
automatic_tax: any,
collection_method: "charge_automatically" | "send_invoice" | undefined,
created: any,
current_period_end: any,
current_period_start: any,
customer: string | undefined,
ending_before: string | undefined,
expand: any,
limit: string | undefined,
price: string | undefined,
starting_after: string | undefined,
status:
| "active"
| "all"
| "canceled"
| "ended"
| "incomplete"
| "incomplete_expired"
| "past_due"
| "paused"
| "trialing"
| "unpaid"
| undefined,
test_clock: string | undefined
) {
const url = new URL(`https://api.stripe.com/v1/subscriptions`);
for (const [k, v] of [
["collection_method", collection_method],
["customer", customer],
["ending_before", ending_before],
["limit", limit],
["price", price],
["starting_after", starting_after],
["status", status],
["test_clock", test_clock],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
encodeParams({
automatic_tax,
created,
current_period_end,
current_period_start,
expand,
}).forEach((v, k) => {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
});
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
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 419 days ago