Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deluge code for creating subscription in Zoho Subscriptions
ORGANISATION_ID = "PORTAL_ID";
AUTH_TOKEN = "AUTH_TOKEN";
custMap = Map();
custMap.put("is_portal_enabled",true);
update_resp = zoho.subscriptions.update("Customers", ORGANISATION_ID, customer_id, custMap);
addons = list();
internet_addons = Map();
upfront_fee = 0;
crm_account_id = application_form.Business_Company_Name_ID;
account_record = zoho.crm.getRecordById("Accounts",crm_account_id);
customer_reference_number = account_record.get("UN Customer Number");
for each product_row in application_form.Internet_Products
{
product_details = Internet_Product[ID == product_row.Product];
upfront_fee = upfront_fee + product_details.Total_Upfront_Cost;
existing_addon_str = internet_addons.get(product_details.Plan_Code);
if(existing_addon_str != null)
{
existing_addon = existing_addon_str.toMap();
existing_addon.put("quantity",existing_addon.get("quantity").toLong() + 1);
internet_addons.put(product_details.Plan_Code,existing_addon.toString());
}
else
{
addon_map = Map();
addon_map.put("addon_code",product_details.Plan_Code);
addon_map.put("addon_description","Charges for billing period (from %BillingStartDate% to %BillingEndDate%)");
addon_map.put("price",product_details.Monthly_Plan_Fee);
addon_map.put("quantity","1");
internet_addons.put(product_details.Plan_Code, addon_map.toString());
}
}
for each internet_addon_key in internet_addons.keys()
{
addons.add(internet_addons.get(internet_addon_key).toMap());
}
phone_addons = Map();
for each phone_product_row in application_form.Phone_Products
{
phone_product_details = Phone_Product[ID == phone_product_row.Phone_Product];
upfront_fee = upfront_fee + phone_product_details.Total_Upfront_Cost;
existing_addon_str = phone_addons.get(phone_product_details.Plan_Code);
info existing_addon_str;
if(existing_addon_str != null)
{
existing_addon = existing_addon_str.toMap();
existing_addon.put("quantity",existing_addon.get("quantity").toLong() + 1);
phone_addons.put(phone_product_details.Plan_Code,existing_addon.toString());
}
else
{
phone_addon_map = Map();
phone_addon_map.put("addon_code",phone_product_details.Plan_Code);
phone_addon_map.put("addon_description","Charges for billing period (from %BillingStartDate% to %BillingEndDate%)");
phone_addon_map.put("price",phone_product_details.Monthly_Plan_Fee);
phone_addon_map.put("quantity","1");
phone_addons.put(phone_product_details.Plan_Code,phone_addon_map.toString());
}
}
for each phone_addon_key in phone_addons.keys()
{
addons.add(phone_addons.get(phone_addon_key).toMap());
}
addon_json = addons.toJSONList();
plan_map = Map();
plan_map.put("plan_code","unified_net");
plan_map.put("plan_description","Unified Net subscription");
plan_map.put("price","0");
plan_map.put("setup_fee",upfront_fee);
plan_map.put("quantity","1");
subsc_map = Map();
subsc_map.put("customer_id",customer_id);
subsc_map.put("auto_collect",false);
subsc_map.put("plan",plan_map);
subsc_map.put("addons",addon_json);
subsc_map.put("is_taxable",true);
subsc_map.put("reference_id",customer_reference_number);
subsc_map.put("tax_id","1005984000000448009");
subsc_map.put("starts_at", date_to_start.toString("yyyy-MM-dd"));
headers = {"Authorization":"Zoho-authtoken " + AUTH_TOKEN,"X-com-zoho-subscriptions-organizationid": ORGANISATION_ID};
result = postUrl("https://subscriptions.zoho.com/api/v1/subscriptions",subsc_map.toString(),headers,true);
response_message = result.getJSON("subscription");
if(response_message != null)
{
subscription_id = response_message.get("subscription_id");
openUrl("https://subscriptions.zoho.com/app#/subscriptions/" + subscription_id,"Same Window");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.