Skip to content

Commit

Permalink
New release: v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sz-altapay-com committed Jun 4, 2020
1 parent cd2c6f4 commit e17209f
Show file tree
Hide file tree
Showing 18 changed files with 904 additions and 211 deletions.
2 changes: 1 addition & 1 deletion docs/ecommerce/payment_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ try {
// Could not connect
} catch (\Valitor\Exceptions\ResponseHeaderException $e) {
// Response error in header
$e->getHeader()->ErrorMessage;
$e->getHeader()->ErrorMessage
} catch (\Valitor\Exceptions\ResponseMessageException $e) {
// Error message
$e->getMessage();
Expand Down
2 changes: 1 addition & 1 deletion docs/others/custom_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ try {
// Could not connect
} catch (\Valitor\Exceptions\ResponseHeaderException $e) {
// Response error in header
$e->getHeader()->ErrorMessage;
$e->getHeader()->ErrorMessage
} catch (\Valitor\Exceptions\ResponseMessageException $e) {
// Error message
$e->getMessage();
Expand Down
2 changes: 1 addition & 1 deletion docs/others/funding_download.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ try {
// Could not connect
} catch (\Valitor\Exceptions\ResponseHeaderException $e) {
// Response error in header
$e->getHeader()->ErrorMessage;
$e->getHeader()->ErrorMessage
} catch (\Valitor\Exceptions\ResponseMessageException $e) {
// Error message
$e->getMessage();
Expand Down
2 changes: 1 addition & 1 deletion docs/others/invoicetext.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ try {
// Could not connect
} catch (\Valitor\Exceptions\ResponseHeaderException $e) {
// Response error in header
$e->getHeader()->ErrorMessage;
$e->getHeader()->ErrorMessage
} catch (\Valitor\Exceptions\ResponseMessageException $e) {
// Error message
$e->getMessage();
Expand Down
2 changes: 1 addition & 1 deletion docs/others/payments.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ try {
// Could not connect
} catch (\Valitor\Exceptions\ResponseHeaderException $e) {
// Response error in header
$e->getHeader()->ErrorMessage;
$e->getHeader()->ErrorMessage
} catch (\Valitor\Exceptions\ResponseMessageException $e) {
// Error message
$e->getMessage();
Expand Down
2 changes: 1 addition & 1 deletion docs/others/terminals.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ try {
// Could not connect
} catch (\Valitor\Exceptions\ResponseHeaderException $e) {
// Response error in header
$e->getHeader()->ErrorMessage;
$e->getHeader()->ErrorMessage
} catch (\Valitor\Exceptions\ResponseMessageException $e) {
// Error message
$e->getMessage();
Expand Down
38 changes: 24 additions & 14 deletions src/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ abstract class AbstractApi
* Configure options
*
* @param OptionsResolver $resolver
*
* @return void
*/
abstract protected function configureOptions(OptionsResolver $resolver);

/**
* Handle response
*
* @param Request $request
* @param Request $request
* @param Response $response
*
* @return AbstractResponse
*/
abstract protected function handleResponse(Request $request, Response $response);
Expand All @@ -133,6 +135,7 @@ abstract protected function handleResponse(Request $request, Response $response)
* Url to api call
*
* @param array $options Resolved options
*
* @return string
*/
abstract protected function getUrl(array $options);
Expand All @@ -145,11 +148,10 @@ abstract protected function getUrl(array $options);
public function __construct(Authentication $authentication)
{
$this->unresolvedOptions = [];
$this->dispatcher = new EventDispatcher();
$this->httpClient = new Client();

$this->authentication = $authentication;
$this->baseUrl = $authentication->getBaseurl();
$this->dispatcher = new EventDispatcher();
$this->httpClient = new Client();
$this->authentication = $authentication;
$this->baseUrl = $authentication->getBaseurl();
}

/**
Expand All @@ -166,11 +168,13 @@ public function call()
* Set HTTP client
*
* @param ClientInterface $client
*
* @return $this
*/
public function setClient(ClientInterface $client)
{
$this->httpClient = $client;

return $this;
}

Expand Down Expand Up @@ -210,8 +214,9 @@ protected function getHttpMethod()
* Handle exception response
*
* @param Exceptions\ClientException $exception
* @throws Exceptions\ClientException
*
* @return bool|void
* @throws Exceptions\ClientException
*/
protected function handleExceptionResponse(Exceptions\ClientException $exception)
{
Expand All @@ -224,9 +229,7 @@ protected function handleExceptionResponse(Exceptions\ClientException $exception
protected function doConfigureOptions()
{
$resolver = new OptionsResolver();

$this->configureOptions($resolver);

$this->setTransactionResolver($resolver);
$this->setOrderLinesResolver($resolver);
$this->setAmountResolver($resolver);
Expand All @@ -235,14 +238,14 @@ protected function doConfigureOptions()
$this->setShopOrderIdResolver($resolver);
$this->setTransactionInfoResolver($resolver);
$this->setCustomerInfoResolver($resolver);

$this->options = $resolver->resolve($this->unresolvedOptions);
}

/**
* Validate response
*
* @param mixed $response
*
* @throws Exceptions\ResponseHeaderException
* @throws Exceptions\ResponseMessageException
*/
Expand All @@ -258,6 +261,12 @@ protected function validateResponse($response)
throw new Exceptions\ResponseMessageException($response->MerchantErrorMessage);
}
}

if (property_exists($response, 'CardHolderMessageMustBeShown')) {
if ($response->CardHolderMessageMustBeShown) {
throw new Exceptions\ResponseMessageException($response->CardHolderErrorMessage);
}
}
}
}

Expand All @@ -277,15 +286,15 @@ protected function doResponse()
$this->request = $request;

try {
$response = $this->getClient()->send($request);
$response = $this->getClient()->send($request);
$this->response = $response;

$output = $this->handleResponse($request, $response);
$output = $this->handleResponse($request, $response);
$this->validateResponse($output);

return $output;
} catch (GuzzleHttpClientException $e) {
$exception = new Exceptions\ClientException($e->getMessage(), $e->getRequest(), $e->getResponse());

return $this->handleExceptionResponse($exception);
}
}
Expand All @@ -309,11 +318,12 @@ protected function parseUrl()
* Build url
*
* @param array $options
*
* @return bool|string
*/
protected function buildUrl(array $options)
{
if (! $options) {
if (!$options) {
return false;
}

Expand Down
Loading

0 comments on commit e17209f

Please sign in to comment.