diff --git a/src/Request/Models/Endpoint.php b/src/Request/Models/Endpoint.php index e694b6d..bd5982e 100644 --- a/src/Request/Models/Endpoint.php +++ b/src/Request/Models/Endpoint.php @@ -9,9 +9,7 @@ use Consilience\Starling\Payments\HydratableTrait; use Consilience\Starling\Payments\ValidationTrait; use Consilience\Starling\Payments\ModelInterface; -use UnexpectedValueException; - -use function GuzzleHttp\Psr7\build_query; +use GuzzleHttp\Psr7\Query; use GuzzleHttp\Psr7\Uri; class Endpoint implements ModelInterface @@ -98,11 +96,15 @@ public function getUrl($servicePath = '', $query = []) $replacements['{' . $fieldName . '}'] = $this->getProperty($fieldName); } - $path = str_replace( - array_keys($replacements), - array_values($replacements), - $template - ); + // A URL with an authority must start with a slash. + + $path = '/' . ltrim( + str_replace( + array_keys($replacements), + array_values($replacements), + $template + ), + '/'); $uri = new Uri(); @@ -112,7 +114,7 @@ public function getUrl($servicePath = '', $query = []) ->withHost($this->host); if (! empty($query)) { - $uri = $uri->withQuery(build_query($query)); + $uri = $uri->withQuery(Query::build($query)); } return $uri; diff --git a/tests/Response/BusinessInformationTest.php b/tests/Response/BusinessInformationTest.php index cfc1362..17e06dc 100644 --- a/tests/Response/BusinessInformationTest.php +++ b/tests/Response/BusinessInformationTest.php @@ -61,6 +61,7 @@ public function testFromPSR7($contentType) "minorUnits": 12345 } }'; + $businessInformationResponse = new Psr7Response( 200, [