Skip to content

Commit

Permalink
Refactor to handle nullable return type in HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaVrachevaAmpeco committed Oct 25, 2024
1 parent 644801a commit 8e0a918
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 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.4",
"version": "1.1.5",
"authors": [
{
"name": "Alexander Alexiev",
Expand Down
14 changes: 5 additions & 9 deletions src/SDK/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\ServerException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

class HttpClient extends \GuzzleHttp\Client
{
Expand All @@ -21,17 +22,12 @@ public function __construct(array $config = [])
parent::__construct(array_merge($config, $options));
}

/**
* @param \Psr\Http\Message\UriInterface|string $uri
* @param array $options
* @return \Psr\Http\Message\ResponseInterface|null|void
*/
public function post($uri, array $options = []): ResponseInterface
public function handlePostRequest(UriInterface|string $uri, array $options = []): ?ResponseInterface
{
$body = http_build_query($options);
$options = ['body' => $body];

try {
$body = http_build_query($options);
$options = ['body' => $body];

return parent::post($uri, $options);
} catch (ConnectException|ServerException $exception) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/SDK/InvoiceApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function invoiceIssue($relateNumber, $amount)
$post = $this->signDataWithMd5($post, ['ItemName', 'ItemWord', 'ItemRemark'], ['CustomerName', 'CustomerAddr', 'CustomerEmail']);
return $this->validDataWithMd5(
$this->parseResponse(
$this->getHttpClient()->post('Invoice/Issue', $post)
$this->getHttpClient()->handlePostRequest('Invoice/Issue', $post)
)
);
}
Expand All @@ -160,7 +160,7 @@ public function checkMobileBarCode($barCode)
$post = $this->signDataWithMd5($post);
return $this->validDataWithMd5(
$this->parseResponse(
$this->getHttpClient()->post('Query/CheckMobileBarCode', $post)
$this->getHttpClient()->handlePostRequest('Query/CheckMobileBarCode', $post)
)
);
}
Expand All @@ -176,7 +176,7 @@ public function checkLoveCode($loveCode)
$post = $this->signDataWithMd5($post);
return $this->validDataWithMd5(
$this->parseResponse(
$this->getHttpClient()->post('Query/CheckLoveCode', $post)
$this->getHttpClient()->handlePostRequest('Query/CheckLoveCode', $post)
)
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/SDK/PaymentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function authorizeViaStoredCard($merchantTradeNo, $cardId, $clientId, $am
$post = $this->signDataWithSha256($post);
return $this->validDataWithSha265(
$this->parseResponse(
$this->getHttpClient()->post('MerchantMember/AuthCardID/V2', $post)
$this->getHttpClient()->handlePostRequest('MerchantMember/AuthCardID/V2', $post)
)
);
}
Expand Down Expand Up @@ -72,7 +72,9 @@ public function queryMemberBinding($clientId){
'MerchantMemberID' => $this->merchant_id.$clientId,
];
$post = $this->signDataWithSha256($post);
return $this->validDataWithSha265($this->parseResponse($this->getHttpClient()->post('MerchantMember/QueryMemberBinding', $post)));
return $this->validDataWithSha265(
$this->parseResponse($this->getHttpClient()->handlePostRequest('MerchantMember/QueryMemberBinding', $post))
);
}

public function deleteCard($cardId, $clientId){
Expand All @@ -82,7 +84,9 @@ public function deleteCard($cardId, $clientId){
'CardID' => $cardId,
];
$post = $this->signDataWithSha256($post);
return $this->validDataWithSha265($this->parseResponse($this->getHttpClient()->post('MerchantMember/DeleteCardID', $post)));
return $this->validDataWithSha265(
$this->parseResponse($this->getHttpClient()->handlePostRequest('MerchantMember/DeleteCardID', $post))
);
}

const UPDATE_CAPTURE = 'C';
Expand All @@ -99,7 +103,7 @@ public function updateTransaction($action, $tradeNo, $merchantTradeNo, $amount){
'TotalAmount' => $amount,
];
$post = $this->signDataWithSha256($post);
return $this->parseResponse($this->getHttpClient()->post('CreditDetail/DoAction', $post));
return $this->parseResponse($this->getHttpClient()->handlePostRequest('CreditDetail/DoAction', $post));
}

public function getNotificationsFromPost($post){
Expand Down

0 comments on commit 8e0a918

Please sign in to comment.