type Stripe = {
token: string;
};
/**
* Post subscription items item
* Updates the plan or quantity of an item on a current subscription.
*/
export async function main(
auth: Stripe,
item: string,
body: {
billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
expand?: string[];
metadata?: { [k: string]: string } | "";
off_session?: boolean;
payment_behavior?:
| "allow_incomplete"
| "default_incomplete"
| "error_if_incomplete"
| "pending_if_incomplete";
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;
};
proration_behavior?: "always_invoice" | "create_prorations" | "none";
proration_date?: number;
quantity?: number;
tax_rates?: string[] | "";
}
) {
const url = new URL(`https://api.stripe.com/v1/subscription_items/${item}`);
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 291 days ago
type Stripe = {
token: string;
};
/**
* Post subscription items item
* <p>Updates the plan or quantity of an item on a current subscription.</p>
*/
export async function main(
auth: Stripe,
item: string,
body: {
billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
expand?: string[];
metadata?: { [k: string]: string } | "";
off_session?: boolean;
payment_behavior?:
| "allow_incomplete"
| "default_incomplete"
| "error_if_incomplete"
| "pending_if_incomplete";
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;
};
proration_behavior?: "always_invoice" | "create_prorations" | "none";
proration_date?: number;
quantity?: number;
tax_rates?: string[] | "";
}
) {
const url = new URL(`https://api.stripe.com/v1/subscription_items/${item}`);
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 419 days ago