From f6bb6441dcf594859aab1281aa0f5cb6840dacbd Mon Sep 17 00:00:00 2001 From: Adeildo Amorim Date: Mon, 25 Mar 2024 17:09:41 -0300 Subject: [PATCH 1/2] [Feature] Added headers and content type for celcoin attachments --- src/Common/CelcoinBaseApi.php | 7 ++++++- src/Interfaces/Attachable.php | 2 ++ src/Types/KYC/KycDocument.php | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Common/CelcoinBaseApi.php b/src/Common/CelcoinBaseApi.php index 5fcc9d7..c237516 100644 --- a/src/Common/CelcoinBaseApi.php +++ b/src/Common/CelcoinBaseApi.php @@ -115,7 +115,12 @@ public function post(string $endpoint, array $body = [], Attachable $attachment } if ($attachment) { - $request->attach($attachment->getField(), $attachment->getContents(), $attachment->getFileName()); + $request->attach( + $attachment->getField(), + $attachment->getContents(), + $attachment->getFileName(), + $attachment->getHeaders() + ); } return $request->post($this->getFinalUrl($endpoint), $body) diff --git a/src/Interfaces/Attachable.php b/src/Interfaces/Attachable.php index 8abb0f0..043b591 100644 --- a/src/Interfaces/Attachable.php +++ b/src/Interfaces/Attachable.php @@ -9,4 +9,6 @@ public function getField(): string; public function getContents(); public function getFileName(); + + public function getHeaders(): array; } \ No newline at end of file diff --git a/src/Types/KYC/KycDocument.php b/src/Types/KYC/KycDocument.php index 3a0c000..7297c2e 100644 --- a/src/Types/KYC/KycDocument.php +++ b/src/Types/KYC/KycDocument.php @@ -40,4 +40,9 @@ public function getField(): string { return $this->field; } + + public function getHeaders(): array + { + return ['Content-Type' => $this->file->getMimeType()]; + } } From cd543ed9e8f4cc331a14a431a883e2f885c75512 Mon Sep 17 00:00:00 2001 From: Adeildo Amorim Date: Mon, 25 Mar 2024 17:14:16 -0300 Subject: [PATCH 2/2] [Refactor] Improved celcoin base api --- src/Common/CelcoinBaseApi.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Common/CelcoinBaseApi.php b/src/Common/CelcoinBaseApi.php index c237516..4fceba5 100644 --- a/src/Common/CelcoinBaseApi.php +++ b/src/Common/CelcoinBaseApi.php @@ -77,10 +77,8 @@ public function get(string $endpoint, array|string|null $query = null, $response { $token = $this->getToken() ?? $this->auth->getToken(); $request = Http::withToken($token) - ->withHeaders([ - 'accept' => 'application/json', - 'content-type' => 'application/json', - ]); + ->asJson() + ->acceptJson(); if ($this->mtlsCert && $this->mtlsKey && $this->mtlsPassphrase) { $request = $this->setRequestMtls($request); @@ -99,10 +97,8 @@ public function post(string $endpoint, array $body = [], Attachable $attachment { $token = $this->getToken() ?? $this->auth->getToken(); $request = Http::withToken($token) - ->withHeaders([ - 'accept' => 'application/json', - 'content-type' => 'application/json' - ]); + ->asJson() + ->acceptJson(); if ($this->mtlsCert && $this->mtlsKey && $this->mtlsPassphrase) { $request = $this->setRequestMtls($request); @@ -138,10 +134,8 @@ public function put( { $token = $this->getToken() ?? $this->auth->getToken(); $request = Http::withToken($token) - ->withHeaders([ - 'accept' => 'application/json', - 'content-type' => 'application/json', - ]); + ->asJson() + ->acceptJson(); if ($this->mtlsCert && $this->mtlsKey && $this->mtlsPassphrase) { $request = $this->setRequestMtls($request); @@ -164,11 +158,9 @@ public function patch( $body_format = $asJson ? 'json' : 'form_params'; $token = $this->getToken() ?? $this->auth->getToken(); $request = Http::withToken($token) - ->bodyFormat($body_format) - ->withHeaders([ - 'accept' => 'application/json', - 'content-type' => 'application/json', - ]); + ->asJson() + ->acceptJson() + ->bodyFormat($body_format); if ($this->mtlsCert && $this->mtlsKey && $this->mtlsPassphrase) { $request = $this->setRequestMtls($request);