Issues (8)

src/Builder/Gvp/SaleRequestBuilder.php (1 issue)

Labels
Severity
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 SaleRequestBuilder extends BaseRequestBuilder
9
{
10
    const TRANSACTION_TYPE = 'sales';
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
            'InstallmentCnt'        => $this->installmentFormatter->format($request->getInstallment()),
29
            'Amount'                => $this->amountFormatter->format($request->getAmount()),
30
            'CurrencyCode'          => $this->currencyCodeFormatter->format($request->getCurrency()),
31
32
            #TODO: Will be changed after 3D integration
33
            'CardholderPresentCode' => self::CARD_HOLDER_PRESENT_CODE_NON_3D,
34
35
            'MotoInd'               => 'N',
36
            'OriginalRetrefNum'     => null,
37
        ];
38
    }
39
40
    protected function getCredentialPair()
41
    {
42
        /** @var Gvp $configuration */
43
        $configuration = $this->configuration;
44
        return [$configuration->getAuthorizationUsername(), $configuration->getAuthorizationPassword()];
45
    }
46
47
    protected function buildHash(Request $request, $password)
48
    {
49
        /** @var Gvp $configuration */
50
        $configuration = $this->configuration;
51
        return strtoupper(
52
            sha1(
53
                sprintf(
54
                    '%s%s%s%s%s',
55
                    $request->getOrderId(),
56
                    $configuration->getTerminalId(),
57
                    $request->getResource()->getNumber(),
0 ignored issues
show
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

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