1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Pixidos package. |
5
|
|
|
* |
6
|
|
|
* (c) Ondra Votava <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace Pixidos\GPWebPay\Factory; |
16
|
|
|
|
17
|
|
|
use Pixidos\GPWebPay\Config\PaymentConfigProvider; |
18
|
|
|
use Pixidos\GPWebPay\Data\OperationInterface; |
19
|
|
|
use Pixidos\GPWebPay\Data\Request; |
20
|
|
|
use Pixidos\GPWebPay\Enum\Param; |
21
|
|
|
use Pixidos\GPWebPay\Exceptions\InvalidArgumentException; |
22
|
|
|
use Pixidos\GPWebPay\Exceptions\LogicException; |
23
|
|
|
use Pixidos\GPWebPay\Exceptions\SignerException; |
24
|
|
|
use Pixidos\GPWebPay\Param\Digest; |
25
|
|
|
use Pixidos\GPWebPay\Signer\SignerProviderInterface; |
26
|
|
|
use UnexpectedValueException; |
27
|
|
|
|
28
|
|
|
class RequestFactory |
29
|
|
|
{ |
30
|
8 |
|
public function __construct( |
31
|
|
|
private readonly PaymentConfigProvider $config, |
32
|
|
|
private readonly SignerProviderInterface $signerProvider |
33
|
|
|
) { |
34
|
8 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @throws InvalidArgumentException |
38
|
|
|
* @throws SignerException |
39
|
|
|
* @throws UnexpectedValueException |
40
|
|
|
*/ |
41
|
8 |
|
public function create(OperationInterface $operation): Request |
42
|
|
|
{ |
43
|
8 |
|
$key = $this->config->getGateway($operation->getGateway()); |
44
|
8 |
|
if (null === $operation->getParam(Param::RESPONSE_URL())) { |
45
|
6 |
|
$responseUrl = $this->config->getResponseUrl(); |
46
|
6 |
|
if (null === $responseUrl) { |
47
|
1 |
|
throw new LogicException('You are forgot setup response url'); |
48
|
|
|
} |
49
|
5 |
|
$operation->addParam($responseUrl); |
50
|
|
|
} |
51
|
7 |
|
$request = new Request( |
52
|
7 |
|
$operation, |
53
|
7 |
|
$this->config->getMerchantNumber($key), |
54
|
7 |
|
$this->config->getDepositFlag($key), |
55
|
7 |
|
$this->config->getUrl($key) |
56
|
7 |
|
); |
57
|
|
|
|
58
|
7 |
|
$signer = $this->signerProvider->get($key); |
59
|
7 |
|
$digestParams = $request->getDigestParams(); |
60
|
7 |
|
$request->setParam(new Digest($signer->sign($digestParams))); |
61
|
7 |
|
$request->sortParams(); |
62
|
|
|
|
63
|
7 |
|
return $request; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|