Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a413fce

Browse files
create payment response added
1 parent 44cd169 commit a413fce

File tree

6 files changed

+331
-0
lines changed

6 files changed

+331
-0
lines changed

src/Enum/ResponseCode.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Comgate\Enum;
4+
5+
class ResponseCode
6+
{
7+
const CODE_OK = 0;
8+
const CODE_UNKNOWN = 1100;
9+
const CODE_NOT_SUPPORTED_LANG = 1102;
10+
const CODE_INVALID_METHOD = 1103;
11+
const CODE_UNABLE_TO_LOAD_PAYMENT = 1104;
12+
const CODE_DB_ERROR = 1200;
13+
const CODE_UNKNOWN_SHOP = 1301;
14+
const CODE_MISSING_LANG = 1303;
15+
const CODE_INVALID_CATEGORY = 1304;
16+
const CODE_MISSING_PRODUCT_DESC = 1305;
17+
const CODE_CHOOSE_CORRECT_METHOD = 1306;
18+
const CODE_NOT_SUPPORTED_METHOD = 1308;
19+
const CODE_INVALID_PRICE = 1309;
20+
const CODE_UNKNOWN_CURRENCY = 1310;
21+
const CODE_INVALID_BANK_ACCOUNT_IDENTIFIER = 1311;
22+
const CODE_PAYMENT_REPEAT_NOT_SUPPORTED = 1316;
23+
const CODE_INVALID_METHOD_REPEAT_PAYMENT = 1317;
24+
const CODE_UNABLE_TO_CREATE_PAYMENT = 1319;
25+
const CODE_DB_RESULT_ERROR = 1399;
26+
const CODE_INVALID_REQUEST = 1400;
27+
const CODE_FATAL = 1500;
28+
29+
30+
static $codes = [
31+
0 => 'OK',
32+
1100 => 'neznámá chyba',
33+
1102 => 'zadaný jazyk není podporován',
34+
1103 => 'nesprávně zadaná metoda',
35+
1104 => 'nelze načíst platbu',
36+
1200 => 'databázová chyba',
37+
1301 => 'neznámý eshop',
38+
1303 => 'propojení nebo jazyk chybí',
39+
1304 => 'neplatná kategorie',
40+
1305 => 'chybí popis produktu',
41+
1306 => 'vyberte správnou metodu',
42+
1308 => 'vybraný způsob platby není povolen',
43+
1309 => 'nesprávná částka',
44+
1310 => 'neznámá měna',
45+
1311 => 'neplatný identifikátor bankovního účtu Klienta',
46+
1316 => 'eshop nemá povolené opakované platby',
47+
1317 => 'neplatná metoda – nepodporuje opakované platby',
48+
1319 => 'nelze založit platbu, problém na straně banky',
49+
1399 => 'neočekávaný výsledek z databáze',
50+
1400 => 'chybný dotaz',
51+
1500 => 'neočekávaná chyba',
52+
];
53+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Comgate\Exception;
4+
5+
class InvalidArgumentException extends \Exception
6+
{
7+
8+
}

src/Request/CreatePayment.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,21 @@ public function isPost()
575575
}
576576

577577

578+
/**
579+
* @return string
580+
*/
578581
public function getEndPoint()
579582
{
580583
return '/create';
581584
}
582585

586+
587+
/**
588+
* @return string
589+
*/
590+
public function getResponseClass()
591+
{
592+
return '/create';
593+
}
594+
583595
}

src/Request/RequestInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ public function isPost();
2121
* @return string
2222
*/
2323
public function getEndPoint();
24+
25+
26+
/**
27+
* @return string
28+
*/
29+
public function getResponseClass();
2430
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Comgate\Response;
4+
5+
use Comgate\Enum\ResponseCode;
6+
use Comgate\Exception\InvalidArgumentException;
7+
8+
class CreatePaymentResponse
9+
{
10+
/**
11+
* @var int
12+
*/
13+
private $code;
14+
15+
/**
16+
* @var string
17+
*/
18+
private $message;
19+
20+
/**
21+
* @var string
22+
*/
23+
private $transId;
24+
25+
/**
26+
* @var string
27+
*/
28+
private $redirect;
29+
30+
31+
/**
32+
* @param array $rawData
33+
* @throws InvalidArgumentException
34+
*/
35+
public function __construct(array $rawData)
36+
{
37+
if (isset($rawData['code'])) {
38+
$this->code = (int)$rawData['code'];
39+
} else {
40+
throw new InvalidArgumentException('Missing "code" in response');
41+
}
42+
43+
if (isset($rawData['message'])) {
44+
$this->message = $rawData['message'];
45+
} else {
46+
throw new InvalidArgumentException('Missing "message" in response');
47+
}
48+
49+
if (isset($rawData['transId'])) {
50+
$this->transId = $rawData['transId'];
51+
} else {
52+
throw new InvalidArgumentException('Missing "transId" in response');
53+
}
54+
55+
if (isset($rawData['redirect'])) {
56+
$this->redirect = $rawData['redirect'];
57+
} else {
58+
throw new InvalidArgumentException('Missing "redirect" in response');
59+
}
60+
}
61+
62+
63+
/**
64+
* @return bool
65+
*/
66+
public function isOk(): bool
67+
{
68+
return $this->code === ResponseCode::CODE_OK;
69+
}
70+
71+
72+
/**
73+
* @return string
74+
*/
75+
public function getMessage(): string
76+
{
77+
return $this->message;
78+
}
79+
80+
81+
/**
82+
* @return string
83+
*/
84+
public function getTransId(): string
85+
{
86+
return $this->transId;
87+
}
88+
89+
90+
/**
91+
* @return string
92+
*/
93+
public function getRedirectUrl(): string
94+
{
95+
return $this->redirect;
96+
}
97+
}

test/CreatePaymentResponseTest.php

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
3+
namespace ComgateTest;
4+
5+
use Comgate\Enum\ResponseCode;
6+
use Comgate\Exception\InvalidArgumentException;
7+
use Comgate\Response\CreatePaymentResponse;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class CreatePaymentResponseTest extends TestCase
11+
{
12+
13+
/**
14+
* test only if no exception throws
15+
* @doesNotPerformAssertions
16+
*/
17+
public function test__construct()
18+
{
19+
new CreatePaymentResponse(
20+
[
21+
'code' => ResponseCode::CODE_OK,
22+
'message' => 'OK',
23+
'transId' => 'asd-asd-asd-asd',
24+
'redirect' => 'http://test.cz',
25+
]
26+
);
27+
}
28+
29+
30+
public function test__constructCodeException()
31+
{
32+
$this->expectException(InvalidArgumentException::class);
33+
34+
new CreatePaymentResponse(
35+
[
36+
'message' => 'OK',
37+
'transId' => 'asd-asd-asd-asd',
38+
'redirect' => 'http://test.cz',
39+
]
40+
);
41+
}
42+
43+
44+
public function test__constructMessageException()
45+
{
46+
$this->expectException(InvalidArgumentException::class);
47+
48+
new CreatePaymentResponse(
49+
[
50+
'code' => ResponseCode::CODE_OK,
51+
'transId' => 'asd-asd-asd-asd',
52+
'redirect' => 'http://test.cz',
53+
]
54+
);
55+
}
56+
57+
58+
public function test__constructTransIdException()
59+
{
60+
$this->expectException(InvalidArgumentException::class);
61+
62+
new CreatePaymentResponse(
63+
[
64+
'code' => ResponseCode::CODE_OK,
65+
'message' => 'OK',
66+
'redirect' => 'http://test.cz',
67+
]
68+
);
69+
}
70+
71+
72+
public function test__constructRedirectException()
73+
{
74+
$this->expectException(InvalidArgumentException::class);
75+
76+
new CreatePaymentResponse(
77+
[
78+
'code' => ResponseCode::CODE_OK,
79+
'message' => 'OK',
80+
'transId' => 'asd-asd-asd-asd',
81+
]
82+
);
83+
}
84+
85+
public function testIsOk()
86+
{
87+
$response = new CreatePaymentResponse(
88+
[
89+
'code' => ResponseCode::CODE_OK,
90+
'message' => 'OK',
91+
'transId' => 'asd-asd-asd-asd',
92+
'redirect' => 'http://test.cz',
93+
]
94+
);
95+
96+
$this->assertSame(true, $response->isOk());
97+
}
98+
99+
public function testIsNotOk()
100+
{
101+
$response = new CreatePaymentResponse(
102+
[
103+
'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD,
104+
'message' => 'OK',
105+
'transId' => 'asd-asd-asd-asd',
106+
'redirect' => 'http://test.cz',
107+
]
108+
);
109+
110+
$this->assertSame(false, $response->isOk());
111+
}
112+
113+
public function testGetMessage()
114+
{
115+
$response = new CreatePaymentResponse(
116+
[
117+
'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD,
118+
'message' => 'OK',
119+
'transId' => 'asd-asd-asd-asd',
120+
'redirect' => 'http://test.cz',
121+
]
122+
);
123+
124+
$this->assertSame('OK', $response->getMessage());
125+
}
126+
127+
public function testGetTransId()
128+
{
129+
$response = new CreatePaymentResponse(
130+
[
131+
'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD,
132+
'message' => 'OK',
133+
'transId' => 'asd-asd-asd-asd',
134+
'redirect' => 'http://test.cz',
135+
]
136+
);
137+
138+
$this->assertSame('asd-asd-asd-asd', $response->getTransId());
139+
}
140+
141+
public function testGetRedirect()
142+
{
143+
$response = new CreatePaymentResponse(
144+
[
145+
'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD,
146+
'message' => 'OK',
147+
'transId' => 'asd-asd-asd-asd',
148+
'redirect' => 'http://test.cz',
149+
]
150+
);
151+
152+
$this->assertSame('http://test.cz', $response->getRedirectUrl());
153+
}
154+
155+
}

0 commit comments

Comments
 (0)