PreAuthorizationRequestBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 27
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 9 1
A getCredentialPair() 0 5 1
A buildTransaction() 0 12 1
A buildHash() 0 13 1
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(),
0 ignored issues
show
Bug introduced by
The method getNumber() does not exist on Paranoia\Request\Resource\ResourceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Paranoia\Request\Resource\ResourceInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
                    $request->getResource()->/** @scrutinizer ignore-call */ getNumber(),
Loading history...
57
                    $this->amountFormatter->format($request->getAmount()),
58
                    $this->generateSecurityHash($password)
59
                )
60
            )
61
        );
62
    }
63
}
64