//native
type Zoho = {
token: string;
};
/**
* Create a subscription
* Create a hosted page for a new subscription. To create a subscription for a new customer, you have to pass the customer object. To create a subscription for a existing customer pass the customer_id of that customer.
*/
export async function main(
auth: Zoho,
X_com_zoho_subscriptions_organizationid: string,
body: {
customer_id: {};
pricebook_id?: string;
customer: {
display_name: string;
salutation?: string;
first_name?: string;
last_name?: string;
email: string;
company_name?: string;
billing_address?: {
attention?: string;
street?: string;
city?: string;
state?: string;
country?: string;
zip?: string;
fax?: string;
};
shipping_address?: {
attention?: string;
street?: string;
city?: string;
state?: string;
country?: string;
zip?: string;
fax?: string;
};
pricebook_id?: string;
payment_terms?: number;
payment_terms_label?: string;
exchange_rate?: never;
currency_code?: string;
vat_treatment?: string;
vat_reg_no?: string;
country_code?: string;
is_taxable?: string;
tax_id?: string;
tax_authority_id: string;
tax_authority_name: string;
tax_exemption_id?: string;
tax_exemption_code?: string;
default_templates?: {
invoice_template_id?: string;
creditnote_template_id?: string;
};
place_of_contact?: string;
gst_no?: string;
gst_treatment?: string;
};
contactpersons?: { contactperson_id: string }[];
plan: {
plan_code: string;
plan_description?: string;
price?: number;
setup_fee?: never;
setup_fee_tax_id?: string;
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;
redirect_url?: string;
salesperson_name?: string;
template_id?: number;
can_charge_setup_fee_immediately?: false | true;
exchange_rate?: never;
place_of_supply?: string;
gst_treatment?: string;
gst_no?: string;
cfdi_usage?: string;
payment_gateways?: { payment_gateway?: string }[];
billing_address_id?: string;
shipping_address_id?: string;
branch_id?: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/billing/v1/hostedpages/newsubscription`,
);
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