PaymentResponse::getTransactionReference()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
crap 12
1
<?php
2
3
namespace Omnipay\PaypalRest\Message;
4
5
/**
6
 * @author    Ivan Kerin <[email protected]>
7
 * @copyright 2014, Clippings Ltd.
8
 * @license   http://spdx.org/licenses/BSD-3-Clause
9
 */
10
class PaymentResponse extends AbstractResponse
11
{
12
    /**
13
     * Return true if state is "approved"
14
     *
15
     * @return boolean
16
     */
17
    public function isSuccessful()
18
    {
19
        return (parent::isSuccessful()
20
            and isset($this->data['state'])
21
            and $this->data['state'] === 'approved');
22
    }
23
24
    /**
25
     * @param  integer     $index
26
     * @param  string      $type
27
     * @return string|null
28
     */
29
    public function getRelatedResourceId($index, $type)
30
    {
31
        if (isset($this->data['transactions'][0]['related_resources'][$index][$type]['id'])) {
32
            return $this->data['transactions'][0]['related_resources'][$index][$type]['id'];
33
        }
34
    }
35
36
    /**
37
     * @return string|null
38
     */
39
    public function getIntent()
40
    {
41
        if (isset($this->data['intent'])) {
42
            return $this->data['intent'];
43
        }
44
    }
45
46
    /**
47
     * @return string|null
48
     */
49
    public function getTransactionReference()
50
    {
51
        if ($this->getIntent() === 'sale') {
52
            return $this->getRelatedResourceId(0, 'sale');
53
        }
54
55
        if ($this->getIntent() === 'authorize') {
56
            return $this->getRelatedResourceId(0, 'authorization');
57
        }
58
    }
59
}
60