Response::getCode()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Empatix\OmnipaySwedbank\Messages;
4
5
use Omnipay\Common\Message\AbstractResponse;
6
use Omnipay\Common\Message\RedirectResponseInterface;
7
8
class Response extends AbstractResponse implements RedirectResponseInterface
9
{
10
    public function getTransactionReference()
11
    {
12
        if (isset($this->data['payment']['id'])) {
13
            return $this->data['payment']['id'];
14
        }
15
    }
16
17
    public function isSuccessful()
18
    {
19
        if ($this->isRedirect()) {
20
            return false;
21
        }
22
23
        if (isset($this->data['reversal']['transaction']['state'])) {
24
            return 'Completed' === $this->data['reversal']['transaction']['state'];
25
        }
26
27
        if (isset($this->data['cancellations'])) {
28
            $cancellations = $this->data['cancellations']['cancellationList'];
29
30
            return 'Completed' === $cancellations[0]['transaction']['state'];
31
        }
32
33
        if (isset($this->data['capture']['transaction']['state'])) {
34
            return 'Completed' === $this->data['capture']['transaction']['state'];
35
        }
36
37
        if (isset($this->data['payment']['state'])) {
38
            return 'Ready' === $this->data['payment']['state'];
39
        }
40
41
        return false;
42
    }
43
44
    public function isCancelled()
45
    {
46
        if (isset($this->data['payment']['state'])) {
47
            return 'Aborted' === $this->data['payment']['state'];
48
        }
49
50
        return false;
51
    }
52
53
    public function isPending()
54
    {
55
        if (isset($this->data['payment']['state'])) {
56
            return 'Pending' === $this->data['payment']['state'];
57
        }
58
59
        return false;
60
    }
61
62
    public function isRedirect()
63
    {
64
        return $this->getRedirectUrl() ? true : false;
65
    }
66
67
    public function getRedirectUrl()
68
    {
69
        return $this->getRedirectAuthorizationUrl();
70
    }
71
72
    public function getRedirectAuthorizationUrl()
73
    {
74
        if (isset($this->data['operations'])) {
75
            foreach (($this->data['operations']) as $operation) {
76
                if ($operation['rel'] == 'redirect-authorization') {
77
                    return $operation['href'];
78
                }
79
            }
80
        }
81
    }
82
83
    public function getMessage()
84
    {
85
        if (isset($this->data['status']) && isset($this->data['type'])) {
86
            return $this->data['title'];
87
        }
88
89
        return null;
90
    }
91
92
    public function getCode()
93
    {
94
        if (isset($this->data['status']) && isset($this->data['type'])) {
95
            return $this->data['status'];
96
        }
97
98
        return null;
99
    }
100
}
101