From 5ed1804b89e0cdeb3fff04355c7d4f5b3567fca5 Mon Sep 17 00:00:00 2001 From: stephen Date: Fri, 21 Oct 2022 21:51:45 +0300 Subject: [PATCH] Refactored Configs to Mpesa Class Refactored Configs to Mpesa Class --- src/Mpesa.php | 53 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Mpesa.php b/src/Mpesa.php index c570840..0bbfa7d 100644 --- a/src/Mpesa.php +++ b/src/Mpesa.php @@ -27,7 +27,7 @@ | *--------------------------------------------------------------------------------------- */ -class Mpesa extends Config +class Mpesa extends { public string $security_credential; @@ -39,14 +39,55 @@ class Mpesa extends Config private string $token; - public function __construct(array $config) - { - // $this->security_credential = $this->security_credential(); - parent::__construct($config); + //public string $SecurityCredential; + protected string $consumer_key; + protected string $consumer_secret; + protected string $shortcode; + protected string $store; + protected string $pass_key; + protected string $TransactionType; + protected string $sandbox_endpoint; + public bool $environment; + protected function __construct(array $config) { - } + if(isset($config['consumer_key'])) { + $this->consumer_key = $config['consumer_key']; + } else { + throw new Exception('Missing Parameter consumer_key"', 400); + } + if(isset($config['consumer_secret'])) { + $this->consumer_secret = $config['consumer_secret']; + } else { + throw new Exception('Missing parameter "consumer_secret"', 400); + } + + if(isset($config['pass_key'])) { + $this->pass_key = $config['pass_key']; + } else { + throw new InvalidRequestException('Missing parameter "pass_key"', 400); + } + + $this->shortcode = (isset($config['shortcode'])) ? $config['shortcode'] :null; + $this->store = (isset($config['store'])) ? $config['store'] :null; + $this->TransactionType = (isset($config['TransactionType'])) ? $config['TransactionType'] :null; + $this->initiator_name = (isset($config['initiator_name'])) ? $config['initiator_name'] :null; + $this->initiator_pass = (isset($config['initiator_pass'])) ? $config['initiator_pass'] :null; + +// $this->callback_url = (isset($config['callback_url'])) ? $config['callback_url'] :null; +// $this->confirmation_url = (isset($config['confirmation_url'])) ? $config['confirmation_url'] :null; +// $this->timeout_url = (isset($config['timeout_url'])) ? $config['timeout_url'] :null; +// $this->validation_url = (isset($config['validation_url'])) ? $config['validation_url'] :null; +// $this->result_url = (isset($config['result_url'])) ? $config['result_url'] :null; + + + $this->environment = (isset($config['environment'])) ? $config['$environment'] :true; + $this->live_endpoint = 'https://api.safaricom.co.ke/'; + $this->sandbox_endpoint = 'https://sandbox.safaricom.co.ke/'; + + + }