Hi,
I have the below code in zoho creator in order to create a new subscription in Zoho Subscriptions when a customer signs up.
Could you please assist in editing this code so that when a customer uses an email address that already exists in zoho subscriptions it will create the subscription under that customers account instead of creating a new customer?
MY CODE:
Get_student_name = Add_an_Athlete[ID == input.Athlete_Name];
Full_Name = Get_student_name.Athlete_Name.first_name.remove(" ") + " " + Get_student_name.Athlete_Name.last_name.remove(" ");
//get year
startDate = input.Start_Date_for_Subscription;
year = zoho.currentdate.year();
//create plan
values = Map();
values.put("plan_code",input.Plan_Code);
values.put("name",year + " " + Full_Name + " Training Fees");
values.put("recurring_price",input.Amount_per_Payment);
values.put("interval",input.interval);
values.put("interval_unit",input.interval_unit);
values.put("billing_cycles",input.Number_of_Payments);
values.put("setup_fee",input.Enrolment_Fee);
values.put("product_id","40973000000089009");
response = zoho.subscriptions.create("Plans","7001298624",values,"create_subscription_plan");
info response;
//create subscritption
organizationID = "7001298624";
plan = Map();
plan.put("plan_code",input.Plan_Code);
customer = Map();
customer.put("display_name",Full_Name);
customer.put("first_name",Get_student_name.Athlete_Name.first_name.remove(" "));
customer.put("last_name",Get_student_name.Athlete_Name.last_name.remove(" "));
customer.put("email",input.Email);
payload = Map();
payload.put("plan",plan);
payload.put("customer",customer);
payload.put("starts_at",input.Start_Date_for_Subscription.toString("yyyy-MM-dd"));
payload.put("reference_id",year + Get_student_name.Athlete_Name.first_name.remove(" ") + Get_student_name.Athlete_Name.last_name.remove(" ") + input.Plan_Code);
info payload;
response = invokeurl
[
url :https://subscriptions.zoho.com.au/api/v1/hostedpages/newsubscription?organization_id= + organizationID
type :POST
parameters:payload.toString()
connection:"create_subscriptions_subsrcription_hostedpage"
];
info response;
if(response.getJSON("hostedpage").size() > 0)
{
url = response.getJSON("hostedpage").getJSON("url");
info url;
openurl(url,"same window");
}