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.

CreditCardAuthReply::getIsAuthAcceptable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
namespace eBayEnterprise\RetailOrderManagement\Payload\Payment;
17
18
use eBayEnterprise\RetailOrderManagement\Payload\IPayload;
19
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap;
20
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator;
21
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator;
22
use eBayEnterprise\RetailOrderManagement\Payload\TTopLevelPayload;
23
use Psr\Log\LoggerInterface;
24
use Psr\Log\NullLogger;
25
26
/**
27
 * Class CreditCardAuthReply
28
 * @package eBayEnterprise\RetailOrderManagement\Payload\Payment
29
 */
30
class CreditCardAuthReply implements ICreditCardAuthReply
31
{
32
    use TTopLevelPayload, TPaymentContext;
33
34
    /** @var string */
35
    protected $authorizationResponseCode;
36
    /** @var string */
37
    protected $bankAuthorizationCode;
38
    /** @var string */
39
    protected $cvv2ResponseCode;
40
    /** @var string */
41
    protected $avsResponseCode;
42
    /** @var string */
43
    protected $phoneResponseCode;
44
    /** @var string */
45
    protected $nameResponseCode;
46
    /** @var string */
47
    protected $emailResponseCode;
48
    /** @var float */
49
    protected $amountAuthorized;
50
    /** @var string */
51
    protected $currencyCode;
52
    /** @var array Mapping of reply authorization response code to OMS response code */
53
    protected $responseCodeMap = [
54
        self::AUTHORIZATION_APPROVED => self::APPROVED_RESPONSE_CODE,
55
        self::AUTHORIZATION_TIMEOUT_PAYMENT_PROVIDER => self::TIMEOUT_RESPONSE_CODE,
56
        self::AUTHORIZATION_TIMEOUT_CARD_PROCESSOR => self::TIMEOUT_RESPONSE_CODE,
57
    ];
58
    /** @var string[] AVS response codes that should be rejected */
59
    protected $invalidAvsCodes = ['N', 'AW'];
60
    /** @var string[] CVV response codes that should be rejected */
61
    protected $invalidCvvCodes = ['N'];
62
63
    /**
64
     * @param IValidatorIterator
65
     * @param ISchemaValidator
66
     * @param IPayloadMap
67
     * @param LoggerInterface
68
     * @param IPayload
69
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
70
     */
71 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
        IValidatorIterator $validators,
73
        ISchemaValidator $schemaValidator,
74
        IPayloadMap $payloadMap,
0 ignored issues
show
Unused Code introduced by
The parameter $payloadMap is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
        LoggerInterface $logger,
76
        IPayload $parentPayload = null
77
    ) {
78
        $this->logger = $logger;
0 ignored issues
show
Documentation Bug introduced by
It seems like $logger of type object<Psr\Log\LoggerInterface> is incompatible with the declared type object<eBayEnterprise\Re...ayload\LoggerInterface> of property $logger.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
79
        $this->validators = $validators;
80
        $this->schemaValidator = $schemaValidator;
81
        $this->parentPayload = $parentPayload;
82
83
        $this->extractionPaths = [
84
            'orderId' => 'string(x:PaymentContext/x:OrderId)',
85
            'cardNumber' =>
86
                'string(x:PaymentContext/x:EncryptedPaymentAccountUniqueId|x:PaymentContext/x:PaymentAccountUniqueId)',
87
            'authorizationResponseCode' => 'string(x:AuthorizationResponseCode)',
88
            'bankAuthorizationCode' => 'string(x:BankAuthorizationCode)',
89
            'cvv2ResponseCode' => 'string(x:CVV2ResponseCode)',
90
            'avsResponseCode' => 'string(x:AVSResponseCode)',
91
            'amountAuthorized' => 'number(x:AmountAuthorized)',
92
            'currencyCode' => 'string(x:AmountAuthorized/@currencyCode)',
93
            'isEncrypted' => 'boolean(x:PaymentContext/x:EncryptedPaymentAccountUniqueId)',
94
        ];
95
        $this->booleanExtractionPaths = [
96
            'panIsToken' => 'string(x:PaymentContext/x:PaymentAccountUniqueId/@isToken)'
97
        ];
98
        $this->optionalExtractionPaths = [
99
            'phoneResponseCode' => 'x:PhoneResponseCode',
100
            'nameResponseCode' => 'x:NameResponseCode',
101
            'emailResponseCode' => 'x:EmailResponseCode',
102
        ];
103
    }
104
105
    public function getIsAVSCorrectionRequired()
106
    {
107
        return $this->getIsAuthApproved() && !$this->getIsAVSSuccessful();
108
    }
109
110
    public function getIsAuthApproved()
111
    {
112
        return $this->getAuthorizationResponseCode() === self::AUTHORIZATION_APPROVED;
113
    }
114
115
    public function getAuthorizationResponseCode()
116
    {
117
        return $this->authorizationResponseCode;
118
    }
119
120
    public function getIsAVSSuccessful()
121
    {
122
        return !in_array($this->getAVSResponseCode(), $this->invalidAvsCodes);
123
    }
124
125
    public function getAVSResponseCode()
126
    {
127
        return $this->avsResponseCode;
128
    }
129
130
    public function getIsCVV2CorrectionRequired()
131
    {
132
        return $this->getIsAuthApproved() && !$this->getIsCVV2Successful();
133
    }
134
135
    public function getIsCVV2Successful($value = '')
136
    {
137
        return !in_array($this->getCVV2ResponseCode(), $this->invalidCvvCodes);
138
    }
139
140
    public function getCVV2ResponseCode()
141
    {
142
        return $this->cvv2ResponseCode;
143
    }
144
145
    public function getIsAuthSuccessful()
146
    {
147
        return ($this->getIsAuthApproved() && $this->getIsAVSSuccessful() && $this->getIsCVV2Successful())
148
        || ($this->getIsAuthTimeout());
149
    }
150
151
    public function getIsAuthTimeout()
152
    {
153
        $responseCode = $this->getAuthorizationResponseCode();
154
        return $responseCode === self::AUTHORIZATION_TIMEOUT_PAYMENT_PROVIDER
155
        || $responseCode === self::AUTHORIZATION_TIMEOUT_CARD_PROCESSOR;
156
    }
157
158
    public function getIsAuthAcceptable()
159
    {
160
        // If there is a response code acceptable by the OMS self::getResponseCode
161
        // doesn't return null, then the reply is acceptable
162
        return !is_null($this->getResponseCode());
163
    }
164
165
    public function getResponseCode()
166
    {
167
        $responseCode = $this->getAuthorizationResponseCode();
168
        return isset($this->responseCodeMap[$responseCode]) ? $this->responseCodeMap[$responseCode] : null;
169
    }
170
171
    /**
172
     * Serialize the various parts of the payload into XML strings and
173
     * simply concatenate them together.
174
     * @return string
175
     */
176
    protected function serializeContents()
177
    {
178
        return $this->serializePaymentContext()
179
        . $this->serializeResponseCodes()
180
        . $this->serializeAdditionalResponseCodes()
181
        . $this->serializeAmount();
182
    }
183
184
    /**
185
     * Create an XML string representing the various response codes, e.g.
186
     * AuthorizationResponseCode, BankAuthorizationCode, CVV2ResponseCode, etc.
187
     * @return string
188
     */
189
    protected function serializeResponseCodes()
190
    {
191
        $template = '<AuthorizationResponseCode>%s</AuthorizationResponseCode>'
192
            . '<BankAuthorizationCode>%s</BankAuthorizationCode>'
193
            . '<CVV2ResponseCode>%s</CVV2ResponseCode>'
194
            . '<AVSResponseCode>%s</AVSResponseCode>';
195
        return sprintf(
196
            $template,
197
            $this->xmlEncode($this->getAuthorizationResponseCode()),
198
            $this->xmlEncode($this->getBankAuthorizationCode()),
199
            $this->xmlEncode($this->getCVV2ResponseCode()),
200
            $this->xmlEncode($this->getAVSResponseCode())
201
        );
202
    }
203
204
    public function getBankAuthorizationCode()
205
    {
206
        return $this->bankAuthorizationCode;
207
    }
208
209
    /**
210
     * Create an XML string representing any of the optional response codes,
211
     * e.g. EmailResponseCode, PhoneResponseCode, etc.
212
     * @return string
213
     */
214
    protected function serializeAdditionalResponseCodes()
215
    {
216
        $phoneResponseCode = $this->xmlEncode($this->getPhoneResponseCode());
217
        $nameResponseCode = $this->xmlEncode($this->getNameResponseCode());
218
        $emailResponseCode = $this->xmlEncode($this->getEmailResponseCode());
219
        return ($phoneResponseCode ? "<PhoneResponseCode>{$phoneResponseCode}</PhoneResponseCode>" : '')
220
        . ($nameResponseCode ? "<NameResponseCode>{$nameResponseCode}</NameResponseCode>" : '')
221
        . ($emailResponseCode ? "<EmailResponseCode>{$emailResponseCode}</EmailResponseCode>" : '');
222
    }
223
224
    public function getPhoneResponseCode()
225
    {
226
        return $this->phoneResponseCode;
227
    }
228
229
    public function getNameResponseCode()
230
    {
231
        return $this->nameResponseCode;
232
    }
233
234
    public function getEmailResponseCode()
235
    {
236
        return $this->emailResponseCode;
237
    }
238
239
    /**
240
     * Create an XML string representing the amount authorized.
241
     * @return string
242
     */
243
    protected function serializeAmount()
244
    {
245
        return sprintf(
246
            '<AmountAuthorized currencyCode="%s">%01.2F</AmountAuthorized>',
247
            $this->xmlEncode($this->getCurrencyCode()),
248
            $this->getAmountAuthorized()
249
        );
250
    }
251
252
    public function getCurrencyCode()
253
    {
254
        return $this->currencyCode;
255
    }
256
257
    public function getAmountAuthorized()
258
    {
259
        return $this->amountAuthorized;
260
    }
261
262
    protected function getSchemaFile()
263
    {
264
        return $this->getSchemaDir() . self::XSD;
265
    }
266
267
    /**
268
     * Return the name of the xml root node.
269
     *
270
     * @return string
271
     */
272
    protected function getRootNodeName()
273
    {
274
        return static::ROOT_NODE;
275
    }
276
277
    /**
278
     * The XML namespace for the payload.
279
     *
280
     * @return string
281
     */
282
    protected function getXmlNamespace()
283
    {
284
        return static::XML_NS;
285
    }
286
}
287