type Stripe = {
token: string;
};
/**
* Delete subscriptions subscription exposed id
* Cancels a customer’s subscription immediately.
*/
export async function main(
auth: Stripe,
subscription_exposed_id: string,
body: {
cancellation_details?: {
comment?: string | "";
feedback?:
| ""
| "customer_service"
| "low_quality"
| "missing_features"
| "other"
| "switched_service"
| "too_complex"
| "too_expensive"
| "unused";
[k: string]: unknown;
};
expand?: string[];
invoice_now?: boolean;
prorate?: boolean;
}
) {
const url = new URL(
`https://api.stripe.com/v1/subscriptions/${subscription_exposed_id}`
);
const response = await fetch(url, {
method: "DELETE",
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 74 days ago
type Stripe = {
token: string;
};
/**
* Delete subscriptions subscription exposed id
* <p>Cancels a customer’s subscription immediately.
*/
export async function main(
auth: Stripe,
subscription_exposed_id: string,
body: {
cancellation_details?: {
comment?: string | "";
feedback?:
| ""
| "customer_service"
| "low_quality"
| "missing_features"
| "other"
| "switched_service"
| "too_complex"
| "too_expensive"
| "unused";
[k: string]: unknown;
};
expand?: string[];
invoice_now?: boolean;
prorate?: boolean;
}
) {
const url = new URL(
`https://api.stripe.com/v1/subscriptions/${subscription_exposed_id}`
);
const response = await fetch(url, {
method: "DELETE",
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 202 days ago