I accepted the challenge call billing.
The objective is to create a console application to charge incoming calls, and list all charges per account.
To create the application I used:
- PHP
- Mysql
- PhpUnit
- Composer
- External packages:
###Prerequisites
To setup the project it is necessary to have installed on your machine:
- PHP
- Composer
- MySql
- PhpUnit
First of all we need to get the necessary external packages with the help of composer
$ composer installNext we need to create the database to be the application storage
$ mysql -u<user> [-p<password>]
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 308
Server version: 10.1.9-MariaDB Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database talkdesk;
Query OK, 1 row affected (0,00 sec)
After creating database we need to restore database structure usefull for the project
$ mysql -u root talkdesk < assets/DB/initial-mysql.sqlIn order to billing is possible we should have at least one account with credit, for that we can insert in db account like this:
insert into account (name, credit) values ('Luis', 300);There is a file named config.ini that has the settings to:
- access database
- host
- user
- database name
- password
- the files paths used to get the cost values
- toll free/not free
- twillio numbers costs
- margin
Command is named call_billing, when invoked without arguments it will show the available commands and is invoked like so:
php call_billing.phpFor help with a particular command you can write
php call_billing.php help <command>The implemented commands are:
- chargeCall - Charges a call and remove credits from a given account
- listInboundCalls - Lists the charges for the given account
- lasts for 100 seconds,
- for Luis account,
- with talkdesknumber 12345545678,
- from client number 22422444446
- the call was taken to a forwarded phone with number 180022344
php call_billing.php chargeCall 100 "Luis" 12345545678 22422444446 180022344php call_billing.php listCalls "KLuis"- File tdMargin.csv:
- Has the rules for margin calculation
- Define the ranges of minutes used and the the correspondant margin
- These values are used with the current month minutes used by the particular account
- If user has a lot of minutes used then our margin decreases...
- File tollFreeNumbers.csv:
- Has the begin of US and UK Toll free numbers, as it's cost
- Fallback is 1cent
- File Twilio - Voice Prices.csv
- Has the prices per location
- This is only considered if call is forwarded to a regular phone
To run int tests that assert that the cost asserts are ok, simply do this:
$ cd tests
$ phpunit