//native
type Zoho = {
token: string;
};
/**
* Update a subscription
* Create a hosted page for a updating a subscription.
*/
export async function main(
auth: Zoho,
X_com_zoho_subscriptions_organizationid: string,
body: {
subscription_id: string;
plan: {
plan_code: string;
plan_description?: string;
price?: number;
setup_fee?: never;
quantity?: number;
tags?: { tag_id?: number; tag_option_id?: number }[];
item_custom_fields?: { label?: string; value?: string }[];
tax_id: {};
tax_exemption_id?: string;
tax_exemption_code?: string;
setup_fee_tax_exemption_id?: string;
setup_fee_tax_exemption_code?: string;
exclude_trial?: false | true;
exclude_setup_fee?: false | true;
billing_cycles?: number;
trial_days?: never;
};
addons?: {
addon_code: string;
addon_description?: string;
price?: number;
quantity?: {};
tags?: { tag_id?: number; tag_option_id?: number }[];
item_custom_fields?: { label?: string; value?: string }[];
tax_id?: {};
tax_exemption_id?: string;
tax_exemption_code?: string;
}[];
reference_id?: string;
starts_at?: string;
custom_fields?: { label?: string; value?: string }[];
coupon_code?: string;
salesperson_name?: string;
can_charge_setup_fee_immediately?: false | true;
gst_treatment?: string;
gst_no?: string;
cfdi_usage?: string;
payment_gateways?: { payment_gateway?: string }[];
exchange_rate?: never;
place_of_supply?: string;
billing_address_id?: string;
shipping_address_id?: string;
branch_id?: string;
template_id?: number;
redirect_url?: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/billing/v1/hostedpages/updatesubscription`,
);
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