-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* card-info: method request & response * card-info: ecs config update * card-info: code coverage * card-info: replaced some response keys
- Loading branch information
Showing
18 changed files
with
306 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor | ||
composer.lock | ||
tests-api/.env | ||
var/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Omnipay\Przelewy24\Message; | ||
|
||
class CardInfoRequest extends AbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('transactionId'); | ||
|
||
return [ | ||
'transactionId' => $this->getTransactionId(), | ||
]; | ||
} | ||
|
||
public function sendData($data): CardInfoResponse | ||
{ | ||
$httpResponse = $this->sendRequest('GET', sprintf('/api/v1/card/info/%s', $data['transactionId']), []); | ||
|
||
$responseData = json_decode($httpResponse->getBody()->getContents(), true); | ||
|
||
return $this->response = new CardInfoResponse($this, $responseData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Omnipay\Przelewy24\Message; | ||
|
||
use Omnipay\Common\Message\RequestInterface; | ||
|
||
class CardInfoResponse extends AbstractResponse | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $info = []; | ||
|
||
public function __construct(RequestInterface $request, $data) | ||
{ | ||
parent::__construct($request, $data); | ||
if (isset($data['data'])) { | ||
$this->info = $this->formatInfo($data['data']); | ||
} | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getInfo(): array | ||
{ | ||
return $this->info; | ||
} | ||
|
||
/** | ||
* @param string[] $data | ||
* @return string[] | ||
*/ | ||
private function formatInfo(array $data): array | ||
{ | ||
$formatted = $data; | ||
|
||
// replace keys | ||
$formatted = $this->replaceInfoKeys($formatted, 'cardType', 'brand'); | ||
$formatted = $this->replaceInfoKeys($formatted, 'cardDate', 'expiry'); | ||
|
||
return $formatted; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Message; | ||
|
||
use Omnipay\Przelewy24\Message\CardInfoRequest; | ||
use Omnipay\Przelewy24\Message\CardInfoResponse; | ||
use Omnipay\Tests\TestCase; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CardInfoRequestTest extends TestCase | ||
{ | ||
/** | ||
* @var CardInfoRequest | ||
*/ | ||
private $request; | ||
|
||
public function setUp() | ||
{ | ||
$this->request = new CardInfoRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->initialize([ | ||
'transactionId' => 1234567890, | ||
]); | ||
} | ||
|
||
public function testGetData(): void | ||
{ | ||
$data = $this->request->getData(); | ||
|
||
$this->assertSame(1234567890, $data['transactionId']); | ||
} | ||
|
||
public function testSendInvalidDataFailure() | ||
{ | ||
$this->setMockHttpResponse('CardInfoInvalidDataFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertInstanceOf(CardInfoResponse::class, $response); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getCode()); | ||
$this->assertSame('Wrong input data', $response->getMessage()); | ||
} | ||
|
||
public function testSendAuthFailure() | ||
{ | ||
$this->setMockHttpResponse('CardInfoAuthFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertInstanceOf(CardInfoResponse::class, $response); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getCode()); | ||
$this->assertSame('Incorrect authentication', $response->getMessage()); | ||
} | ||
|
||
public function testSendNotFoundFailure() | ||
{ | ||
$this->setMockHttpResponse('CardInfoNotFoundFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertInstanceOf(CardInfoResponse::class, $response); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertSame(Response::HTTP_NOT_FOUND, $response->getCode()); | ||
$this->assertSame('Transaction not exists', $response->getMessage()); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('CardInfoSuccess.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertInstanceOf(CardInfoResponse::class, $response); | ||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertSame(Response::HTTP_OK, $response->getCode()); | ||
$this->assertSame('', $response->getMessage()); | ||
|
||
$this->assertSame('ref-id', $response->getInfo()['refId']); | ||
$this->assertSame(0, $response->getInfo()['bin']); | ||
$this->assertSame('xxxx-xxxx-xxxx-1234', $response->getInfo()['mask']); | ||
$this->assertSame('VISA', $response->getInfo()['brand']); | ||
$this->assertSame('202505', $response->getInfo()['expiry']); | ||
$this->assertSame('e0dfeab6-39c2-42cb-b96e-fb0d6d48d503', $response->getInfo()['hash']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
HTTP/1.1 422 Unprocessable Entity | ||
Server: nginx/1.4.4 | ||
Date: Sat, 17 May 2022 17:00:00 GMT | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 101 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
Strict-Transport-Security: max-age=31556926; includeSubDomains | ||
|
||
{ | ||
"error": "Incorrect authentication", | ||
"code": 401 | ||
} |
Oops, something went wrong.