|
1
|
|
|
<?php |
|
2
|
|
|
namespace Paranoia\Builder\Gvp; |
|
3
|
|
|
|
|
4
|
|
|
use Paranoia\Common\Serializer\Serializer; |
|
5
|
|
|
use Paranoia\Configuration\Gvp; |
|
6
|
|
|
use Paranoia\Request\Request; |
|
7
|
|
|
|
|
8
|
|
|
class PreAuthorizationRequestBuilder extends BaseRequestBuilder |
|
9
|
|
|
{ |
|
10
|
|
|
const TRANSACTION_TYPE = 'preauth'; |
|
11
|
|
|
const ENVELOPE_NAME = 'GVPSRequest'; |
|
12
|
|
|
|
|
13
|
|
|
public function build(Request $request) |
|
14
|
|
|
{ |
|
15
|
|
|
$data = array_merge( |
|
16
|
|
|
$this->buildBaseRequest($request), |
|
17
|
|
|
['Card' => $this->buildCard($request->getResource())] |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
$serializer = new Serializer(Serializer::XML); |
|
21
|
|
|
return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function buildTransaction(Request $request) |
|
25
|
|
|
{ |
|
26
|
|
|
return [ |
|
27
|
|
|
'Type' => self::TRANSACTION_TYPE, |
|
28
|
|
|
'Amount' => $this->amountFormatter->format($request->getAmount()), |
|
29
|
|
|
'CurrencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), |
|
30
|
|
|
|
|
31
|
|
|
#TODO: Will be changed after 3D integration |
|
32
|
|
|
'CardholderPresentCode' => self::CARD_HOLDER_PRESENT_CODE_NON_3D, |
|
33
|
|
|
|
|
34
|
|
|
'MotoInd' => 'N', |
|
35
|
|
|
'OriginalRetrefNum' => null, |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function getCredentialPair() |
|
40
|
|
|
{ |
|
41
|
|
|
/** @var Gvp $configuration */ |
|
42
|
|
|
$configuration = $this->configuration; |
|
43
|
|
|
return [$configuration->getAuthorizationUsername(), $configuration->getAuthorizationPassword()]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function buildHash(Request $request, $password) |
|
47
|
|
|
{ |
|
48
|
|
|
/** @var Gvp $configuration */ |
|
49
|
|
|
$configuration = $this->configuration; |
|
50
|
|
|
return strtoupper( |
|
51
|
|
|
sha1( |
|
52
|
|
|
sprintf( |
|
53
|
|
|
'%s%s%s%s%s', |
|
54
|
|
|
$request->getOrderId(), |
|
55
|
|
|
$configuration->getTerminalId(), |
|
56
|
|
|
$request->getResource()->getNumber(), |
|
|
|
|
|
|
57
|
|
|
$this->amountFormatter->format($request->getAmount()), |
|
58
|
|
|
$this->generateSecurityHash($password) |
|
59
|
|
|
) |
|
60
|
|
|
) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|