//native
type Zoho = {
token: string;
};
/**
* Cancel a subscription
* Your subscription can be either cancelled immediately or at the end of the current term based on the value of `cancel_at_end`.
*/
export async function main(
auth: Zoho,
subscription_id: string,
cancel_at_end: string | undefined,
X_com_zoho_subscriptions_organizationid: string,
) {
const url = new URL(
`https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}/cancel`,
);
for (const [k, v] of [["cancel_at_end", cancel_at_end]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"X-com-zoho-subscriptions-organizationid":
X_com_zoho_subscriptions_organizationid,
Authorization: "Zoho-oauthtoken " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago