From 43798f32fe35fd42e3f602a1e942410a01113133 Mon Sep 17 00:00:00 2001 From: stephencoduor Date: Tue, 4 Oct 2022 20:51:27 +0300 Subject: [PATCH] Refactored constructor by removing callback urls --- src/B2B.php | 7 ++++--- src/B2C.php | 4 ++-- src/C2B.php | 6 +++--- src/Config.php | 20 ++++++++++---------- src/STK.php | 4 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/B2B.php b/src/B2B.php index 3fe8804..62b228e 100644 --- a/src/B2B.php +++ b/src/B2B.php @@ -26,7 +26,8 @@ public function __construct(array $config) * @param string $remarks * @return array object */ - public function b2bSend($Amount, $commandId, $PartyB, $RecieverIdentifierType, $SenderIdentifierType, $AccountReference, $Remarks, $timeout_url, $result_url) + public function b2bSend($Amount, $commandId, $PartyB, $RecieverIdentifierType, $SenderIdentifierType, $AccountReference, $Remarks, $timeout_url, + $result_url) { $url = $this->env('/mpesa/b2b/v1/paymentrequest'); @@ -42,8 +43,8 @@ public function b2bSend($Amount, $commandId, $PartyB, $RecieverIdentifierType, $ 'PartyB' => $PartyB, 'AccountReference' => $AccountReference, 'Remarks' => $Remarks, - 'QueueTimeOutURL' => $this->timeout_url . $timeout_url, - 'ResultURL' => $this->result_url . $result_url + 'QueueTimeOutURL' => $timeout_url, + 'ResultURL' => $result_url ); $this->query($url, $curl_post_data); diff --git a/src/B2C.php b/src/B2C.php index af77dd7..f1340a9 100644 --- a/src/B2C.php +++ b/src/B2C.php @@ -38,8 +38,8 @@ public function b2cSend($amount, $commandId, $receiver, $remark, $occassion = nu 'PartyA' => $this->shortcode1, 'PartyB' => $receiver, 'Remarks' => $remark, - 'QueueTimeOutURL' => $this->timeout_url . $timeout_url, - 'ResultURL' => $this->result_url . $result_url, + 'QueueTimeOutURL' => $timeout_url, + 'ResultURL' => $result_url, 'Occasion' => $occassion ); diff --git a/src/C2B.php b/src/C2B.php index 06ce064..ebafd9d 100644 --- a/src/C2B.php +++ b/src/C2B.php @@ -22,7 +22,7 @@ public function __construct(array $config) * * @return json */ - public function register_url() + public function register_url($confirmation_url,$validation_url) { $url = $this->env('mpesa/c2b/v1/registerurl'); @@ -30,8 +30,8 @@ public function register_url() $curl_post_data = array( 'ShortCode' => $this->shortcode1, 'ResponseType' => 'Completed', - 'ConfirmationURL' => $this->confirmation_url, - 'ValidationURL' => $this->validation_url + 'ConfirmationURL' => $confirmation_url, + 'ValidationURL' => $validation_url ); $this->query($url, $curl_post_data); diff --git a/src/Config.php b/src/Config.php index 87a3c3c..c364da8 100644 --- a/src/Config.php +++ b/src/Config.php @@ -16,11 +16,11 @@ class Config protected string $initiator_name; protected string $initiator_pass; protected string $security_credential; - protected string $confirmation_url; - protected string $timeout_url; - protected string $validation_url; - protected string $callback_url; - protected string $result_url; +// protected string $confirmation_url; +// protected string $timeout_url; +// protected string $validation_url; +// protected string $callback_url; +// protected string $result_url; protected string $live_endpoint; protected string $sandbox_endpoint; @@ -50,11 +50,11 @@ protected function __construct(array $config) { $this->initiator_name = (isset($config['initiator_name'])) ? $config['initiator_name'] :null; $this->initiator_pass = (isset($config['initiator_pass'])) ? $config['initiator_pass'] :null; $this->store = (isset($config['store'])) ? $config['store'] :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->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->env = (isset($config['env'])) ? $config['env'] :true; $this->live_endpoint = 'https://api.safaricom.co.ke/'; diff --git a/src/STK.php b/src/STK.php index 7a29fb2..cf71869 100644 --- a/src/STK.php +++ b/src/STK.php @@ -23,7 +23,7 @@ public function __construct(array $config) * @return array object */ - public function stkPush($Amount, $PartyA, $AccountReference, $TransactionDesc) + public function stkPush($Amount, $PartyA, $AccountReference, $TransactionDesc,$callback_url) { $url = $this->env('mpesa/stkpush/v1/processrequest'); @@ -37,7 +37,7 @@ public function stkPush($Amount, $PartyA, $AccountReference, $TransactionDesc) 'PartyA' => $PartyA, 'PartyB' => $this->shortcode, 'PhoneNumber' => $PartyA, - 'CallBackURL' => $this->callback_url, + 'CallBackURL' => $callback_url, 'AccountReference' => $AccountReference, 'TransactionDesc' => $TransactionDesc );