Skip to content

Commit f70cad7

Browse files
refactor(paystack): Use guzzle 6 methods
1 parent c063dae commit f70cad7

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/Paystack.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,12 @@ private function setRequestOptions()
8888
{
8989
$authBearer = 'Bearer '. $this->secretKey;
9090

91-
$this->client = new Client(['base_uri' => $this->baseUrl]);
92-
93-
$this->client->setDefaultOption('headers', [
94-
'Authorization' => $authBearer,
95-
'Content-Type' => 'application/json',
96-
'Accept' => 'application/json'
97-
]);
91+
$this->client = new Client(['base_uri' => $this->baseUrl,
92+
'headers' => [
93+
'Authorization' => $authBearer,
94+
'Content-Type' => 'application/json',
95+
'Accept' => 'application/json'
96+
]]);
9897
}
9998

10099
/**
@@ -143,7 +142,7 @@ public function getAuthorizationUrl()
143142
{
144143
$this->makePaymentRequest();
145144

146-
$this->url = $this->response->json()["data"]["authorization_url"];
145+
$this->url = $this->getResponse()['data']['authorization_url'];
147146

148147
return $this;
149148
}
@@ -169,7 +168,7 @@ public function isTransactionVerificationValid()
169168
{
170169
$this->verifyTransactionAtGateway();
171170

172-
$result = $this->response->json()["message"];
171+
$result = $this->getResponse()['message'];
173172

174173
switch ($result)
175174
{
@@ -195,7 +194,7 @@ public function isTransactionVerificationValid()
195194
public function getPaymentData()
196195
{
197196
if ($this->isTransactionVerificationValid()) {
198-
return $this->response->json();
197+
return $this->getResponse();
199198
} else {
200199
throw new PaymentVerificationFailedException("Invalid Transaction Reference");
201200
}
@@ -216,7 +215,7 @@ public function redirectNow()
216215
*/
217216
public function getAccessCode()
218217
{
219-
return $this->response->json()["data"]["access_code"];
218+
return $this->getResponse()['data']['access_code'];
220219
}
221220

222221
/**
@@ -262,12 +261,21 @@ public function getAllTransactions()
262261
}
263262

264263
/**
265-
* Get the response from a get operation
264+
* Get the whole response from a get operation
265+
* @return array
266+
*/
267+
private function getResponse()
268+
{
269+
return json_decode($this->response->getBody(), true);
270+
}
271+
272+
/**
273+
* Get the data response from a get operation
266274
* @return array
267275
*/
268276
private function getData()
269277
{
270-
return $this->response->json()["data"];
278+
return $this->getResponse()['data'];
271279
}
272280

273281
}

0 commit comments

Comments
 (0)