From 4a85f46ceb11c7e4491f9df21f990c406689168b Mon Sep 17 00:00:00 2001 From: HeLiTiK Date: Mon, 4 Sep 2023 10:16:39 +0200 Subject: [PATCH] Added config paybox.load_uri --- config/paybox.php | 5 ++++ src/Services/Billing.php | 25 +++++++++++++++---- src/Services/ServerSelector.php | 7 +++++- tests/Providers/PayboxServiceProviderTest.php | 1 + tests/Services/ServerSelectorTest.php | 20 +++++++++++++++ 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/config/paybox.php b/config/paybox.php index d6cdc8c..52b54db 100644 --- a/config/paybox.php +++ b/config/paybox.php @@ -109,6 +109,11 @@ */ "transaction_verify_route_name" => "paybox.process", + /* + * Load uri (not url) for testing server selector + */ + "load_uri" => "load.html", + /* * Access urls for Paybox for production environment */ diff --git a/src/Services/Billing.php b/src/Services/Billing.php index 22a992b..2c15036 100644 --- a/src/Services/Billing.php +++ b/src/Services/Billing.php @@ -322,15 +322,30 @@ public function getXml(): string '
' ); if ($this->companyName) { - $dom->Address->addChild("CompanyName", htmlspecialchars($this->companyName)); + $dom->Address->addChild( + "CompanyName", + htmlspecialchars($this->companyName) + ); } - $dom->Address->addChild("FirstName", htmlspecialchars($this->firstName ?? "xxx")); - $dom->Address->addChild("LastName", htmlspecialchars($this->lastName ?? "xxx")); - $dom->Address->addChild("Address1", htmlspecialchars($this->address1 ?? "xxx")); + $dom->Address->addChild( + "FirstName", + htmlspecialchars($this->firstName ?? "xxx") + ); + $dom->Address->addChild( + "LastName", + htmlspecialchars($this->lastName ?? "xxx") + ); + $dom->Address->addChild( + "Address1", + htmlspecialchars($this->address1 ?? "xxx") + ); if ($this->address2) { $dom->Address->addChild("Address2", htmlspecialchars($this->address2)); } - $dom->Address->addChild("ZipCode", htmlspecialchars($this->zipcode ?? "xxx")); + $dom->Address->addChild( + "ZipCode", + htmlspecialchars($this->zipcode ?? "xxx") + ); $dom->Address->addChild("City", htmlspecialchars($this->city ?? "xxx")); $dom->Address->addChild("CountryCode", $this->countryCode ?? 250); diff --git a/src/Services/ServerSelector.php b/src/Services/ServerSelector.php index 41f2ff8..e3b6d61 100644 --- a/src/Services/ServerSelector.php +++ b/src/Services/ServerSelector.php @@ -38,7 +38,12 @@ public function find($type) foreach ($servers as $key => $server) { $doc = $this->getDocumentLoader(); - $doc->loadHTMLFile("https://" . $server . "/load.html"); + $doc->loadHTMLFile( + "https://" . + $server . + "/" . + ltrim($this->config->get("paybox.load_uri", "load.html"), "/") + ); $element = $doc->getElementById("server_status"); if ($element && $element->textContent == "OK") { return $urls[$key]; diff --git a/tests/Providers/PayboxServiceProviderTest.php b/tests/Providers/PayboxServiceProviderTest.php index 84d9091..a014fda 100644 --- a/tests/Providers/PayboxServiceProviderTest.php +++ b/tests/Providers/PayboxServiceProviderTest.php @@ -2,6 +2,7 @@ namespace Tests\Providers; +use Illuminate\Config\Repository as Config; use Sf\PayboxGateway\Providers\PayboxServiceProvider; use Illuminate\Foundation\Application; use Mockery; diff --git a/tests/Services/ServerSelectorTest.php b/tests/Services/ServerSelectorTest.php index e474d82..687ac95 100644 --- a/tests/Services/ServerSelectorTest.php +++ b/tests/Services/ServerSelectorTest.php @@ -46,6 +46,11 @@ public function testFindValidServerForPayboxWhenTestIsOnAnd1stServerIsFine() ->with("paybox.test_urls.paybox") ->once() ->andReturn($urls); + $config + ->shouldReceive("get") + ->with("paybox.load_uri", "load.html") + ->once() + ->andReturn("load.html"); $serverSelector ->shouldReceive("getDocumentLoader") @@ -93,6 +98,11 @@ public function testReturnValidServerForPayboxWhenTestIsOffAnd1stServerIsFine() ->with("paybox.production_urls.paybox") ->once() ->andReturn($urls); + $config + ->shouldReceive("get") + ->with("paybox.load_uri", "load.html") + ->once() + ->andReturn("load.html"); $serverSelector ->shouldReceive("getDocumentLoader") @@ -143,6 +153,11 @@ public function testFindValidServerForPayboxWhenTestIsOffAnd1stServerIsDown() ->with("paybox.production_urls.paybox") ->once() ->andReturn($urls); + $config + ->shouldReceive("get") + ->with("paybox.load_uri", "load.html") + ->twice() + ->andReturn("load.html"); $serverSelector ->shouldReceive("getDocumentLoader") @@ -203,6 +218,11 @@ public function testThrowsExceptionWhenTestIsOffAndAllServersAreDown() ->with("paybox.production_urls.paybox") ->once() ->andReturn($urls); + $config + ->shouldReceive("get") + ->with("paybox.load_uri", "load.html") + ->twice() + ->andReturn("load.html"); $serverSelector ->shouldReceive("getDocumentLoader")