//native
type Zoho = {
token: string;
};
/**
* Add Charge
* Charge a one-time amount for the subscription.
*/
export async function main(
auth: Zoho,
subscription_id: string,
X_com_zoho_subscriptions_organizationid: string,
body: {
amount: number;
description?: {};
tags?: { tag_id?: number; tag_option_id?: number }[];
item_custom_fields?: { label?: string; value?: string }[];
account_id?: string;
add_to_unbilled_charges?: false | true;
},
) {
const url = new URL(
`https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}/charge`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-com-zoho-subscriptions-organizationid":
X_com_zoho_subscriptions_organizationid,
"Content-Type": "application/json",
Authorization: "Zoho-oauthtoken " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago