Commit 6a7423da by Camoo Sarl

Test mode option added

parent c0aee634
...@@ -3,9 +3,14 @@ require_once('src/autoload.php'); ...@@ -3,9 +3,14 @@ require_once('src/autoload.php');
$oAirtime = new \CAMOO\Airtime\Airtime('592595095gh57', '4e32da5979879b89479847b9798479494984'); $oAirtime = new \CAMOO\Airtime\Airtime('592595095gh57', '4e32da5979879b89479847b9798479494984');
// receiver recipient
$oAirtime->destination_msisdn='237671234567'; $oAirtime->destination_msisdn='237671234567';
$oAirtime->topup=1500; // airtime from
$oAirtime->msisdn='237340404'; $oAirtime->msisdn='237340404';
// airtime amount
$oAirtime->topup=100;
// just to test
$oAirtime->test_mode=true;
/* /*
$oAirtime->send_sms=true; $oAirtime->send_sms=true;
$oAirtime->sms='Developer own custom message'; $oAirtime->sms='Developer own custom message';
......
...@@ -30,7 +30,12 @@ class Airtime extends Client{ ...@@ -30,7 +30,12 @@ class Airtime extends Client{
} }
public function __set($property, $value) { public function __set($property, $value) {
try {
Payload::create()->set($property, $value); Payload::create()->set($property, $value);
} catch ( CamooException $err) {
echo $err->getMessage();
exit();
}
return $this; return $this;
} }
......
...@@ -9,7 +9,7 @@ namespace CAMOO\Airtime; ...@@ -9,7 +9,7 @@ namespace CAMOO\Airtime;
* File: src/CAMOO/Airtime/Payload.php * File: src/CAMOO/Airtime/Payload.php
* updated: Mai 2017 * updated: Mai 2017
* Created by: Epiphane Tchabom (e.tchabom@camoo.cm) * Created by: Epiphane Tchabom (e.tchabom@camoo.cm)
* Description: CAMOO Airtime API * Description: CAMOO Airtime API Payload
* *
* @link http://www.camoo.cm * @link http://www.camoo.cm
*/ */
...@@ -19,6 +19,7 @@ use Valitron\Validator; ...@@ -19,6 +19,7 @@ use Valitron\Validator;
use CAMOO\Exceptions\CamooException; use CAMOO\Exceptions\CamooException;
final class Payload{ final class Payload{
private $destination_msisdn = null; private $destination_msisdn = null;
private $msisdn = null; private $msisdn = null;
private $topup = null; private $topup = null;
...@@ -26,6 +27,17 @@ final class Payload{ ...@@ -26,6 +27,17 @@ final class Payload{
private $sms = null; private $sms = null;
private $sender_sms = false; private $sender_sms = false;
private $sender_text = null; private $sender_text = null;
private $test_mode = false;
protected static $_create = null;
public static function create()
{
if ( is_null(static::$_create) )
{
static::$_create = new self;
}
return static::$_create;
}
private function ValidatorDefault(Validator $oValidator) { private function ValidatorDefault(Validator $oValidator) {
$oValidator $oValidator
...@@ -37,12 +49,14 @@ final class Payload{ ...@@ -37,12 +49,14 @@ final class Payload{
$oValidator $oValidator
->rule('required', ['destination_msisdn', 'topup', 'msisdn']); ->rule('required', ['destination_msisdn', 'topup', 'msisdn']);
$oValidator $oValidator
->rule('optional', ['sms', 'sender_sms']); ->rule('optional', ['sms', 'sender_sms', 'test_mode']);
$oValidator $oValidator
->rule('boolean', 'send_sms'); ->rule('boolean', 'send_sms');
$oValidator $oValidator
->rule('boolean', 'sender_sms'); ->rule('boolean', 'sender_sms');
$oValidator
->rule('boolean', 'test_mode');
$this->notBlankRule($oValidator, 'topup'); $this->notBlankRule($oValidator, 'topup');
return $oValidator; return $oValidator;
} }
...@@ -56,21 +70,15 @@ final class Payload{ ...@@ -56,21 +70,15 @@ final class Payload{
return false; return false;
} }
return true; return true;
}, $sParam)->message("{field} failed..."); }, $sParam)->message("{field} can not be blank/empty...");
} }
protected static $_create = null;
public static function create()
{
if ( is_null(static::$_create) )
{
static::$_create = new self;
}
return static::$_create;
}
public function set($sProperty, $value) { public function set($sProperty, $value) {
if ( !property_exists($this, $sProperty) ) {
throw new CamooException([$sProperty => 'is not allowed!']);
}
$this->$sProperty = $value; $this->$sProperty = $value;
} }
......
...@@ -31,10 +31,18 @@ class Client { ...@@ -31,10 +31,18 @@ class Client {
} }
public function post($data=[]) { public function post($data=[]) {
return $this->oHttpClient->performRequest(static::REQUEST_POST, ['form_params' => $data]); try{
return $this->oHttpClient->performRequest(static::REQUEST_POST, ['form_params' => $data]);
} catch ( HttpClientException $err ) {
echo $err->getMessage();
}
} }
public function get($data=[]) { public function get($data=[]) {
return $this->oHttpClient->performRequest(static::REQUEST_GET, ['query' => $data]); try {
return $this->oHttpClient->performRequest(static::REQUEST_GET, ['query' => $data]);
} catch ( HttpClientException $err ) {
echo $err->getMessage();
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment