Skip to content

Commit

Permalink
Merge pull request #14 from splitfire-agency/feat/add-config-server-s…
Browse files Browse the repository at this point in the history
…electore

Added config paybox.load_uri
  • Loading branch information
helitik authored Sep 4, 2023
2 parents f5108f8 + 4a85f46 commit 6e6df4e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
5 changes: 5 additions & 0 deletions config/paybox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
25 changes: 20 additions & 5 deletions src/Services/Billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,30 @@ public function getXml(): string
'<?xml version="1.0" encoding="utf-8"?><Billing><Address></Address></Billing>'
);
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);

Expand Down
7 changes: 6 additions & 1 deletion src/Services/ServerSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions tests/Providers/PayboxServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Providers;

use Illuminate\Config\Repository as Config;
use Sf\PayboxGateway\Providers\PayboxServiceProvider;
use Illuminate\Foundation\Application;
use Mockery;
Expand Down
20 changes: 20 additions & 0 deletions tests/Services/ServerSelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6e6df4e

Please sign in to comment.