Skip to content

Commit 8c9e039

Browse files
committed
wip
1 parent c92f6b6 commit 8c9e039

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

src/Client.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function __construct(
3232
protected ?Environment $env = null
3333
) {
3434
$this->config()->setHost(match ($env) {
35-
$env::SANDBOX => 'https://sandbox.simplepay.hu/payment/v2',
36-
$env::SECURE => 'https://secure.simplepay.hu/payment/v2',
35+
Environment::SANDBOX => 'https://sandbox.simplepay.hu/payment/v2',
36+
Environment::SECURE => 'https://secure.simplepay.hu/payment/v2',
3737
default => 'https://secure.simplepay.hu/payment/v2'
3838
});
3939
}
@@ -71,25 +71,20 @@ public function client(): ClientInterface
7171
{
7272
$stack = HandlerStack::create();
7373

74-
$stack->push(function (callable $next): Closure {
74+
$stack->before('prepare_body', function (callable $next): Closure {
7575
return function (RequestInterface $request, array $options) use ($next): PromiseInterface {
76-
$modify = [
77-
'body' => [
78-
'merchant' => $this->merchant,
79-
'salt' => substr(str_shuffle(md5(microtime())), 0, 32),
80-
'sdkVersion' => 'Cone OTP SimplePay PHP Client:' . static::VERSION,
81-
],
82-
];
76+
$data = json_decode((string) $request->getBody(), true) ?? [];
8377

84-
return $next(Utils::modifyRequest($request, $modify), $options);
85-
};
86-
});
78+
$data = array_merge($data, [
79+
'merchant' => $this->merchant,
80+
'salt' => substr(str_shuffle(md5(microtime())), 0, 32),
81+
'sdkVersion' => 'Cone OTP SimplePay PHP Client:' . static::VERSION,
82+
]);
8783

88-
$stack->push(function (callable $next): Closure {
89-
return function (RequestInterface $request, array $options) use ($next): PromiseInterface {
9084
$modify = [
85+
'body' => Utils::streamFor($data = json_encode($data)),
9186
'set_headers' => [
92-
'Signature' => $this->sign($request->getBody()->getContents()),
87+
'Signature' => $this->sign($data),
9388
],
9489
];
9590

0 commit comments

Comments
 (0)