type Stripe = {
token: string;
};
/**
* Post billing portal configurations
* Creates a configuration that describes the functionality and behavior of a PortalSession
*/
export async function main(
auth: Stripe,
body: {
business_profile: {
headline?: string | "";
privacy_policy_url?: string;
terms_of_service_url?: string;
[k: string]: unknown;
};
default_return_url?: string | "";
expand?: string[];
features: {
customer_update?: {
allowed_updates?:
| ("address" | "email" | "name" | "phone" | "shipping" | "tax_id")[]
| "";
enabled: boolean;
[k: string]: unknown;
};
invoice_history?: { enabled: boolean; [k: string]: unknown };
payment_method_update?: { enabled: boolean; [k: string]: unknown };
subscription_cancel?: {
cancellation_reason?: {
enabled: boolean;
options:
| (
| "customer_service"
| "low_quality"
| "missing_features"
| "other"
| "switched_service"
| "too_complex"
| "too_expensive"
| "unused"
)[]
| "";
[k: string]: unknown;
};
enabled: boolean;
mode?: "at_period_end" | "immediately";
proration_behavior?: "always_invoice" | "create_prorations" | "none";
[k: string]: unknown;
};
subscription_pause?: { enabled?: boolean; [k: string]: unknown };
subscription_update?: {
default_allowed_updates:
| ("price" | "promotion_code" | "quantity")[]
| "";
enabled: boolean;
products:
| { prices: string[]; product: string; [k: string]: unknown }[]
| "";
proration_behavior?: "always_invoice" | "create_prorations" | "none";
[k: string]: unknown;
};
[k: string]: unknown;
};
login_page?: { enabled: boolean; [k: string]: unknown };
metadata?: { [k: string]: string };
}
) {
const url = new URL(
`https://api.stripe.com/v1/billing_portal/configurations`
);
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 billing portal configurations
* Creates a configuration that describes the functionality and behavior of a PortalSession
*/
export async function main(
auth: Stripe,
body: {
business_profile: {
headline?: string | "";
privacy_policy_url?: string;
terms_of_service_url?: string;
[k: string]: unknown;
};
default_return_url?: string | "";
expand?: string[];
features: {
customer_update?: {
allowed_updates?:
| ("address" | "email" | "name" | "phone" | "shipping" | "tax_id")[]
| "";
enabled: boolean;
[k: string]: unknown;
};
invoice_history?: { enabled: boolean; [k: string]: unknown };
payment_method_update?: { enabled: boolean; [k: string]: unknown };
subscription_cancel?: {
cancellation_reason?: {
enabled: boolean;
options:
| (
| "customer_service"
| "low_quality"
| "missing_features"
| "other"
| "switched_service"
| "too_complex"
| "too_expensive"
| "unused"
)[]
| "";
[k: string]: unknown;
};
enabled: boolean;
mode?: "at_period_end" | "immediately";
proration_behavior?: "always_invoice" | "create_prorations" | "none";
[k: string]: unknown;
};
subscription_pause?: { enabled?: boolean; [k: string]: unknown };
subscription_update?: {
default_allowed_updates:
| ("price" | "promotion_code" | "quantity")[]
| "";
enabled: boolean;
products:
| { prices: string[]; product: string; [k: string]: unknown }[]
| "";
proration_behavior?: "always_invoice" | "create_prorations" | "none";
[k: string]: unknown;
};
[k: string]: unknown;
};
login_page?: { enabled: boolean; [k: string]: unknown };
metadata?: { [k: string]: string };
}
) {
const url = new URL(
`https://api.stripe.com/v1/billing_portal/configurations`
);
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 billing portal configurations
* <p>Creates a configuration that describes the functionality and behavior of a PortalSession</p>
*/
export async function main(
auth: Stripe,
body: {
business_profile: {
headline?: string | "";
privacy_policy_url?: string;
terms_of_service_url?: string;
[k: string]: unknown;
};
default_return_url?: string | "";
expand?: string[];
features: {
customer_update?: {
allowed_updates?:
| ("address" | "email" | "name" | "phone" | "shipping" | "tax_id")[]
| "";
enabled: boolean;
[k: string]: unknown;
};
invoice_history?: { enabled: boolean; [k: string]: unknown };
payment_method_update?: { enabled: boolean; [k: string]: unknown };
subscription_cancel?: {
cancellation_reason?: {
enabled: boolean;
options:
| (
| "customer_service"
| "low_quality"
| "missing_features"
| "other"
| "switched_service"
| "too_complex"
| "too_expensive"
| "unused"
)[]
| "";
[k: string]: unknown;
};
enabled: boolean;
mode?: "at_period_end" | "immediately";
proration_behavior?: "always_invoice" | "create_prorations" | "none";
[k: string]: unknown;
};
subscription_pause?: { enabled?: boolean; [k: string]: unknown };
subscription_update?: {
default_allowed_updates:
| ("price" | "promotion_code" | "quantity")[]
| "";
enabled: boolean;
products:
| { prices: string[]; product: string; [k: string]: unknown }[]
| "";
proration_behavior?: "always_invoice" | "create_prorations" | "none";
[k: string]: unknown;
};
[k: string]: unknown;
};
login_page?: { enabled: boolean; [k: string]: unknown };
metadata?: { [k: string]: string };
}
) {
const url = new URL(
`https://api.stripe.com/v1/billing_portal/configurations`
);
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