Passed
Pull Request — master (#20)
by Kiet
02:29
created

getTransactionReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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 2
cts 2
cp 1
crap 1
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 7
    public function __construct(RequestInterface $request, int $statusCode, $data)
19
    {
20 7
        parent::__construct($request, $data);
21
22 7
        $this->statusCode = $statusCode;
23 7
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function isSuccessful(): bool
29
    {
30 1
        return $this->getTransactionStatus() === self::TRANSACTION_STATUS_COMPLETED;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 3
    public function isCancelled(): bool
37
    {
38 3
        return $this->getTransactionStatus() === self::TRANSACTION_STATUS_CANCELLED;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 5
    public function getCode(): int
45
    {
46 5
        return $this->statusCode;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function getTransactionReference(): ?string
53
    {
54 1
        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 4
    protected function getTransactionStatus(): ?string
66
    {
67 4
        if ($this->getCode() === 404) {
68 1
            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\Message\AbstractRequest. ( 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 3
        return $this->data['status'] ?? null;
72
    }
73
}
74