Zoho | Create Zoho Subscription using the PHP and subscription API

Author - Webner
11.07.2016
|
0 Comments
||

We can create new Zoho Subscriptions via code by using PHP curl and with the help of Subscription APIs.

Below is the sample code which is required to create a subscription:

$headerArray = array("Content-Type: application/json;charset=UTF-8",
"X-com-zoho-subscriptions-organizationid: 00000000",
"Authorization: Zoho-authtoken --------Auth token"
);

Here we have an array which needs to be passed to the header parameter in the curl request.

We have to pass the organization Id in the above example in place of “0000000”. This is the Id of organization created in Zoho Subscription while creating the organization. In place of Auth token, enter the subscription auth token of Zoho.

Now we have another array which will have subscription data in the curl request.

Below is the sample. We have only used the necessary parameters which should be there and compulsory while creating the subscription. We can pass any number of parameters which are present in the API documentation.

$data = array("customer_id"=> $subscriptioncontactid,
"starts_at"=> $subscriptionstartdate,
"plan"=> array
(
  "plan_code"=> $plancode,
  "name"=> $name,
  "price"=> $price,
  "quantity"=> 1,
  "billing_cycles"=> -1,
  "trial_days"=> 15,
 ),);

Customer_id is the Id of the customer for which the subscription needs to be created. We will use the Zoho subscription id of the customer.

Starts_at is the start date of the subscription.

Further we have Plan array. Plan is created for products which are added in the subscription. A plan object contains the billing and pricing information of a plan.
This array contains the plan_code of the plan created for the product which is added in the subscription.

When data and header are ready, pass these arrays in curl request.

Example:

$url = "https://subscriptions.zoho.com/api/v1/subscriptions";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt($ch, CURLOPT_HTTPHEADER,$headerArray);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($ch);
$json = json_decode($resp, true);

$json returns the response with subscription details which is recently created.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Zoho customization, App development or any other software development assistance please contact us at zoho@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *