Skip to content

Commit

Permalink
Merge pull request #60 from wedevBr/feature/AttachmentHeaders
Browse files Browse the repository at this point in the history
Feature/attachment headers
  • Loading branch information
adeildo-jr authored Mar 25, 2024
2 parents 7c64b75 + cd543ed commit ed1f7e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/Common/CelcoinBaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -115,7 +111,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)
Expand All @@ -133,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);
Expand All @@ -159,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);
Expand Down
2 changes: 2 additions & 0 deletions src/Interfaces/Attachable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public function getField(): string;
public function getContents();

public function getFileName();

public function getHeaders(): array;
}
5 changes: 5 additions & 0 deletions src/Types/KYC/KycDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public function getField(): string
{
return $this->field;
}

public function getHeaders(): array
{
return ['Content-Type' => $this->file->getMimeType()];
}
}

0 comments on commit ed1f7e1

Please sign in to comment.