Skip to content

Commit

Permalink
fixed trait and data decoding in response
Browse files Browse the repository at this point in the history
  • Loading branch information
mpaannddreew committed Dec 9, 2019
1 parent d5e65c7 commit e8a85ca
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 42 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ $options = [
// 'environment' => '', //(optional) default is sandbox
// 'accountHolderIdType' => '', //(optional) default is msisdn
'subscriptionKey' => '', //Product Subscription key
'xReferenceId' => '', //Api user reference id
'apiKey' => '', // Api user key
'xReferenceId' => '', //Api user reference id (in UUID format)
'apiKey' => '', // Api user key (Supply this after generating it at 'Create API Key')
//'preApproval' => '', //(optional) default is false
//'accessToken' => '' //Required for transactions
];
Expand Down
16 changes: 8 additions & 8 deletions src/Products/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public function getToken() {
],
]);

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

Expand All @@ -151,9 +151,9 @@ public function getAccountBalance() {
]
]);

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

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

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

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

Expand All @@ -247,9 +247,9 @@ protected function getTransactionStatus($paymentRef) {
]
]);

return TransactionStatus::create(json_decode($response->getBody(), true));
return TransactionStatus::create(json_decode($response->getBody()->getContents(), true));
} catch (\Exception $exception) {
throw new \Exception("Unable to get transaction status");
throw new \Exception($exception->getMessage());
}
}
}
9 changes: 0 additions & 9 deletions src/Responses/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ class Balance extends Response
*/
protected $currency;

/**
* Balance constructor.
* @param $options
*/
public function __construct($options)
{
$this->setOptions($options);
}

/**
* @return string
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Responses/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
abstract class Response
{
use Configurations;

public function __construct($options)
{
$this->setOptions($options);
}
}
9 changes: 0 additions & 9 deletions src/Responses/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ class Token extends Response
*/
protected $expires_in;

/**
* Token constructor.
* @param $options
*/
public function __construct($options)
{
$this->setOptions($options);
}

/**
* Access token
*
Expand Down
9 changes: 0 additions & 9 deletions src/Responses/TransactionStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ class TransactionStatus extends Response
*/
protected $reason = [];

/**
* TransactionStatus constructor.
* @param $options
*/
public function __construct($options)
{
$this->setOptions($options);
}

/**
* @return string
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Traits/SandboxUserProvisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function createApiUser() {
]);
return json_encode(['statusCode' => $response->getStatusCode()]);
} catch (\Exception $exception) {
throw new \Exception("Unable to create an api user");
throw new \Exception($exception->getMessage());
}
}

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

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

0 comments on commit e8a85ca

Please sign in to comment.