diff --git a/composer.json b/composer.json index 027f4c4..06293ac 100644 --- a/composer.json +++ b/composer.json @@ -24,11 +24,11 @@ "guzzlehttp/psr7": "^2.6.2" }, "require-dev": { - "mockery/mockery": "^1.6.7", - "nette/di": "^3.1.8", + "contributte/phpstan": "^0.2.0", "contributte/qa": "^0.4", "contributte/tester": "^0.4", - "contributte/phpstan": "^0.1" + "mockery/mockery": "^1.6.7", + "nette/di": "^3.1.8" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 562ab05..17b4df4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,5 +14,6 @@ parameters: paths: - src - .docs + - tests/Cases ignoreErrors: diff --git a/src/Entity/AbstractEntity.php b/src/Entity/AbstractEntity.php index d30c715..63ab603 100644 --- a/src/Entity/AbstractEntity.php +++ b/src/Entity/AbstractEntity.php @@ -6,7 +6,7 @@ abstract class AbstractEntity { /** - * @return mixed[] + * @return array */ abstract public function toArray(): array; diff --git a/src/Entity/AbstractPayment.php b/src/Entity/AbstractPayment.php index 4853f8e..d03d813 100644 --- a/src/Entity/AbstractPayment.php +++ b/src/Entity/AbstractPayment.php @@ -10,7 +10,7 @@ class AbstractPayment extends AbstractEntity protected ?int $price = null; - /** @var string ISO 4217 */ + /** @see https://cs.wikipedia.org/wiki/ISO_4217 */ protected ?string $curr = null; protected ?string $label = null; @@ -119,7 +119,17 @@ public function setName(string $name): void } /** - * @return mixed[] + * @return array{ + * price: ?int, + * curr: ?string, + * label: ?string, + * refId: ?string, + * email: ?string, + * fullName: ?string, + * country: ?string, + * account: ?string, + * name: ?string, + * } */ public function toArray(): array { diff --git a/src/Entity/Payment.php b/src/Entity/Payment.php index 7f0bfd6..67fda6e 100644 --- a/src/Entity/Payment.php +++ b/src/Entity/Payment.php @@ -13,7 +13,7 @@ class Payment extends AbstractPayment private string $method = PaymentMethodCode::ALL; - /** @var string ISO 639-1 */ + /** @see https://cs.wikipedia.org/wiki/ISO_639-1 */ private string $lang = LangCode::CS; private bool $prepareOnly = true; @@ -26,6 +26,14 @@ class Payment extends AbstractPayment private bool $embedded = false; + private bool $chargeUnregulatedCardFees; + + private string $urlPaid; + + private string $urlCancelled; + + private string $urlPending; + final private function __construct() { // Noop @@ -39,7 +47,7 @@ public static function of( string $fullName, string $method = PaymentMethodCode::ALL, string $country = CountryCode::ALL, - string $lang = LangCode::CS + string $lang = LangCode::CS, ): self { $p = new static(); @@ -121,12 +129,73 @@ public function setEmbedded(bool $embedded): void $this->embedded = $embedded; } + public function isChargeUnregulatedCardFees(): bool + { + return $this->chargeUnregulatedCardFees; + } + + public function setChargeUnregulatedCardFees(bool $chargeUnregulatedCardFees): void + { + $this->chargeUnregulatedCardFees = $chargeUnregulatedCardFees; + } + + public function getUrlPaid(): string + { + return $this->urlPaid; + } + + public function setUrlPaid(string $urlPaid): void + { + $this->urlPaid = $urlPaid; + } + + public function getUrlCancelled(): string + { + return $this->urlCancelled; + } + + public function setUrlCancelled(string $urlCancelled): void + { + $this->urlCancelled = $urlCancelled; + } + + public function getUrlPending(): string + { + return $this->urlPending; + } + + public function setUrlPending(string $urlPending): void + { + $this->urlPending = $urlPending; + } + /** - * @return mixed[] + * @return array{ + * price: ?int, + * curr: ?string, + * label: ?string, + * refId: ?string, + * email: ?string, + * fullName: ?string, + * country: ?string, + * account: ?string, + * name: ?string, + * method: string, + * lang: string, + * prepareOnly: string, + * preauth: string, + * initRecurring: string, + * verification: string, + * embedded: string, + * chargeUnregulatedCardFees?: string, + * url_paid?: string, + * url_cancelled?: string, + * url_pending?: string, + * } */ public function toArray(): array { - return array_merge(parent::toArray(), [ + $data = [ 'method' => $this->method, 'lang' => $this->lang, 'prepareOnly' => $this->prepareOnly ? 'true' : 'false', @@ -134,7 +203,24 @@ public function toArray(): array 'initRecurring' => $this->initRecurring ? 'true' : 'false', 'verification' => $this->verification ? 'true' : 'false', 'embedded' => $this->embedded ? 'true' : 'false', - ]); + ]; + if (isset($this->chargeUnregulatedCardFees)) { + $data['chargeUnregulatedCardFees'] = $this->chargeUnregulatedCardFees ? 'true' : 'false'; + } + + if (isset($this->urlPaid)) { + $data['url_paid'] = $this->urlPaid; + } + + if (isset($this->urlCancelled)) { + $data['url_cancelled'] = $this->urlCancelled; + } + + if (isset($this->urlPending)) { + $data['url_pending'] = $this->urlPending; + } + + return array_merge(parent::toArray(), $data); } } diff --git a/src/Entity/PaymentStatus.php b/src/Entity/PaymentStatus.php index 8d3e724..16073d3 100644 --- a/src/Entity/PaymentStatus.php +++ b/src/Entity/PaymentStatus.php @@ -26,8 +26,10 @@ public function getTransId(): string } /** - * @return mixed[] - */ + * @return array{ + * transId: string, + * } + **/ public function toArray(): array { return [ diff --git a/src/Entity/RecurringPayment.php b/src/Entity/RecurringPayment.php index cf4f0fc..7fdfcd4 100644 --- a/src/Entity/RecurringPayment.php +++ b/src/Entity/RecurringPayment.php @@ -45,8 +45,20 @@ public function getInitRecurringId(): string } /** - * @return mixed[] - */ + * @return array{ + * price: ?int, + * curr: ?string, + * label: ?string, + * refId: ?string, + * email: ?string, + * fullName: ?string, + * country: ?string, + * account: ?string, + * name: ?string, + * prepareOnly: string, + * initRecurringId: string, + * } + **/ public function toArray(): array { return array_merge(parent::toArray(), [ diff --git a/src/Entity/Refund.php b/src/Entity/Refund.php index 7245812..7ce2679 100644 --- a/src/Entity/Refund.php +++ b/src/Entity/Refund.php @@ -10,7 +10,7 @@ class Refund extends AbstractEntity private int $amount; - /** @var string ISO 4217 */ + /** @see https://cs.wikipedia.org/wiki/ISO_4217 */ private string $curr; private string $transId; @@ -58,7 +58,12 @@ public function getRefId(): ?string } /** - * @return mixed[] + * @return array{ + * amount: float, + * curr: string, + * transId: string, + * refId: ?string + * } */ public function toArray(): array { diff --git a/src/Entity/Storno.php b/src/Entity/Storno.php index fe53768..f1b0cfa 100644 --- a/src/Entity/Storno.php +++ b/src/Entity/Storno.php @@ -28,7 +28,9 @@ public function getTransId(): string } /** - * @return mixed[] + * @return array{ + * transId: string, + * } */ public function toArray(): array { diff --git a/tests/Cases/E2E/payments.php b/tests/Cases/E2E/payments.php index 6e057e2..0c0b919 100644 --- a/tests/Cases/E2E/payments.php +++ b/tests/Cases/E2E/payments.php @@ -44,11 +44,10 @@ function createPayment(): void ); $res1 = $payments->create($payment); assert($res1->isOk() === true); - // var_dump($res->getData()); + assert(array_key_exists('transId', $res1->getData())); $res2 = $payments->status(PaymentStatus::of($res1->getData()['transId'])); assert($res2->isOk() === true); - // var_dump($res2->getData()); } (function (): void { diff --git a/tests/Cases/Entity/Payment.phpt b/tests/Cases/Entity/Payment.phpt index 6d27b9b..3ac18bf 100644 --- a/tests/Cases/Entity/Payment.phpt +++ b/tests/Cases/Entity/Payment.phpt @@ -138,3 +138,37 @@ Toolkit::test(function (): void { $payment->setLang(LangCode::PL); Assert::equal('pl', $payment->toArray()['lang']); }); + +Toolkit::test(function (): void { + $payment = Payment::of( + Money::of(50, 'CZK'), + 'Test item', + 'order101', + 'dev@contributte.org', + 'John Doe', + ); + $payment->setChargeUnregulatedCardFees(true); + Assert::hasKey('chargeUnregulatedCardFees', $payment->toArray()); + Assert::equal('true', $payment->toArray()['chargeUnregulatedCardFees']); +}); + +Toolkit::test(function (): void { + $payment = Payment::of( + Money::of(50, 'CZK'), + 'Test item', + 'order101', + 'dev@contributte.org', + 'John Doe', + ); + $payment->setUrlPaid('https://example.com/paid'); + $payment->setUrlCancelled('https://example.com/cancelled'); + $payment->setUrlPending('https://example.com/pending'); + + Assert::hasKey('url_paid', $payment->toArray()); + Assert::hasKey('url_cancelled', $payment->toArray()); + Assert::hasKey('url_pending', $payment->toArray()); + + Assert::equal('https://example.com/paid', $payment->toArray()['url_paid']); + Assert::equal('https://example.com/cancelled', $payment->toArray()['url_cancelled']); + Assert::equal('https://example.com/pending', $payment->toArray()['url_pending']); +});