Skip to content

Commit

Permalink
Bug fix:
Browse files Browse the repository at this point in the history
- Caught errors when generating live or sandbox tokens
  • Loading branch information
coolsam726 committed May 19, 2020
1 parent 1376412 commit 114e0e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Daraja.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Savannabits\Daraja;

use Symfony\Component\Dotenv\Dotenv;;
use Symfony\Component\Dotenv\Dotenv;

class Daraja
{
Expand Down Expand Up @@ -72,7 +72,10 @@ public function generateLiveToken(){
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
$this->access_token = json_decode($curl_response)->access_token;
$this->access_token = optional(json_decode($curl_response))->access_token;
if (!$this->access_token) {
abort(500, "Access token could not be generated.");
}
return $this;
}

Expand Down Expand Up @@ -102,7 +105,10 @@ public function generateSandBoxToken(){

$curl_response = curl_exec($curl);

$this->access_token = json_decode($curl_response)->access_token;
$this->access_token = optional(json_decode($curl_response))->access_token;
if (!$this->access_token) {
abort(500, "Access token could not be generated.");
}
return $this;
}

Expand Down

0 comments on commit 114e0e9

Please sign in to comment.