FetchTransactionResponse   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 58
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isSuccessful() 0 7 3
A isPending() 0 7 3
A getCode() 0 3 1
A getMessage() 0 3 1
A getTransactionReference() 0 3 1
1
<?php
2
3
namespace Omnipay\Worldline\Message;
4
5
use Omnipay\Common\Message\AbstractResponse;
6
7
/**
8
 * Worldline Fetch Transaction Response
9
 */
10
class FetchTransactionResponse extends AbstractResponse
11
{
12
    /**
13
     * Is the response pending success or failure?
14
     *
15
     * @return boolean
16
     */
17
    public function isPending()
18
    {
19
        if (empty($this->data) || isset($this->data->errorId)) {
20
            return false;
21
        }
22
23
        return $this->data->statusOutput->statusCategory == 'PENDING_CONNECT_OR_3RD_PARTY';
24
    }
25
26
    /**
27
     * Is the response successful?
28
     *
29
     * @return boolean
30
     */
31
    public function isSuccessful()
32
    {
33
        if (empty($this->data) || isset($this->data->errorId)) {
34
            return false;
35
        }
36
37
        return in_array($this->data->statusOutput->statusCategory, ['COMPLETED', 'REFUNDED']);
38
    }
39
40
    /**
41
     * Numeric status code (also in back office / report files)
42
     *
43
     * @return null|string
44
     */
45
    public function getCode()
46
    {
47
        return $this->data->statusOutput->statusCode ?? $this->data->errors[0]->errorCode ?? null;
48
    }
49
50
    /**
51
     * Get the authorisation code if available.
52
     *
53
     * @return null|string
54
     */
55
    public function getTransactionReference()
56
    {
57
        return $this->data->id ?? null;
58
    }
59
60
    /**
61
     * Get the merchant response message if available.
62
     *
63
     * @return null|string
64
     */
65
    public function getMessage()
66
    {
67
        return $this->data->status ?? $this->data->errorId ?? null;
68
    }
69
}
70