Skip to content

Commit e8a85ca

Browse files
committed
fixed trait and data decoding in response
1 parent d5e65c7 commit e8a85ca

File tree

7 files changed

+20
-42
lines changed

7 files changed

+20
-42
lines changed

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ $options = [
5757
// 'environment' => '', //(optional) default is sandbox
5858
// 'accountHolderIdType' => '', //(optional) default is msisdn
5959
'subscriptionKey' => '', //Product Subscription key
60-
'xReferenceId' => '', //Api user reference id
61-
'apiKey' => '', // Api user key
60+
'xReferenceId' => '', //Api user reference id (in UUID format)
61+
'apiKey' => '', // Api user key (Supply this after generating it at 'Create API Key')
6262
//'preApproval' => '', //(optional) default is false
6363
//'accessToken' => '' //Required for transactions
6464
];

src/Products/Product.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ public function getToken() {
127127
],
128128
]);
129129

130-
return Token::create(json_decode($response->getBody(), true));
130+
return Token::create(json_decode($response->getBody()->getContents(), true));
131131
} catch (\Exception $exception) {
132-
throw new \Exception("Unable to generate token");
132+
throw new \Exception($exception->getMessage());
133133
}
134134
}
135135

@@ -151,9 +151,9 @@ public function getAccountBalance() {
151151
]
152152
]);
153153

154-
return Balance::create(json_decode($response->getBody(), true));
154+
return Balance::create(json_decode($response->getBody()->getContents(), true));
155155
} catch (\Exception $exception) {
156-
throw new \Exception("Unable to get account balance");
156+
throw new \Exception($exception->getMessage());
157157
}
158158
}
159159

@@ -179,7 +179,7 @@ public function getAccountHolderInfo($accountHolderId) {
179179

180180
return ['statusCode' => $response->getStatusCode()];
181181
} catch (\Exception $exception) {
182-
throw new \Exception("Unable to get account holder information");
182+
throw new \Exception($exception->getMessage());
183183
}
184184
}
185185

@@ -224,7 +224,7 @@ protected function transact($externalId, $partyId, $amount, $currency, $payerMes
224224
]);
225225
return ["statusCode" => $response->getStatusCode(), 'financialTransactionId' => $financialTransactionId];
226226
} catch (\Exception $exception) {
227-
throw new \Exception("Unable to complete transaction");
227+
throw new \Exception($exception->getMessage());
228228
}
229229
}
230230

@@ -247,9 +247,9 @@ protected function getTransactionStatus($paymentRef) {
247247
]
248248
]);
249249

250-
return TransactionStatus::create(json_decode($response->getBody(), true));
250+
return TransactionStatus::create(json_decode($response->getBody()->getContents(), true));
251251
} catch (\Exception $exception) {
252-
throw new \Exception("Unable to get transaction status");
252+
throw new \Exception($exception->getMessage());
253253
}
254254
}
255255
}

src/Responses/Balance.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ class Balance extends Response
2121
*/
2222
protected $currency;
2323

24-
/**
25-
* Balance constructor.
26-
* @param $options
27-
*/
28-
public function __construct($options)
29-
{
30-
$this->setOptions($options);
31-
}
32-
3324
/**
3425
* @return string
3526
*/

src/Responses/Response.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414
abstract class Response
1515
{
1616
use Configurations;
17+
18+
public function __construct($options)
19+
{
20+
$this->setOptions($options);
21+
}
1722
}

src/Responses/Token.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ class Token extends Response
2626
*/
2727
protected $expires_in;
2828

29-
/**
30-
* Token constructor.
31-
* @param $options
32-
*/
33-
public function __construct($options)
34-
{
35-
$this->setOptions($options);
36-
}
37-
3829
/**
3930
* Access token
4031
*

src/Responses/TransactionStatus.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ class TransactionStatus extends Response
5656
*/
5757
protected $reason = [];
5858

59-
/**
60-
* TransactionStatus constructor.
61-
* @param $options
62-
*/
63-
public function __construct($options)
64-
{
65-
$this->setOptions($options);
66-
}
67-
6859
/**
6960
* @return string
7061
*/

src/Traits/SandboxUserProvisioning.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function createApiUser() {
3131
]);
3232
return json_encode(['statusCode' => $response->getStatusCode()]);
3333
} catch (\Exception $exception) {
34-
throw new \Exception("Unable to create an api user");
34+
throw new \Exception($exception->getMessage());
3535
}
3636
}
3737

@@ -44,9 +44,9 @@ public function createApiUser() {
4444
public function getApiUser() {
4545
try {
4646
$response = $this->newClient()->get(self::BASE_URL . self::API_USER_URI . "/" . $this->xReferenceId);
47-
return ApiUser::create(json_decode($response->getBody(), true));
47+
return ApiUser::create(json_decode($response->getBody()->getContents(), true));
4848
} catch (\Exception $exception) {
49-
throw new \Exception("Unable to validate api user");
49+
throw new \Exception($exception->getMessage());
5050
}
5151
}
5252

@@ -59,9 +59,9 @@ public function getApiUser() {
5959
public function createApiKey() {
6060
try {
6161
$response = $this->newClient()->post(self::BASE_URL . self::API_USER_URI . "/" . $this->xReferenceId . "/apikey");
62-
return ApiKey::create(json_decode($response->getBody(), true));
62+
return ApiKey::create(json_decode($response->getBody()->getContents(), true));
6363
} catch (\Exception $exception) {
64-
throw new \Exception("Unable to create api key");
64+
throw new \Exception($exception->getMessage());
6565
}
6666
}
6767
}

0 commit comments

Comments
 (0)