Passed
Push — main ( 007e00...f82f47 )
by
unknown
09:50
created

CompletePurchaseResponse::__construct()   A

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 2
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
    protected function getTransactionResult()
39
    {
40
        return $this->getData()['transactions'][0] ?? [];
41
    }
42
43
    public function getTransactionId()
44
    {
45
        return $this->getTransactionResult()['merchantReference'] ?? '';
46
47
    }
48
49
    public function getTransactionReference()
50
    {
51
        return $this->getTransactionResult()['id'] ?? '';
52
    }
53
54
    public function getTransactionType()
55
    {
56
        return $this->getTransactionResult()['type'] ?? '';
57
    }
58
59
    public function getMessage()
60
    {
61
        return $this->getResponseText() ?? '';
62
    }
63
64
    public function getResponseText()
65
    {
66
        $transaction = $this->getTransactionResult();
67
68
        return $transaction['responseText'] ?? '';
69
    }
70
71
    public function getSessionId()
72
    {
73
        return $this->getTransactionResult()['sessionId'] ?? '';
74
    }
75
76
    public function getCard()
77
    {
78
        return $this->getTransactionResult()['card'] ?? '';
79
    }
80
81
    public function getCardNumber()
82
    {
83
        return $this->getCard()['cardNumber'] ?? '';
84
    }
85
86
    public function cardHolderName()
87
    {
88
        return $this->getCard()['cardHolderName'] ?? '';
89
    }
90
91
    public function getCardExpiry()
92
    {
93
        return ($this->getCard()['dateExpiryMonth'] ?? '') . '/' . ($this->getCard()['dateExpiryYear'] ?? '');
94
    }
95
96
    public function getCardType()
97
    {
98
        return $this->getCard()['type'] ?? '';
99
    }
100
}
101