Skip to content

Commit 3d609ef

Browse files
authored
Merge branch 'master' into typos
2 parents 92266dc + c92f6b6 commit 3d609ef

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

src/Client.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
namespace Cone\SimplePay;
44

5+
use Closure;
56
use Cone\SimplePay\Api\TransactionApi;
67
use GuzzleHttp\Client as Http;
78
use GuzzleHttp\ClientInterface;
89
use GuzzleHttp\HandlerStack;
10+
use GuzzleHttp\Promise\PromiseInterface;
11+
use GuzzleHttp\Psr7\Utils;
12+
use Psr\Http\Message\RequestInterface;
913

1014
class Client
1115
{
@@ -67,14 +71,35 @@ public function client(): ClientInterface
6771
{
6872
$stack = HandlerStack::create();
6973

70-
// Signature Header middleware
71-
// Form data middleware
74+
$stack->push(function (callable $next): Closure {
75+
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+
];
7283

73-
$client = new Http([
84+
return $next(Utils::modifyRequest($request, $modify), $options);
85+
};
86+
});
87+
88+
$stack->push(function (callable $next): Closure {
89+
return function (RequestInterface $request, array $options) use ($next): PromiseInterface {
90+
$modify = [
91+
'set_headers' => [
92+
'Signature' => $this->sign($request->getBody()->getContents()),
93+
],
94+
];
95+
96+
return $next(Utils::modifyRequest($request, $modify), $options);
97+
};
98+
});
99+
100+
return new Http([
74101
'handler' => $stack,
75102
]);
76-
77-
return $client;
78103
}
79104

80105
/**

0 commit comments

Comments
 (0)