Skip to content

Commit

Permalink
chore: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ging-dev committed Oct 11, 2024
1 parent 5f978d3 commit a4b3d9c
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 377 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
vendor
tools
test.php
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"type": "library",
"license": "MIT",
"autoload": {
"classmap": [
"src"
]
"psr-4": {
"IPay\\": "src/"
}
},
"authors": [
{
Expand Down
6 changes: 5 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
parameters:
ignoreErrors: []
ignoreErrors:
-
message: "#^Property IPay\\\\Builders\\\\TransactionBuilder\\:\\:\\$resolver is never written, only read\\.$#"
count: 1
path: src/Builders/TransactionBuilder.php
63 changes: 0 additions & 63 deletions src/Api/AbstractApi.php

This file was deleted.

87 changes: 0 additions & 87 deletions src/Api/AuthenticatedApi.php

This file was deleted.

43 changes: 0 additions & 43 deletions src/Api/UnauthenticatedApi.php

This file was deleted.

67 changes: 0 additions & 67 deletions src/Builder/BodyBuilder.php

This file was deleted.

58 changes: 58 additions & 0 deletions src/Builders/BodyBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace IPay\Builders;

use IPay\Encryption\Encryptor;
use Nette\Utils\Json;
use Nette\Utils\Random;

/**
* @psalm-type ValueType = string|int
* @psalm-type ParametersType = array<string, ValueType>
*/
final class BodyBuilder implements \Stringable, \JsonSerializable
{
/**
* @param ParametersType $parameters
*/
public function __construct(
private array $parameters = [],
) {
}

public function setSessionId(string $value): void
{
$this->parameters['sessionId'] = $value;
}

/**
* @param ParametersType $parameters
*/
public function build(array $parameters = []): self
{
$data = array_merge([
'lang' => 'en',
'requestId' => Random::generate(12, '0-9A-Z').'|'.time(),
], $this->parameters, $parameters);
ksort($data);
$data['signature'] = md5(http_build_query($data));

return new self($data);
}

public function encrypt(): string
{
return new self(['encrypted' => Encryptor::encrypt($this)]);
}

public function __toString(): string
{
return Json::encode($this->parameters);
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->parameters;
}
}
Loading

0 comments on commit a4b3d9c

Please sign in to comment.