CompletePurchaseResponse::getTransactionId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
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
     * Constructor
15
     *
16
     * @param RequestInterface $request the initiating request.
17
     * @param mixed $data
18
     *
19
     * @throws InvalidResponseException If merchant data or order number is missing, or signature does not match
20
     */
21
    public function __construct(RequestInterface $request, $data) {
22
        parent::__construct($request, $data);
23
    }
24
25
    public function isSuccessful() {
26
        $transaction = $this->getTransactionResult();
27
28
        return (
29
            $transaction &&
30
            ($transaction['authorised'] ?? false) &&
31
            (strtoupper($transaction['responseText'] ?? '')) === 'APPROVED'
32
        ) ?? false;
33
    }
34
35
    protected function getTransactionResult() {
36
        return $this->getData()['transactions'][0] ?? [];
37
    }
38
39
    public function getTransactionId() {
40
        return $this->getTransactionResult()['merchantReference'] ?? '';
41
    }
42
43
    public function getTransactionReference() {
44
        return $this->getTransactionResult()['id'] ?? '';
45
    }
46
47
    public function getTransactionType() {
48
        return $this->getTransactionResult()['type'] ?? '';
49
    }
50
51
    public function getMessage() {
52
        return $this->getResponseText() ?? '';
53
    }
54
55
    public function getResponseText() {
56
        $transaction = $this->getTransactionResult();
57
58
        return $transaction['responseText'] ?? '';
59
    }
60
61
    public function getSessionId() {
62
        return $this->getTransactionResult()['sessionId'] ?? '';
63
    }
64
65
    public function getCard() {
66
        return $this->getTransactionResult()['card'] ?? '';
67
    }
68
69
    public function getCardNumber() {
70
        return $this->getCard()['cardNumber'] ?? '';
71
    }
72
73
    public function cardHolderName() {
74
        return $this->getCard()['cardHolderName'] ?? '';
75
    }
76
77
    public function getCardExpiry() {
78
        return ($this->getCard()['dateExpiryMonth'] ?? '') . '/' . ($this->getCard()['dateExpiryYear'] ?? '');
79
    }
80
81
    public function getCardType() {
82
        return $this->getCard()['type'] ?? '';
83
    }
84
}
85