//native
type Zoho = {
token: string;
};
/**
* Generate payment link
* This API generates a payment link for the invoice with an expiry date.
*/
export async function main(
auth: Zoho,
transaction_id: string | undefined,
transaction_type: string | undefined,
link_type: string | undefined,
expiry_time: string | undefined,
organization_id: string | undefined,
) {
const url = new URL(`https://www.zohoapis.com/books/v3/share/paymentlink`);
for (const [k, v] of [
["transaction_id", transaction_id],
["transaction_type", transaction_type],
["link_type", link_type],
["expiry_time", expiry_time],
["organization_id", organization_id],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
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