CompletePurchaseResponse::getTransactionId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Omnipay\WindcaveHpp\Message;
4
5
use Omnipay\Common\Exception\InvalidResponseException;
6
use Omnipay\Common\Message\AbstractResponse;
7
use Omnipay\Common\Message\RequestInterface;
8
9
/**
10
 * Windcave HPP Complete Purchase Response
11
 */
12
class CompletePurchaseResponse extends AbstractResponse
13
{
14
    /**
15
     * Constructor
16
     *
17
     * @param RequestInterface $request the initiating request.
18
     * @param mixed $data
19
     *
20
     * @throws InvalidResponseException If merchant data or order number is missing, or signature does not match
21
     */
22
    public function __construct(RequestInterface $request, $data)
23
    {
24
        parent::__construct($request, $data);
25
    }
26
27
    public function isSuccessful()
28
    {
29
        $transaction = $this->getTransactionResult();
30
31
        return (
32
            $transaction &&
33
            ($transaction['authorised'] ?? false) &&
34
            ( strtoupper($transaction['responseText'] ?? '') ) === 'APPROVED'
35
        ) ?? false;
36
    }
37
38
    public function getTransactionResult()
39
    {
40
        return $this->getData()['transactions'][0] ?? [];
41
    }
42
43
    public function getTransactionId()
44
    {
45
        return $this->getTransactionResult()['merchantReference'] ?? '';
46
    }
47
48
    public function getTransactionReference()
49
    {
50
        return $this->getTransactionResult()['id'] ?? '';
51
    }
52
53
    public function getTransactionType()
54
    {
55
        return $this->getTransactionResult()['type'] ?? '';
56
    }
57
58
    public function getTransactionMethod()
59
    {
60
        return $this->getTransactionResult()['method'] ?? '';
61
    }
62
63
    public function getMessage()
64
    {
65
        return $this->getResponseText() ?? '';
66
    }
67
68
    public function getResponseText()
69
    {
70
        $transaction = $this->getTransactionResult();
71
72
        return $transaction['responseText'] ?? '';
73
    }
74
75
    public function getSessionId()
76
    {
77
        return $this->getTransactionResult()['sessionId'] ?? '';
78
    }
79
80
    public function getCard()
81
    {
82
        return $this->getTransactionResult()['card'] ?? '';
83
    }
84
85
    public function getCardNumber()
86
    {
87
        return $this->getCard()['cardNumber'] ?? '';
88
    }
89
90
    public function getCardHolderName()
91
    {
92
        return $this->getCard()['cardHolderName'] ?? '';
93
    }
94
95
    public function getCardExpiry()
96
    {
97
        return $this->getCardExpiryMonth() . '/' . $this->getCardExpiryYear();
98
    }
99
100
    public function getCardExpiryYear()
101
    {
102
        return $this->getCard()['dateExpiryYear'] ?? '';
103
    }
104
105
    public function getCardExpiryMonth()
106
    {
107
        return $this->getCard()['dateExpiryMonth'] ?? '';
108
    }
109
110
    public function getCardType()
111
    {
112
        return $this->getCard()['type'] ?? '';
113
    }
114
115
    public function getCardReference()
116
    {
117
        if ( !in_array($this->getTransactionMethod(), ['card', 'visacheckout']) ) {
118
            return null;
119
        }
120
121
        return $this->getCard()['id'] ?? null;
122
    }
123
}
124