From 3993d939a61c92ae181baa52303b0844636d9241 Mon Sep 17 00:00:00 2001 From: yoeriwalstra Date: Tue, 23 Sep 2025 14:39:46 +0200 Subject: [PATCH 1/2] :sparkles: add followUpWithConfiguration constructor property to ShopSetupResponse --- src/Shop/Http/Responses/ShopSetupResponse.php | 23 ++++--- tests/Shops/ShopSetupResponseTest.php | 67 +++++++++++++++++++ 2 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 tests/Shops/ShopSetupResponseTest.php diff --git a/src/Shop/Http/Responses/ShopSetupResponse.php b/src/Shop/Http/Responses/ShopSetupResponse.php index a838e87..8d36df3 100644 --- a/src/Shop/Http/Responses/ShopSetupResponse.php +++ b/src/Shop/Http/Responses/ShopSetupResponse.php @@ -6,26 +6,29 @@ use Illuminate\Contracts\Support\Responsable; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Response; -use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class ShopSetupResponse implements Responsable { + /** + * @param string|null $authorizationUrl URL to external authorization service. + * @param bool $showConfiguration Instruction to the recipient of the response to fetch the configuration schema. + */ public function __construct( private readonly ?string $authorizationUrl = null, + private readonly bool $showConfiguration = false, ) { } - public function toResponse($request): SymfonyResponse + public function toResponse($request): JsonResponse { - if (!$this->authorizationUrl) { - return new Response('', SymfonyResponse::HTTP_NO_CONTENT); + $responseData = [ + 'show_configuration' => $this->showConfiguration, + ]; + + if ($this->authorizationUrl) { + $responseData['authorization_url'] = $this->authorizationUrl; } - return new JsonResponse([ - 'data' => [ - 'authorization_url' => $this->authorizationUrl, - ], - ]); + return new JsonResponse(['data' => $responseData]); } } diff --git a/tests/Shops/ShopSetupResponseTest.php b/tests/Shops/ShopSetupResponseTest.php new file mode 100644 index 0000000..225174c --- /dev/null +++ b/tests/Shops/ShopSetupResponseTest.php @@ -0,0 +1,67 @@ +toResponse(Mockery::mock(Request::class)) + ->getData(true), + ); + } + + public static function setupProvider(): array + { + return [ + [ + 'authorizationUrl' => null, + 'showConfiguration' => false, + 'responseData' => [ + 'data' => [ + 'show_configuration' => false, + ], + ], + ], + [ + 'authorizationUrl' => null, + 'showConfiguration' => true, + 'responseData' => [ + 'data' => [ + 'show_configuration' => true, + ], + ], + ], + [ + 'authorizationUrl' => 'http://localhost', + 'showConfiguration' => false, + 'responseData' => [ + 'data' => [ + 'show_configuration' => false, + 'authorization_url' => 'http://localhost', + ], + ], + ], + ]; + } +} From 74fe56e65cd3ed3feccec9ec97d41ba0db1d72ed Mon Sep 17 00:00:00 2001 From: yoeri walstra <48599583+yoerriwalstra@users.noreply.github.com> Date: Tue, 23 Sep 2025 15:58:39 +0200 Subject: [PATCH 2/2] update doc comment Co-authored-by: Yoan-Alexander Grigorov <46448148+yoan-myparcel@users.noreply.github.com> --- src/Shop/Http/Responses/ShopSetupResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shop/Http/Responses/ShopSetupResponse.php b/src/Shop/Http/Responses/ShopSetupResponse.php index 8d36df3..4f05624 100644 --- a/src/Shop/Http/Responses/ShopSetupResponse.php +++ b/src/Shop/Http/Responses/ShopSetupResponse.php @@ -11,7 +11,7 @@ class ShopSetupResponse implements Responsable { /** * @param string|null $authorizationUrl URL to external authorization service. - * @param bool $showConfiguration Instruction to the recipient of the response to fetch the configuration schema. + * @param bool $showConfiguration Instruction to the client of the response to display configuration form */ public function __construct( private readonly ?string $authorizationUrl = null,