CompletePurchaseResponse   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 21
eloc 27
c 4
b 0
f 3
dl 0
loc 110
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A isSuccessful() 0 9 3
A getTransactionResult() 0 3 1
A getTransactionId() 0 3 1
A __construct() 0 3 1
A getTransactionReference() 0 3 1
A getTransactionType() 0 3 1
A getCardNumber() 0 3 1
A getTransactionMethod() 0 3 1
A getCardExpiryMonth() 0 3 1
A getCard() 0 3 1
A getSessionId() 0 3 1
A getResponseText() 0 5 1
A getCardHolderName() 0 3 1
A getCardExpiryYear() 0 3 1
A getCardExpiry() 0 3 1
A getCardReference() 0 7 2
A getCardType() 0 3 1
A getMessage() 0 3 1
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