Test Failed
Push — refactor-icepaypayments ( 0502bc...2c8cbf )
by Kiet
01:54
created

CompleteAuthorizeResponse::isCancelled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Omnipay\IcepayPayments\Message;
6
7
use Omnipay\Common\Message\RequestInterface;
8
9
class CompleteAuthorizeResponse extends AbstractResponse
10
{
11
    /**
12
     * The response status code.
13
     *
14
     * @var int
15
     */
16
    private $statusCode;
17
18
    public function __construct(RequestInterface $request, int $statusCode, $data)
19
    {
20
        parent::__construct($request, $data);
21
22
        $this->statusCode = $statusCode;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function isSuccessful(): bool
29
    {
30
        return $this->getTransactionStatus() === self::TRANSACTION_STATUS_COMPLETED;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function isCancelled(): bool
37
    {
38
        return $this->getTransactionStatus() === self::TRANSACTION_STATUS_CANCELLED;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getCode(): int
45
    {
46
        return $this->statusCode;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getTransactionReference(): ?string
53
    {
54
        return $this->data['id'] ?? null;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * Fallback on the postback data that was given by ICEPAY when the transaction cannot be found.
61
     * Do note: this is not a reliable way of checking the transaction status.
62
     *
63
     * @see https://documentation.icepay.com/payments/payment-process/payment-feedback/postback/
64
     */
65
    protected function getTransactionStatus(): ?string
66
    {
67
        if ($this->getCode() === 404) {
68
            return $this->request->getHttpRequest()->query->getAlpha('statusCode', null);
0 ignored issues
show
Bug introduced by
The method getHttpRequest() does not exist on Omnipay\Common\Message\RequestInterface. It seems like you code against a sub-type of Omnipay\Common\Message\RequestInterface such as Omnipay\IcepayPayments\M...ompleteAuthorizeRequest. ( Ignorable by Annotation )

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

68
            return $this->request->/** @scrutinizer ignore-call */ getHttpRequest()->query->getAlpha('statusCode', null);
Loading history...
69
        }
70
71
        return $this->data['status'] ?? null;
72
    }
73
}
74