Skip to content

Commit dd8c2ce

Browse files
committed
Added card type and card mask fields to parsed status response
1 parent d00b1e7 commit dd8c2ce

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ Main exception, that can be thrown by the library is the `GatewayException`. Fol
350350
- `DigestMissingException` - will be thrown if response missing Authorization header (corrupted response).
351351
- `DigestMismatchException` - will be thrown if response digest validation fail (corrupted response).
352352

353+
### Useful constants
354+
355+
`\TransactPro\Gateway\Responses\Constants\ErrorCode` - error codes
356+
`\TransactPro\Gateway\Responses\Constants\Status` - transaction statuses
357+
`\TransactPro\Gateway\Responses\Constants\CardFamily` - card families
358+
353359
## About
354360

355361
### Requirements
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types = 1);
2+
3+
/*
4+
* This file is part of the transact-pro/gw3-client package.
5+
*
6+
* (c) Transact Pro
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace TransactPro\Gateway\Responses\Constants;
13+
14+
class CardFamily
15+
{
16+
const VISA = 'VISA';
17+
const MASTER_CARD = 'MC';
18+
const MAESTRO = 'MA';
19+
const AMERICAN_EXPRESS = 'AMEX';
20+
}

src/Gateway/Responses/Parts/Info/TransactionStatus.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ class TransactionStatus
1717
{
1818
public $error;
1919
public $gatewayTransactionId;
20+
2021
public $statusCode;
2122
public $statusCodeGeneral;
2223
public $statusText;
2324
public $statusTextGeneral;
2425

26+
public $cardFamily;
27+
public $cardMask;
28+
2529
public function __construct(array $rawDecoded = null)
2630
{
2731
$this->error = !empty($rawDecoded['error']) ? new Error($rawDecoded['error']) : null;
2832
$this->gatewayTransactionId = strval($rawDecoded['gateway-transaction-id'] ?? null);
33+
2934
$this->statusCode = intval($rawDecoded['status'][0]['status-code'] ?? null);
3035
$this->statusCodeGeneral = intval($rawDecoded['status'][0]['status-code-general'] ?? null);
3136
$this->statusText = strval($rawDecoded['status'][0]['status-text'] ?? null);
3237
$this->statusTextGeneral = strval($rawDecoded['status'][0]['status-text-general'] ?? null);
38+
39+
$this->cardFamily = strval($rawDecoded['status'][0]['card-family'] ?? null);
40+
$this->cardMask = strval($rawDecoded['status'][0]['card-mask'] ?? null);
3341
}
3442
}

tests/Gateway/Operations/Info/StatusTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use TransactPro\Gateway\DataSets\DataSet;
1616
use TransactPro\Gateway\DataSets\Info;
1717
use TransactPro\Gateway\Http\Response;
18+
use TransactPro\Gateway\Responses\Constants\CardFamily;
1819
use TransactPro\Gateway\Responses\Constants\Status as StatusCode;
1920
use TransactPro\Gateway\Validator\Validator;
2021

@@ -42,9 +43,10 @@ public function testSuccess(): void
4243
public function testParseStatusResponse(): void
4344
{
4445
$body = "{\"transactions\":[{\"gateway-transaction-id\":\"cd7b8bdf-3c78-4540-95d0-68018d2aba97\",\"status\":" .
45-
"[{\"gateway-transaction-id\":\"cd7b8bdf-3c78-4540-95d0-68018d2aba97\",\"status-code\":7,\"status-code-general\":8," .
46-
"\"status-text\":\"SUCCESS\",\"status-text-general\":\"EXPIRED\"}]},{\"gateway-transaction-id\":\"37908991-789b-4d79-8c6a-f90ba0ce12b6\"," .
47-
"\"status\":[{\"gateway-transaction-id\":\"37908991-789b-4d79-8c6a-f90ba0ce12b6\",\"status-code\":8,\"status-code-general\":7," .
46+
"[{\"card-mask\":\"534219*5267\",\"card-family\":\"MC\",\"gateway-transaction-id\":\"cd7b8bdf-3c78-4540-95d0-68018d2aba97\"," .
47+
"\"status-code\":7,\"status-code-general\":8,\"status-text\":\"SUCCESS\",\"status-text-general\":\"EXPIRED\"}]}," .
48+
"{\"gateway-transaction-id\":\"37908991-789b-4d79-8c6a-f90ba0ce12b6\",\"status\":[" .
49+
"{\"gateway-transaction-id\":\"37908991-789b-4d79-8c6a-f90ba0ce12b6\",\"status-code\":8,\"status-code-general\":7," .
4850
"\"status-text\":\"EXPIRED\",\"status-text-general\":\"SUCCESS\"}]}," .
4951
"{\"error\":{\"code\":400,\"message\":\"Failed to fetch data for transaction with gateway id: 99900000-789b-4d79-8c6a-f90ba0ce12b0\"}," .
5052
"\"gateway-transaction-id\":\"99900000-789b-4d79-8c6a-f90ba0ce12b0\"}]}";
@@ -59,6 +61,8 @@ public function testParseStatusResponse(): void
5961
$this->assertEquals(StatusCode::EXPIRED, $tr1->statusCodeGeneral);
6062
$this->assertEquals("SUCCESS", $tr1->statusText);
6163
$this->assertEquals("EXPIRED", $tr1->statusTextGeneral);
64+
$this->assertEquals(CardFamily::MASTER_CARD, $tr1->cardFamily);
65+
$this->assertEquals("534219*5267", $tr1->cardMask);
6266

6367
$tr2 = $parsedResponse->transactions[1];
6468
$this->assertEquals("37908991-789b-4d79-8c6a-f90ba0ce12b6", $tr2->gatewayTransactionId);

0 commit comments

Comments
 (0)