Test Failed
Push — 3ds-authentication ( 8aad35 )
by Kiet
09:46
created

CreateTransactionRequest::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 1
eloc 43
nc 1
nop 0
dl 0
loc 57
ccs 0
cts 31
cp 0
crap 2
rs 9.232
c 4
b 0
f 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Omnipay\IcepayPayments\Message;
4
5
use Omnipay\Common\Message\ResponseInterface;
6
use Symfony\Component\HttpFoundation\Request;
7
8
/**
9
 * The request for creating a transaction at Icepay.
10
 */
11
class CreateTransactionRequest extends AbstractRequest
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function getData(): array
17
    {
18
        $parentData = parent::getData();
19
20
        $data = [
21
            'Contract' => [
22
                'ContractProfileId' => $this->getContractProfileId(),
23
                'AmountInCents' => $this->getAmountInteger(),
24
                'CurrencyCode' => $this->getCurrencyCode(),
25
                'Reference' => $this->getTransactionId(),
26
            ],
27
            'Postback' => [
28
                'UrlCompleted' => $this->getReturnUrl(),
29
                'UrlError' => $this->getCancelUrl(),
30
                'UrlsNotify' => [
31
                    $this->getNotifyUrl(),
32
                ],
33
            ],
34
            'IntegratorFootprint' => [
35
                'IPAddress' => '127.0.0.1',
36
                'TimeStampUTC' => '0',
37
            ],
38
            'ConsumerFootprint' => [
39
                'IPAddress' => '127.0.0.1',
40
                'TimeStampUTC' => '0',
41
            ],
42
            'Fulfillment' => [
43
                'PaymentMethod' => $this->getPaymentMethod(),
44
                'IssuerCode' => $this->getIssuerCode(),
45
                'AmountInCents' => $this->getAmountInteger(),
46
                'CurrencyCode' => $this->getCurrencyCode(),
47
                'Timestamp' => $this->getTimestamp()->format(self::TIMESTAMP_FORMAT),
48
                'LanguageCode' => $this->getLanguageCode(),
49
                'CountryCode' => $this->getCountryCode(),
50
                'Reference' => $this->getTransactionId(),
51
                'Consumer' => [
52
                    'Address' => [
53
                        'Street' => $this->getAddressStreet(),
54
                        'HouseNumber' => $this->getAddressHouseNumber(),
55
                        'PostalCode' => $this->getAddressPostalCode(),
56
                        'City' => $this->getAddressCity(),
57
                        'CountryCode' => $this->getCountryCode(),
58
                    ],
59
                    'Phone' => $this->getPhoneNumber(),
60
                    'Email' => $this->getEmailAddress(),
61
                ],
62
                'Order' => [
63
                    'OrderNumber' => $this->getReference(),
64
                    'CurrencyCode' => $this->getCurrencyCode(),
65
                    'TotalGrossAmountCents' => $this->getAmountInteger(),
66
                    'TotalNetAmountCents' => $this->getAmountInteger(),
67
                ],
68
                'Description' => $this->getDescription(),
69
            ],
70
        ];
71
72
        return array_merge($parentData, $data);
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 1
    public function sendData($data): ResponseInterface
79
    {
80 1
        $this->sendRequest(
81 1
            Request::METHOD_POST,
82 1
            '/contract/transaction',
83 1
            $data
84
        );
85
86 1
        return new CreateTransactionResponse(
87 1
            $this,
88 1
            $this->getResponseBody()
89
        );
90
    }
91
}
92