Skip to content

Commit

Permalink
Handle ConnectionException
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaVrachevaAmpeco committed Aug 16, 2024
1 parent 04964c2 commit b4250e4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ampeco/omnipay-ecpay",
"description": "Ecpay gateway for Omnipay payment processing",
"version": "1.1.1",
"version": "1.1.2",
"authors": [
{
"name": "Alexander Alexiev",
Expand Down
12 changes: 8 additions & 4 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ public function getData()

public function sendData($data)
{
$res = $this->getPaymentApi()->authorizeViaStoredCard(
$authRes = $this->getPaymentApi()->authorizeViaStoredCard(
$data['merchantTradeNo'], $data['cardReference'],$data['clientId'], $data['amount'], $data['description']
);
$authResponse = new Response($this, $res);
$authResponse = new Response($this, $authRes);
$this->response = $authResponse;
if ($authResponse->isSuccessful()){
$this->getPaymentApi()->updateTransaction(

if ($authResponse->isSuccessful()) {
$captureRes = $this->getPaymentApi()->updateTransaction(
PaymentApi::UPDATE_CAPTURE,
$authResponse->getTransactionReference(),
$data['merchantTradeNo'],
$data['amount']
);

return new Response($this, $captureRes);
}

return $authResponse;
}
}
12 changes: 9 additions & 3 deletions src/SDK/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Ampeco\OmnipayEcpay\SDK;

use GuzzleHttp\Exception\ConnectException;
use Psr\Http\Message\ResponseInterface;

class HttpClient extends \GuzzleHttp\Client
Expand All @@ -22,12 +23,17 @@ public function __construct(array $config = [])
/**
* @param \Psr\Http\Message\UriInterface|string $uri
* @param array $options
* @return \Psr\Http\Message\ResponseInterface|void
* @return \Psr\Http\Message\ResponseInterface|null|void
*/
public function post($uri, array $options = []): ResponseInterface
public function post($uri, array $options = [])
{
$body = http_build_query($options);
$options = ['body' => $body];
return parent::post($uri, $options);

try {
return parent::post($uri, $options);
} catch (ConnectException $exception) {
return null;
}
}
}
8 changes: 6 additions & 2 deletions src/SDK/LoadsHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ protected function setHttpClientOptions($options){
$this->httpClient = null;
}

protected function parseResponse(ResponseInterface $response){
return parse_query($response->getBody()->getContents());
/**
* @param ResponseInterface|null $response
* @return array
*/
protected function parseResponse($response) {
return $response ? parse_query($response->getBody()->getContents()) : [];
}
}
4 changes: 4 additions & 0 deletions src/SDK/SignsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ protected function signDataWithMd5($data, $exemptions = [], $normalize = [])

protected function validData($data, $method = 'signSHA256', $ignoreOnTest=false)
{
if (empty($data)) {
return [];
}

if ($ignoreOnTest && $this->testMode) {
return $data; // Signature is missing on testing for some responses
}
Expand Down

0 comments on commit b4250e4

Please sign in to comment.