Skip to content

Commit 5de50cb

Browse files
author
Vladimir Gelunov
committed
PE-868: WIP
1 parent 0ea1f15 commit 5de50cb

File tree

9 files changed

+131
-86
lines changed

9 files changed

+131
-86
lines changed

composer.json

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
{
2-
"name": "ecommpay/paymentpage-sdk",
3-
"description": "Ecommpay SDK",
4-
"type": "library",
5-
"version": "1.5.2",
6-
"authors": [
7-
{
8-
"name": "Roman Zhukov",
9-
"email": "r.zhukov@it.ecommpay.com"
10-
}
11-
],
12-
"autoload": {
13-
"psr-4": { "ecommpay\\": "src/" }
14-
},
15-
"require": {
16-
"php": ">=7.4",
17-
"ext-json": "*",
18-
"ext-mbstring": "*"
19-
},
20-
"require-dev": {
21-
"phpunit/phpunit": "^9.5",
22-
"squizlabs/php_codesniffer": "^3.3"
23-
},
24-
"scripts": {
25-
"lint": "phpcs --report=full --report-width=120",
26-
"test": "phpunit --coverage-clover clover.xml"
2+
"name": "ecommpay/paymentpage-sdk",
3+
"description": "Ecommpay SDK",
4+
"type": "library",
5+
"version": "1.5.2",
6+
"authors": [
7+
{
8+
"name": "Roman Zhukov",
9+
"email": "r.zhukov@it.ecommpay.com"
2710
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"ecommpay\\": "src/"
15+
}
16+
},
17+
"require": {
18+
"php": ">=7.0",
19+
"ext-json": "*",
20+
"ext-mbstring": "*"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "^9.5",
24+
"squizlabs/php_codesniffer": "^3.3"
25+
},
26+
"scripts": {
27+
"lint": "phpcs --report=full --report-width=120",
28+
"test": "phpunit --coverage-clover clover.xml"
29+
}
2830
}

src/Callback.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@
1616
*/
1717
class Callback extends DataContainer
1818
{
19-
public const PAYMENT_FIELD = 'payment';
20-
public const OPERATION_FIELD = 'operation';
19+
const PAYMENT_FIELD = 'payment';
20+
const OPERATION_FIELD = 'operation';
2121

22-
private SignatureHandler $signatureHandler;
22+
/**
23+
* @var \ecommpay\SignatureHandler
24+
*/
25+
private $signatureHandler;
2326

24-
private Payment $payment;
27+
/**
28+
* @var Payment
29+
*/
30+
private $payment;
2531

26-
private Operation $operation;
32+
/**
33+
* @var Operation
34+
*/
35+
private $operation;
2736

2837
/**
2938
* @param string|array $data RAW or already processed data from gate
@@ -63,12 +72,18 @@ public function setData($data): DataContainer
6372
return $this;
6473
}
6574

66-
public function getPayment(): ?Payment
75+
/**
76+
* @return Payment|null
77+
*/
78+
public function getPayment()
6779
{
6880
return $this->payment ?? null;
6981
}
7082

71-
public function getOperation(): ?Operation
83+
/**
84+
* @return Operation|null
85+
*/
86+
public function getOperation()
7287
{
7388
return $this->operation ?? null;
7489
}
@@ -118,8 +133,9 @@ public function checkSignature(): bool
118133
*
119134
* @param string $name param name
120135
* @param array $data tmp data (passed by reference)
136+
* @return void
121137
*/
122-
private function removeParam(string $name, array &$data): void
138+
private function removeParam(string $name, array &$data)
123139
{
124140
if (isset($data[$name])) {
125141
unset($data[$name]);

src/Gate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*/
1212
class Gate
1313
{
14-
public const CURRENCY_RUB = 'RUB';
15-
public const CURRENCY_USD = 'USD';
16-
public const CURRENCY_EUR = 'EUR';
14+
const CURRENCY_RUB = 'RUB';
15+
const CURRENCY_USD = 'USD';
16+
const CURRENCY_EUR = 'EUR';
1717

1818
/**
1919
* Builder for Payment page

src/callback/Operation.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
class Operation extends DataContainer
88
{
9-
public const REQUEST_ID = 'request_id';
10-
public const STATUS = 'status';
11-
public const SUCCESS_STATUS = 'success';
9+
const REQUEST_ID = 'request_id';
10+
const STATUS = 'status';
11+
const SUCCESS_STATUS = 'success';
1212

13-
public function getStatus(): ?string
13+
/**
14+
* @return string|null
15+
*/
16+
public function getStatus()
1417
{
1518
return $this->getValue(self::STATUS);
1619
}
@@ -20,7 +23,10 @@ public function isSuccess(): bool
2023
return $this->getStatus() === self::SUCCESS_STATUS;
2124
}
2225

23-
public function getRequestId(): ?string
26+
/**
27+
* @return string|null
28+
*/
29+
public function getRequestId()
2430
{
2531
return $this->getValue(self::REQUEST_ID);
2632
}

src/callback/Payment.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
class Payment extends DataContainer
99
{
10-
public const DESCRIPTION = 'description';
11-
public const METHOD = 'method';
12-
public const AMOUNT = 'amount';
13-
public const STATUS = 'status';
14-
public const ID = 'id';
15-
16-
public function getStatus(): ?string
10+
const DESCRIPTION = 'description';
11+
const METHOD = 'method';
12+
const AMOUNT = 'amount';
13+
const STATUS = 'status';
14+
const ID = 'id';
15+
16+
/**
17+
* @return string|null
18+
*/
19+
public function getStatus()
1720
{
1821
return $this->getValue(self::STATUS);
1922
}
@@ -23,24 +26,36 @@ public function isSuccess(): bool
2326
return $this->getStatus() === EcpPaymentStatus::SUCCESS;
2427
}
2528

26-
public function getId(): ?string
29+
/**
30+
* @return string|null
31+
*/
32+
public function getId()
2733
{
2834
return $this->getValue(self::ID);
2935
}
3036

31-
public function getDescription(): ?string
37+
/**
38+
* @return string|null
39+
*/
40+
public function getDescription()
3241
{
3342
return $this->getValue(self::DESCRIPTION);
3443
}
3544

36-
public function getMethod(): ?string
45+
/**
46+
* @return string|null
47+
*/
48+
public function getMethod()
3749
{
3850
return $this->getValue(self::METHOD);
3951
}
4052

41-
public function getAmount(): ?int
53+
/**
54+
* @return int|null
55+
*/
56+
public function getAmount()
4257
{
4358
$amount = $this->getValue(self::AMOUNT);
44-
return $amount != null ? intval($amount) : null;
59+
return $amount !== null ? (int) $amount : null;
4560
}
4661
}

src/enums/EcpPaymentStatus.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,67 @@ final class EcpPaymentStatus
1010
* Payment completed successfully
1111
* @var string
1212
*/
13-
public const SUCCESS = 'success';
13+
const SUCCESS = 'success';
1414

1515
/**
1616
* An internal error occurred
1717
* @var string
1818
*/
19-
public const INTERNAL_ERROR = 'internal error';
19+
const INTERNAL_ERROR = 'internal error';
2020

2121
/**
2222
* The payment request has expired
2323
* @var string
2424
*/
25-
public const EXPIRED = 'expired';
25+
const EXPIRED = 'expired';
2626

2727
/**
2828
* Awaiting customer actions, if the customer may perform additional attempts to make a payment
2929
* @var string
3030
*/
31-
public const AWAITING_CUSTOMER = 'awaiting customer';
31+
const AWAITING_CUSTOMER = 'awaiting customer';
3232

3333
/**
3434
* The payment was declined
3535
* @var string
3636
*/
37-
public const DECLINE = 'decline';
37+
const DECLINE = 'decline';
3838

3939
/**
4040
* An external error occurred during the payment process
4141
* @var string
4242
*/
43-
public const EXTERNAL_ERROR = 'external error';
43+
const EXTERNAL_ERROR = 'external error';
4444

4545
/**
4646
* Awaiting a request with the result of a 3-D Secure Verification
4747
* @var string
4848
*/
49-
public const AWAITING_3DS_RESULT = 'awaiting 3ds result';
49+
const AWAITING_3DS_RESULT = 'awaiting 3ds result';
5050

5151
/**
5252
* Awaiting customer return after redirecting the customer to an external provider system
5353
* @var string
5454
*/
55-
public const AWAITING_REDIRECT_RESULT = 'awaiting redirect result';
55+
const AWAITING_REDIRECT_RESULT = 'awaiting redirect result';
5656

5757
/**
5858
* Awaiting additional parameters
5959
* @var string
6060
*/
61-
public const AWAITING_CLARIFICATION = 'awaiting clarification';
61+
const AWAITING_CLARIFICATION = 'awaiting clarification';
6262

6363
/**
6464
* Awaiting request for withdrawal of funds (capture) or cancellation of payment (cancel) from your project
6565
* @var string
6666
*/
67-
public const AWAITING_CAPTURE = 'awaiting capture';
67+
const AWAITING_CAPTURE = 'awaiting capture';
6868

6969
/**
7070
* Holding of funds (produced on authorization request) is cancelled
7171
* @var string
7272
*/
73-
public const CANCELED = 'canceled';
73+
const CANCELED = 'canceled';
7474

7575
/**
7676
* @deprecated use Callback::CANCELED instead
@@ -79,37 +79,37 @@ final class EcpPaymentStatus
7979
* Holding of funds (produced on authorization request) is cancelled
8080
* @var string
8181
*/
82-
public const CANCELLED = self::CANCELED;
82+
const CANCELLED = self::CANCELED;
8383

8484
/**
8585
* Successfully completed the full refund after a successful payment
8686
* @var string
8787
*/
88-
public const REFUNDED = 'refunded';
88+
const REFUNDED = 'refunded';
8989

9090
/**
9191
* Completed partial refund after a successful payment
9292
* @var string
9393
*/
94-
public const PARTIALLY_REFUNDED = 'partially refunded';
94+
const PARTIALLY_REFUNDED = 'partially refunded';
9595

9696
/**
9797
* Payment processing at Gate
9898
* @var string
9999
*/
100-
public const PROCESSING = 'processing';
100+
const PROCESSING = 'processing';
101101

102102
/**
103103
* An error occurred while reviewing data for payment processing
104104
* @var string
105105
*/
106-
public const ERROR = 'error';
106+
const ERROR = 'error';
107107

108108
/**
109109
* Refund after a successful payment before closing of the business day
110110
* @var string
111111
*/
112-
public const REVERSED = 'reversed';
112+
const REVERSED = 'reversed';
113113

114114
public static function values(): array
115115
{

src/exception/SdkException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
interface SdkException extends Throwable
1111
{
12-
public const
12+
const
1313
INVALID_SIGNATURE = 0xa0000001,
1414
UNDEFINED_SIGNATURE = 0xa0000002,
1515
DECODING_ERROR = 0xa0000003,

src/support/DataContainer.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
abstract class DataContainer
99
{
10-
private array $data;
10+
11+
/**
12+
* @var array
13+
*/
14+
private $data;
1115

1216
/**
1317
* @param string|array $data
@@ -54,14 +58,16 @@ private function toArray($rawData): array
5458
}
5559

5660
return $data;
57-
} elseif (is_array($rawData)) {
61+
}
62+
63+
if (is_array($rawData)) {
5864
return $rawData;
59-
} else {
60-
throw new ProcessException(
61-
'Error on response decoding. Unexpected type of data',
62-
SdkException::DECODING_ERROR
63-
);
6465
}
66+
67+
throw new ProcessException(
68+
'Error on response decoding. Unexpected type of data',
69+
SdkException::DECODING_ERROR
70+
);
6571
}
6672

6773
/**

0 commit comments

Comments
 (0)