Passed
Push — master ( 1afe3e...d4d981 )
by
unknown
08:48
created

Response::isCancelled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
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 (isset($this->data['reversal']['transaction']['state'])) {
20
            return 'Completed' === $this->data['reversal']['transaction']['state'];
21
        }
22
23
        if (isset($this->data['cancellations'])) {
24
            $cancellations = $this->data['cancellations']['cancellationList'];
25
26
            return 'Completed' === $cancellations[0]['transaction']['state'];
27
        }
28
29
        if (isset($this->data['capture']['transaction']['state'])) {
30
            return 'Completed' === $this->data['capture']['transaction']['state'];
31
        }
32
33
        if (isset($this->data['payment']['state'])) {
34
            return 'Ready' === $this->data['payment']['state'];
35
        }
36
37
        return false;
38
    }
39
40
    public function isCancelled()
41
    {
42
        if (isset($this->data['payment']['state'])) {
43
            return 'Aborted' === $this->data['payment']['state'];
44
        }
45
46
        return false;
47
    }
48
49
    public function isPending()
50
    {
51
        if (isset($this->data['payment']['state'])) {
52
            return 'Pending' === $this->data['payment']['state'];
53
        }
54
55
        return false;
56
    }
57
58
    public function isRedirect()
59
    {
60
        return $this->getRedirectUrl() ? true : false;
61
    }
62
63
    public function getRedirectUrl()
64
    {
65
        return $this->getRedirectAuthorizationUrl();
66
    }
67
68
    public function getRedirectAuthorizationUrl()
69
    {
70
        if (isset($this->data['operations'])) {
71
            foreach (($this->data['operations']) as $operation) {
72
                if ($operation['rel'] == 'redirect-authorization') {
73
                    return $operation['href'];
74
                }
75
            }
76
        }
77
    }
78
79
    public function getMessage()
80
    {
81
        if (isset($this->data['status']) && isset($this->data['type'])) {
82
            return $this->data['title'];
83
        }
84
85
        return null;
86
    }
87
88
    public function getCode()
89
    {
90
        if (isset($this->data['status']) && isset($this->data['type'])) {
91
            return $this->data['status'];
92
        }
93
94
        return null;
95
    }
96
}
97