Skip to content

Commit

Permalink
feat: add mockHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
kajetan-nobel committed Oct 4, 2023
1 parent cb2f26b commit 0842698
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Exceptions/SchemaValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SchemaValidationException extends Exception
public function __construct(array $errors)
{
$this->errors = $errors;
parent::__construct('Given data doesnt fullfill JSON schema requirements', 422);
parent::__construct('Given data doesnt fulfill JSON schema requirements.', 422);
}

public function context(): array
Expand Down
18 changes: 17 additions & 1 deletion src/Lib/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Routegroup\Imoje\Payment\DTO\BaseDto;
use Routegroup\Imoje\Payment\Types\HashMethod;

class Utils
Expand Down Expand Up @@ -69,7 +70,22 @@ public function transformValues(array $values): array
return $computed;
}

public function isEqualWithStructure(array $data, array $structure): bool
public function mockHeaders(
BaseDto $dto,
HashMethod $hashMethod = HashMethod::SHA256
): array {
$body = json_encode($dto->toArray(), JSON_UNESCAPED_SLASHES);
$signature = hash($hashMethod->value, $body.$this->config->serviceKey);

$value = "merchantid={$this->config->merchantId};";
$value .= "serviceid={$this->config->serviceId};";
$value .= "signature=$signature;";
$value .= "alg=$hashMethod->value";

return ['x-imoje-signature' => $value];
}

public function hasStructure(array $data, array $structure): bool
{
$structure = Arr::dot($structure);
$data = Arr::dot($data);
Expand Down
4 changes: 3 additions & 1 deletion tests/Lib/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@

it('transforms values')->todo();

it('checks if contains a structure')->todo();
it('mock headers')->todo();

it('checks if contains structure')->todo();

0 comments on commit 0842698

Please sign in to comment.