From 107c610bba3b39eab7ef6477f0c43d468e974278 Mon Sep 17 00:00:00 2001 From: woutse Date: Thu, 27 Feb 2025 14:13:29 +0100 Subject: [PATCH 1/5] Added getAmountRefunded method for PayOrder class --- samples/OrderStatus.php | 1 + samples/TransactionStatus.php | 2 ++ src/Model/Pay/PayOrder.php | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/samples/OrderStatus.php b/samples/OrderStatus.php index c0257e2..97652bc 100644 --- a/samples/OrderStatus.php +++ b/samples/OrderStatus.php @@ -41,6 +41,7 @@ echo 'isRefunded: ' . ($payOrder->isRefunded() ? 'YES' : 'no') . PHP_EOL; echo 'isPartiallyRefunded: ' . ($payOrder->isRefundedPartial() ? 'YES' : 'no') . PHP_EOL . PHP_EOL; echo 'isFastcheckout: ' . ($payOrder->isFastcheckout() ? 'YES' : 'no') . PHP_EOL; +echo 'getAmountRefunded: ' . ($payOrder->getAmountRefunded()) . PHP_EOL . PHP_EOL; echo 'getStatusCode: ' . $payOrder->getStatusCode() . PHP_EOL; echo 'getStatusName: ' . $payOrder->getStatusName() . PHP_EOL; echo 'getId: ' . $payOrder->getId() . PHP_EOL; diff --git a/samples/TransactionStatus.php b/samples/TransactionStatus.php index 3563465..6176568 100644 --- a/samples/TransactionStatus.php +++ b/samples/TransactionStatus.php @@ -38,6 +38,8 @@ echo 'isPartialPayment: ' . ($payOrder->isPartialPayment() ? 'YES' : 'no') . PHP_EOL; echo 'isRefunded: ' . ($payOrder->isRefunded() ? 'YES' : 'no') . PHP_EOL; echo 'isPartiallyRefunded: ' . ($payOrder->isRefundedPartial() ? 'YES' : 'no') . PHP_EOL . PHP_EOL; +echo 'getAmount: ' . ($payOrder->getAmount()) . PHP_EOL; +echo 'getAmountRefunded: ' . ($payOrder->getAmountRefunded()) . PHP_EOL . PHP_EOL; echo 'getStatusCode: ' . $payOrder->getStatusCode() . PHP_EOL; echo 'getStatusName: ' . $payOrder->getStatusName() . PHP_EOL; echo 'getId: ' . $payOrder->getId() . PHP_EOL; diff --git a/src/Model/Pay/PayOrder.php b/src/Model/Pay/PayOrder.php index 0f5c839..a668330 100644 --- a/src/Model/Pay/PayOrder.php +++ b/src/Model/Pay/PayOrder.php @@ -130,6 +130,11 @@ class PayOrder implements ModelInterface */ protected $completedAt; + /** + * @var Amount + */ + protected $amountRefunded; + /** * @var array */ @@ -153,6 +158,27 @@ public function __construct($payload = null) } } + /** + * @return mixed + */ + public function getAmountRefunded() + { + if (!empty($this->amountRefunded) && $this->amountRefunded instanceof Amount) { + return $this->amountRefunded->getValue() / 100; + } + return null; + } + + /** + * @param $amountRefunded + * @return $this + */ + public function setAmountRefunded($amountRefunded): self + { + $this->amountRefunded = $amountRefunded; + return $this; + } + /** * @return string */ @@ -736,6 +762,16 @@ public function isRefundedPartial() } + /** + * @return bool + * @throws \Exception + */ + public function amountRefunded() + { + return (new PayStatus)->get($this->getStatusCode()) === PayStatus::PARTIAL_REFUND; + + } + /** * @return bool * @throws \Exception From 454d02cf8b03bb56be130b181fef9ae15c2ccf6d Mon Sep 17 00:00:00 2001 From: woutse Date: Thu, 27 Feb 2025 14:59:26 +0100 Subject: [PATCH 2/5] Fixed getSettings returning array --- src/Model/Method.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Method.php b/src/Model/Method.php index 2c61031..a380b00 100644 --- a/src/Model/Method.php +++ b/src/Model/Method.php @@ -159,7 +159,7 @@ public function setOptions(array $options): self */ public function getSettings(): array { - return $this->settings; + return $this->settings ?? []; } /** From 42b1bb4c023295d70b51dc41178420a7cd86ad3e Mon Sep 17 00:00:00 2001 From: woutse Date: Thu, 27 Feb 2025 15:32:02 +0100 Subject: [PATCH 3/5] Updated getCores method --- samples/ServiceGetConfig.php | 2 +- .../Response/ServiceGetConfigResponse.php | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/samples/ServiceGetConfig.php b/samples/ServiceGetConfig.php index 4b5d75e..231677e 100644 --- a/samples/ServiceGetConfig.php +++ b/samples/ServiceGetConfig.php @@ -36,7 +36,7 @@ $terminals = $config->getTerminals(); print_r($terminals); -$tguList = $config->getTguList(); +$tguList = $config->getCores(); print_r($tguList); $paymentMethods = $config->getPaymentMethods(); diff --git a/src/Model/Response/ServiceGetConfigResponse.php b/src/Model/Response/ServiceGetConfigResponse.php index cdc85d4..796e4df 100644 --- a/src/Model/Response/ServiceGetConfigResponse.php +++ b/src/Model/Response/ServiceGetConfigResponse.php @@ -316,7 +316,7 @@ public function setCategory(array $category): void */ public function getTguList(): array { - return $this->tguList; + return $this->tguList ?? []; } /** @@ -328,11 +328,35 @@ public function setTguList(array $tguList): void } /** + * Returns formatted cores with ensured subdomains and HTTPS prefix. + * * @return array */ public function getCores(): array { - return $this->getTguList(); + $tguList = $this->getTguList(); + + foreach ($tguList as &$v) { + $domain = trim($v['domain']); + $hasHttp = strtolower(substr($domain, 0, 4)) == 'http'; + + $host = parse_url($hasHttp ? $domain : 'https://' . $domain, PHP_URL_HOST); + $parts = explode('.', $host); + + # No subdomain, then add "connect" + if (count($parts) <= 2) { + $domain = 'connect.' . $domain; + } + + # Ensure HTTPS prefix + if (!$hasHttp) { + $domain = 'https://' . $domain; + } + + $v['domain'] = $domain; + } + + return $tguList; } /** From 78598ea3b5fdac918bbbbb263731d992585f6abb Mon Sep 17 00:00:00 2001 From: woutse Date: Thu, 27 Feb 2025 18:43:17 +0100 Subject: [PATCH 4/5] Code polish --- samples/OrderCreate.php | 2 +- .../Response/ServiceGetConfigResponse.php | 26 +------------------ src/Util/Exchange.php | 5 ++-- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/samples/OrderCreate.php b/samples/OrderCreate.php index a616041..95690d4 100644 --- a/samples/OrderCreate.php +++ b/samples/OrderCreate.php @@ -15,7 +15,7 @@ $request->setDescription('Order ABC0123456789'); $request->setAmount((float)($_REQUEST['amount'] ?? 5.3)); $request->setCurrency('EUR'); -$request->setExpire(date('Y-m-d H:i:s', strtotime('+1 DAY'))); +$request->setExpire(date('c', time() + 60)); $request->setReturnurl($_REQUEST['returnUrl'] ?? 'https://yourdomain/finish.php'); $request->setExchangeUrl($_REQUEST['exchangeUrl'] ?? 'https://yourdomain/exchange.php'); $request->setPaymentMethodId((int)($_REQUEST['paymentMethodId'] ?? 10)); diff --git a/src/Model/Response/ServiceGetConfigResponse.php b/src/Model/Response/ServiceGetConfigResponse.php index 796e4df..a7ad8d9 100644 --- a/src/Model/Response/ServiceGetConfigResponse.php +++ b/src/Model/Response/ServiceGetConfigResponse.php @@ -328,35 +328,11 @@ public function setTguList(array $tguList): void } /** - * Returns formatted cores with ensured subdomains and HTTPS prefix. - * * @return array */ public function getCores(): array { - $tguList = $this->getTguList(); - - foreach ($tguList as &$v) { - $domain = trim($v['domain']); - $hasHttp = strtolower(substr($domain, 0, 4)) == 'http'; - - $host = parse_url($hasHttp ? $domain : 'https://' . $domain, PHP_URL_HOST); - $parts = explode('.', $host); - - # No subdomain, then add "connect" - if (count($parts) <= 2) { - $domain = 'connect.' . $domain; - } - - # Ensure HTTPS prefix - if (!$hasHttp) { - $domain = 'https://' . $domain; - } - - $v['domain'] = $domain; - } - - return $tguList; + return $this->getTguList(); } /** diff --git a/src/Util/Exchange.php b/src/Util/Exchange.php index cae6240..aa63f0a 100644 --- a/src/Util/Exchange.php +++ b/src/Util/Exchange.php @@ -4,7 +4,6 @@ namespace PayNL\Sdk\Util; -use PayNL\Sdk\Config\Config as PayConfig; use PayNL\Sdk\Config\Config; use PayNL\Sdk\Model\Amount; use PayNL\Sdk\Model\Request\OrderStatusRequest; @@ -201,11 +200,11 @@ public function getPayLoad() /** * Process the exchange request. * - * @param Config|null $config + * @param Config |null $config * @return PayOrder * @throws Exception */ - public function process(PayConfig $config = null): PayOrder + public function process(Config $config = null): PayOrder { $payload = $this->getPayload(); From 196ec460bde4f1557ee35f62b891b9855b5eba30 Mon Sep 17 00:00:00 2001 From: woutse Date: Thu, 27 Feb 2025 21:12:33 +0100 Subject: [PATCH 5/5] Code polish --- src/Model/Pay/PayOrder.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Model/Pay/PayOrder.php b/src/Model/Pay/PayOrder.php index a668330..a5bde9d 100644 --- a/src/Model/Pay/PayOrder.php +++ b/src/Model/Pay/PayOrder.php @@ -762,16 +762,6 @@ public function isRefundedPartial() } - /** - * @return bool - * @throws \Exception - */ - public function amountRefunded() - { - return (new PayStatus)->get($this->getStatusCode()) === PayStatus::PARTIAL_REFUND; - - } - /** * @return bool * @throws \Exception