From 7f3c62d7834066eeea2420668d2e3931126e3144 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 21 Jan 2020 13:53:34 +0000 Subject: [PATCH 01/11] removed minimum-stabily from composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a28f013..3b1238b 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,5 @@ "psr-4": { "Redde\\Tests\\": "tests/" } - }, - "minimum-stability": "stable" + } } From d61e1a3df04715e09d64e2b17f922a10ef96048f Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 4 Feb 2020 12:48:43 +0000 Subject: [PATCH 02/11] added minimum-stability: stable back to composer.json --- composer.json | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) mode change 100644 => 100755 composer.json diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 3b1238b..ac4d83d --- a/composer.json +++ b/composer.json @@ -2,16 +2,14 @@ "name": "redde/php-api-sdk", "description": "Redde API wrapper", "type": "library", - "keywords": ["online payment","payment integration","wigal","wigal solutions", "mobile money"], + "keywords": ["online payment", "payment integration", "wigal", "wigal solutions", "mobile money"], "homepage": "https://www.reddeonline.com/", "license": "MIT", - "authors": [ - { - "name": "Oteng Kwame Appiah-Nti", - "email": "koteng@wigalsolutions.com", - "role": "Software Engineer" - } - ], + "authors": [{ + "name": "Oteng Kwame Appiah-Nti", + "email": "koteng@wigalsolutions.com", + "role": "Software Engineer" + }], "require": { "php": ">=5.5.0", "ext-curl": "*", @@ -29,5 +27,6 @@ "psr-4": { "Redde\\Tests\\": "tests/" } - } -} + }, + "minimum-stability": "stable" +} \ No newline at end of file From 8208fc368f5bec399c55460d96745a4ffbccd820 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 4 Feb 2020 12:52:38 +0000 Subject: [PATCH 03/11] removed some required extensions from composer.json --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ac4d83d..a87a420 100755 --- a/composer.json +++ b/composer.json @@ -11,9 +11,7 @@ "role": "Software Engineer" }], "require": { - "php": ">=5.5.0", - "ext-curl": "*", - "ext-json": "*" + "php": ">=5.5.0" }, "require-dev": { "phpunit/phpunit": "^5.7" From 7d9476f3ef26c71cbd307f59ac72267ad3093490 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 6 Jul 2021 16:58:31 +0000 Subject: [PATCH 04/11] :sparkles: add checkout and checkoutStatus functions --- src/ReddeApi.php | 131 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 122 insertions(+), 9 deletions(-) diff --git a/src/ReddeApi.php b/src/ReddeApi.php index 58813c0..6d087f6 100644 --- a/src/ReddeApi.php +++ b/src/ReddeApi.php @@ -16,7 +16,7 @@ class ReddeApi */ private $apikey = ''; - private $app_id = ''; + private $appid = ''; private $lastResponseRaw; @@ -24,7 +24,7 @@ class ReddeApi public $url = 'https://api.reddeonline.com/v1/'; - const USER_AGENT = 'Redde PHP API SDK 1.0'; + const USER_AGENT = 'Redde PHP API SDK 1.2'; /** * Maximum amount of time in seconds that is allowed to make the connection to the API server @@ -39,13 +39,15 @@ class ReddeApi public $curlTimeout = 20; /** - * @param string $apikey Redde Store API key - * @throws \Redde\Exceptions\ReddeException if the library failed to initialize + * ReddeApi construct + * + * @param string $apikey Redde API key + * @param string $appid Redd App ID */ - public function __construct($apikey, $app_id) + public function __construct($apikey, $appid) { $this->apikey = $apikey; - $this->app_id = $app_id; + $this->appid = $appid; } /** @@ -55,7 +57,7 @@ public function __construct($apikey, $app_id) */ protected function getBaseUrl() { - return $this->setBaseUrl(); + return $this->setBaseUrl($this->url); } /** @@ -141,7 +143,7 @@ private function request($method, $path, array $params = [], $data = null) curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'apikey: ' . $this->apikey, - 'appid: ' . $this->app_id, + 'appid: ' . $this->appid, ]); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); @@ -193,7 +195,6 @@ private function request($method, $path, array $params = [], $data = null) */ public function receiveMoney($params) { - //$this->api = new ReddeApi($this->apikey, $this->app_id); try { // Receive payment from Customer $transaction = $this->post('receive', $params); @@ -231,5 +232,117 @@ public function sendMoney($params) echo $this->getLastResponseRaw(); } } + + /** + * Perform a status request to the API + * To check the status of a transaction api initiated through sendMoney or receiveMoney + * @param $transaction_id int|string + * @return mixed API response + * @throws \Redde\Exceptions\ReddeApiException If the API call status code is not in the 2xx range + * @throws ReddeException If the API call has failed or the response is invalid + */ + public function transactionStatus($transaction_id) + { + + $status_id = $transaction_id; //use the exact transaction_id here + + try { + // Checkout Status from Customer + $status = $this->get('status/' . $status_id); + echo $status; + } catch (ReddeApiException $e) { + // API response status code was not successful + echo 'Redde API Exception: ' . $e->getCode() . ' ' . $e->getMessage(); + } catch (ReddeException $e) { + // API call failed + echo 'Redde Exception: ' . $e->getMessage(); + echo $this->getLastResponseRaw(); + } + } + + /** + * Perform a checkout request to the API + * To receive money from customer through Checkout + * @param array $checkout_params + * @return mixed API response + * + * If the API call status code is not in the 2xx range + * and API call fails it will return to failure callback url + */ + public function checkOut($checkout_params) { + + $checkouturl = ''; + + try { + + // Checkout from Customer + $transaction = $this->post('checkout', $checkout_params); + $transaction = json_decode($transaction); + $checkouturl = $transaction->checkouturl; + + if ( + defined('LARAVEL_START') + && function_exists('redirect') + ) { + + return @redirect()->to($checkouturl); + } + + header("Location: " . $checkouturl); + + } catch (ReddeApiException $e) { + + // API response status code was not successful + if ( + defined('LARAVEL_START') + && function_exists('redirect') + ) { + return @redirect()->to($checkout_params['failurecallback']); + } else { + // die(var_dump($e)); + // echo 'Redde API Exception: ' . $e->getCode() . ' ' . $e->getMessage(); + header("Location: " . $checkout_params['failurecallback']); + } + } catch (ReddeException $e) { + + // API call failed + if ( + defined('LARAVEL_START') + && function_exists('redirect') + ) { + // die(var_dump($e)); + return @redirect()->to($checkout_params['failurecallback']); + } else { + header("Location: " . $checkout_params['failurecallback']); + } + } + } + + /** + * Perform a checkout status request to the API + * To check the status of a checkout api initiated through Checkout + * @param $transaction_id int|string + * @return mixed API response + * @throws \Redde\Exceptions\ReddeApiException If the API call status code is not in the 2xx range + * @throws ReddeException If the API call has failed or the response is invalid + */ + public function checkoutStatus($transaction_id) + { + + $checkout_status_id = $transaction_id; //use the exact transaction_id here + + try { + // Checkout Status from Customer + $status = $this->get('checkoutstatus/' . $checkout_status_id); + echo $status; + } catch (ReddeApiException $e) { + //API response status code was not successful + echo 'Redde API Exception: ' . $e->getCode() . ' ' . $e->getMessage(); + } catch (ReddeException $e) { + //API call failed + echo 'Redde Exception: ' . $e->getMessage(); + echo $this->getLastResponseRaw(); + } + } } \ No newline at end of file From da8ead8a6a5df90d290385dc437a107c604d1122 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 6 Jul 2021 16:58:57 +0000 Subject: [PATCH 05/11] :sparkles: add tests folder --- tests/gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/gitkeep diff --git a/tests/gitkeep b/tests/gitkeep new file mode 100644 index 0000000..e69de29 From 1a7a581c34709359522170c455ac3a142b036801 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 6 Jul 2021 16:59:28 +0000 Subject: [PATCH 06/11] :hammer: improve WebHookStatus --- src/Webhooks/WebHookStatus.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Webhooks/WebHookStatus.php b/src/Webhooks/WebHookStatus.php index a4361f1..d943ea9 100644 --- a/src/Webhooks/WebHookStatus.php +++ b/src/Webhooks/WebHookStatus.php @@ -1,8 +1,6 @@ setResponse($data); + $this->setResponse($data); return $this->getResponse(); } /** * The callback function prepares and retrieve - * final status of api call - * @return json + * response as object of final api call + * @return object */ public function callback() { - return json_decode($this->getRawResponse()); + $this->getRawResponse(); + return json_decode($this->response); } - + } From b6a67868e9ff021ec0fac281b6e9c77d2b683966 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 6 Jul 2021 16:59:54 +0000 Subject: [PATCH 07/11] :hammer: improve examples implementations --- examples/callback.php | 21 +++++++++++++--- examples/callback.txt | 0 examples/checkout.php | 48 ++++++++++++++++++++++++++++++++++++ examples/checkout_status.php | 32 ++++++++++++++++++++++++ examples/gitkeep | 0 5 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 examples/callback.txt create mode 100644 examples/checkout.php create mode 100644 examples/checkout_status.php create mode 100644 examples/gitkeep diff --git a/examples/callback.php b/examples/callback.php index c3a524a..9a17bb6 100755 --- a/examples/callback.php +++ b/examples/callback.php @@ -3,13 +3,26 @@ * A simple implementation of callback * on Redde Api */ -require_once '../vendor/autoload.php'; use Redde\Exceptions\ReddeApiException; use Redde\Exceptions\ReddeException; use Redde\Webhooks\WebHookStatus; -$status = new WebHookStatus(); //instantiate an object +require_once '../vendor/autoload.php'; + +$status = new WebHookStatus(); // instantiate an object + +$data = $status->callback(); // get callback and set it to a variable + +echo $data->reason; // output any data e.g. status|reason| etc + +/** + * Another implementation can be seen below + * This is to show how to log in a text file + */ + +// $data = $status->getRawResponse(); // get raw response and use it how you want -$data = $status->callback(); //get callback and set it to a variable +// if($data != null) { +// file_put_contents('callback.txt', "Log: ".date('d-m-Y')." => " . $params, FILE_APPEND | LOCK_EX); +// } -echo $data->reason; //output any data e.g. status|reason| etc diff --git a/examples/callback.txt b/examples/callback.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/checkout.php b/examples/checkout.php new file mode 100644 index 0000000..e0bcf66 --- /dev/null +++ b/examples/checkout.php @@ -0,0 +1,48 @@ + 1, // amount to receive + "apikey" => $apikey, // your api key + "appid" => $appid, // your app id + "description" => "A description for your transaction", // A description for the transaction + "merchantname" => "Some Company Limited", // Merchantname (Your Company or A name of your application) + "logolink" => "https://example.com/some-path-to-image-logo.jpg", // Url to fetch for your logo + "clienttransid" => $clientreference, // client reference from your end + "successcallback" => "https://example.com/", // A success callback url from your end + "failurecallback" => "https://example.com/failure", // A failure callback url from your end +]; + +/** +* Call checkOut function and pass +* the payload as parameter. This will +* take you to the Redde Checkout page +* when successful or throw an error +* when something goes wrong +* +* On success the success callbackurl will be called +* On failure the failure callbackurl will be called +*/ +$api->checkOut($params); diff --git a/examples/checkout_status.php b/examples/checkout_status.php new file mode 100644 index 0000000..33a3e7b --- /dev/null +++ b/examples/checkout_status.php @@ -0,0 +1,32 @@ + $apikey, + "appid" => $appid, +]; + +// To check status of checkout call this function +$api->checkoutStatus($transaction_id, $status_params); \ No newline at end of file diff --git a/examples/gitkeep b/examples/gitkeep new file mode 100644 index 0000000..e69de29 From f5afdeab1b3cc813ca9573f880fa13014cc69717 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Tue, 6 Jul 2021 17:00:10 +0000 Subject: [PATCH 08/11] :hammer: modify ReddeApiException --- src/Exceptions/ReddeApiException.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Exceptions/ReddeApiException.php b/src/Exceptions/ReddeApiException.php index 42d74df..4521666 100644 --- a/src/Exceptions/ReddeApiException.php +++ b/src/Exceptions/ReddeApiException.php @@ -1,5 +1,6 @@ Date: Tue, 6 Jul 2021 17:00:26 +0000 Subject: [PATCH 09/11] :hammer: modify composer.json --- composer.json | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) mode change 100755 => 100644 composer.json diff --git a/composer.json b/composer.json old mode 100755 new mode 100644 index a87a420..c54147b --- a/composer.json +++ b/composer.json @@ -2,16 +2,20 @@ "name": "redde/php-api-sdk", "description": "Redde API wrapper", "type": "library", - "keywords": ["online payment", "payment integration", "wigal", "wigal solutions", "mobile money"], + "keywords": ["online payment","payment integration","wigal","wigal solutions", "mobile money", "card payments"], "homepage": "https://www.reddeonline.com/", "license": "MIT", - "authors": [{ - "name": "Oteng Kwame Appiah-Nti", - "email": "koteng@wigalsolutions.com", - "role": "Software Engineer" - }], + "authors": [ + { + "name": "Oteng Kwame Appiah-Nti", + "email": "koteng@wigal.com.gh", + "role": "Software Engineer" + } + ], "require": { - "php": ">=5.5.0" + "php": ">=5.5.0", + "ext-curl": "*", + "ext-json": "*" }, "require-dev": { "phpunit/phpunit": "^5.7" @@ -27,4 +31,4 @@ } }, "minimum-stability": "stable" -} \ No newline at end of file +} From 29fae7a786d40db6dbee8ea4430c2b523438115d Mon Sep 17 00:00:00 2001 From: otengkwame Date: Fri, 18 Nov 2022 03:09:21 +0000 Subject: [PATCH 10/11] :hammer: add otpcode from checkout example Signed-off-by: otengkwame --- examples/otpcode-example.php | 19 +++++++++++++++++ examples/otpcode.php | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 examples/otpcode-example.php create mode 100644 examples/otpcode.php diff --git a/examples/otpcode-example.php b/examples/otpcode-example.php new file mode 100644 index 0000000..d5c9a3e --- /dev/null +++ b/examples/otpcode-example.php @@ -0,0 +1,19 @@ + 'OK', + 'reason' => 'To Receive Payment Prompt Dial *800*0*3072#', + 'transactionid' => 2553918, + 'clienttransid' => 345655, + 'clientreference' => 754876, + 'statusdate' => '2022-03-02 11:59:17.779', + 'brandtransid' => null +]); + +$reason = getReason($response); + +$output = getOtpUssd($reason); + +echo $otpCode = $output->notice .' '.$output->otp_code; diff --git a/examples/otpcode.php b/examples/otpcode.php new file mode 100644 index 0000000..28bac0a --- /dev/null +++ b/examples/otpcode.php @@ -0,0 +1,41 @@ +reason; +} + +function getOtpUssd($string) +{ + $strpos = strpos($string, '*'); + $first_star = substr($string, 0, $strpos); + $otp_code = substr($string, ($strpos)); + + return (object) [ + 'notice' => $first_star, + 'otp_code' => $otp_code + ]; +} + +// Put this code where you want to display otpcode to user $reason variable +$reason = getReason($response); +$output = getOtpUssd($reason); From 1cc8ad7e521fa952a9683d64dbc7ec117b3ed567 Mon Sep 17 00:00:00 2001 From: otengkwame Date: Fri, 18 Nov 2022 03:09:57 +0000 Subject: [PATCH 11/11] :zap: support from PHP 7.4 and above Signed-off-by: otengkwame --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c54147b..ed72b8e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "redde/php-api-sdk", "description": "Redde API wrapper", "type": "library", - "keywords": ["online payment","payment integration","wigal","wigal solutions", "mobile money", "card payments"], + "keywords": ["redde","redde payments","online payment","payment integration","wigal","wigal solutions", "wigal vision", "mobile money", "card payments"], "homepage": "https://www.reddeonline.com/", "license": "MIT", "authors": [ @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=5.5.0", + "php": "^7.4", "ext-curl": "*", "ext-json": "*" },