Skip to main content

Assign a billing ID

To assign a billing_id to Ticaga, you need to post their Ticaga ID and their Billing System ID:

URL: https://yourdomain.com/api/customers/assign

Type: POST

{
  "user": true
}

ticaga_id: Ticaga's customer ID.

billing_id: The billing system customer ID.

billing_system: The billing system name supported by Ticaga Enum.

If the customer doesn't exist, you get this error:

{
  "error": "User not authenticated"
}

We recommend you store this in the database for the billing system too.

Example from our Blesta plugin:

/**
     * Associates/Syncs Blesta Account with Ticaga Account
     *
     * @param int $id The id of the client to fetch
     * @return mixed An stdClass object representing the ticket, or false if none exist
     */
    public function connectAccounts($email_address, $ticaga_id)
    {
		$ipaddress = $this->get_client_ip_server();

		$client_id = $this->Session->read("blesta_client_id");

		if ($email_address != false)
        {
              $blesta_email = $this->Record->select('email')->from("contacts")->where('Client_id', '=', $client_id)->fetch();
              $ticaga_info = json_decode($this->getUserInfoById($ticaga_id), true);

              if($blesta_email->email == $email_address)
              {
                  if($ticaga_info["user"]['id'] == $ticaga_id && $ticaga_info["user"]['email'] == $blesta_email->email)
                  {
                        $company_id = Configure::get('Blesta.company_id');
                        $apiKey = $this->getAPIInfoByCompanyId($company_id)->api_key;
                        $apiURL = $this->getAPIInfoByCompanyId($company_id)->api_url;
                        $apiEmail = $this->getAPIInfoByCompanyId($company_id)->api_email;

		                $callvars = array('ticaga_id' => $ticaga_id, "billing_id" => $client_id, "billing_system" => "Blesta");
                        $this->TicagaSettings->callAPIPost("customers/assign", $callvars, $apiURL, $apiEmail, $apiKey);

                        $this->Record->duplicate("ticaga_userid", "=", $ticaga_id)->insert("ticaga_billing", array('ticaga_userid' => $ticaga_id,'billing_userid' => $client_id, 'email_address' => $email_address, 'billing_system' => 'Blesta'));
                      return true;
                  } else {
                      return false;
                  }
              } else {
                  return false;
              }
        } else {
            return false;
        }
    }