GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Query::getHistory()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Netaxept API package.
5
 *
6
 * (c) Andrew Plank
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
declare(strict_types=1);
13
14
namespace FDM\Netaxept\Response;
15
16
class Query extends AbstractResponse implements QueryInterface, ErrorInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     *
21
     * @return string
22
     */
23
    public function getTransactionStatus(): string
24
    {
25
        // If the user cancelled in the terminal window, then we need to detect that.
26
        if ($this->hasError()) {
27
            $error = $this->getError();
28
            if (
29
                !empty($error['operation']) && $error['operation'] === 'Terminal' &&
30
                !empty($error['responseCode']) && $error['responseCode'] === '17' &&
31
                !empty($error['responseSource']) && ($error['responseSource'] === 'Terminal' || $error['responseSource'] === '05') &&
32
                !empty($error['responseText']) && $error['responseText'] === 'Cancelled by customer.'
33
            ) {
34
                return QueryInterface::STATUS_CANCELLED;
35
            }
36
37
            return QueryInterface::STATUS_FAILED;
38
        }
39
40
        $summary = $this->getSummary();
41
42
        // If the cancelled flag is set, then it can no longer be considered to be authed, captured or credited.
43
        if ($summary['cancelled']) {
44
            return QueryInterface::STATUS_CANCELLED;
45
        }
46
47
        // If there's an amount present in the amountCredited field, it's because it's not a request for payment.
48
        if ($summary['amountCredited']) {
49
            return QueryInterface::STATUS_CREDITED;
50
        }
51
52
        // If it's not cancelled, not credited, but is authed and not captured, then it must just be authed.
53
        if ($summary['authorized'] && !$summary['amountCaptured']) {
54
            return QueryInterface::STATUS_AUTHORIZED;
55
        }
56
57
        // If it's not cancelled, not credited, not authed, and not captured, then it's either pending, (Netaxept's
58
        // 'registered' state) or rejected.
59
        if (!$summary['authorized'] && !$summary['amountCaptured']) {
60
            return QueryInterface::STATUS_PENDING;
61
        }
62
63
        // The only other option is that it's been captured.
64
        return QueryInterface::STATUS_CAPTURED;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     *
70
     * @return array
71
     */
72
    public function getSummary(): array
73
    {
74
        return [
75
            'amountCaptured' => (int) $this->xml->Summary->AmountCaptured,
76
            'amountCredited' => (int) $this->xml->Summary->AmountCredited,
77
            'cancelled' => filter_var($this->xml->Summary->Annulled, FILTER_VALIDATE_BOOLEAN),
78
            'authorized' => filter_var($this->xml->Summary->Authorized, FILTER_VALIDATE_BOOLEAN),
79
            'authorizationId' => (string) $this->xml->Summary->AuthorizationId,
80
        ];
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     *
86
     * @return string
87
     */
88
    public function getMerchantId(): string
89
    {
90
        return (string) $this->xml->MerchantId;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     *
96
     * @return string
97
     */
98
    public function getTransactionId(): string
99
    {
100
        return (string) $this->xml->TransactionId;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     *
106
     * @return array
107
     */
108
    public function getCustomerInfo(): array
109
    {
110
        return [
111
            'email' => (string) $this->xml->CustomerInformation->Email,
112
            'phoneNumber' => (string) $this->xml->CustomerInformation->PhoneNumber,
113
            'customerNumber' => (string) $this->xml->CustomerInformation->CustomerNumber,
114
            'firstName' => (string) $this->xml->CustomerInformation->FirstName,
115
            'lastName' => (string) $this->xml->CustomerInformation->LastName,
116
            'address1' => (string) $this->xml->CustomerInformation->Address1,
117
            'address2' => (string) $this->xml->CustomerInformation->Address2,
118
            'postcode' => (string) $this->xml->CustomerInformation->Postcode,
119
            'town' => (string) $this->xml->CustomerInformation->Town,
120
            'country' => (string) $this->xml->CustomerInformation->Country,
121
            'socialSecurityNumber' => (string) $this->xml->CustomerInformation->SocialSecurityNumber,
122
            'companyName' => (string) $this->xml->CustomerInformation->CompanyName,
123
            'companyRegistrationNumber' => (string) $this->xml->CustomerInformation->CompanyRegistrationNumber,
124
        ];
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     *
130
     * @return array
131
     */
132
    public function getHistory(): array
133
    {
134
        $history = [];
135
        foreach ($this->xml->History->children() as $logEntry) {
136
            $log = [];
137
            foreach ($logEntry as $key => $val) {
138
                $log[lcfirst($key)] = (string) $val;
139
            }
140
            $history[] = $log;
141
        }
142
143
        return $history;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     *
149
     * @return array
150
     */
151
    public function getOrderInformation(): array
152
    {
153
        return [
154
            'amount' => (int) $this->xml->OrderInformation->Amount,
155
            'currency' => (string) $this->xml->OrderInformation->Currency,
156
            'orderNumber' => (string) $this->xml->OrderInformation->OrderNumber,
157
            'orderDescription' => (string) $this->xml->OrderInformation->OrderDescription,
158
            'fee' => (int) $this->xml->OrderInformation->Fee,
159
            'roundingAmount' => (int) $this->xml->OrderInformation->RoundingAmount,
160
            'total' => (int) $this->xml->OrderInformation->Total,
161
            'timestamp' => (string) $this->xml->OrderInformation->Timestamp,
162
        ];
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     *
168
     * @return int
169
     */
170
    public function getOrderTotal(): int
171
    {
172
        return (int) $this->xml->OrderInformation->Total;
173
    }
174
}
175