Passed
Pull Request — main (#1)
by Leith
01:50
created

RefundResponse::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Omnipay\Worldline\Message;
4
5
use Omnipay\Common\Message\AbstractResponse;
6
7
/**
8
 * Worldline Refund Response
9
 */
10
class RefundResponse extends AbstractResponse
11
{
12
    /**
13
     * Is the response successful?
14
     *
15
     * @return boolean
16
     */
17
    public function isSuccessful()
18
    {
19
        if (empty($this->data)) {
20
            return false;
21
        }
22
23
        return !isset($this->data->errorId) && $this->data->status == 'REFUNDED';
24
    }
25
26
    /**
27
     * Numeric status code (also in back office / report files)
28
     *
29
     * @return null|string
30
     */
31
    public function getCode()
32
    {
33
        return $this->data->statusOutput->statusCode
34
            ?? $this->data->refundResult->statusOutput->statusCode
35
            ?? $this->data->errors[0]->errorCode
36
            ?? null;
37
    }
38
39
    /**
40
     * Get the authorisation code if available.
41
     *
42
     * @return null|string
43
     */
44
    public function getTransactionReference()
45
    {
46
        return $this->data->id ?? null;
47
    }
48
49
    /**
50
     * Get the merchant response message if available.
51
     *
52
     * @return null|string
53
     */
54
    public function getMessage()
55
    {
56
        return $this->data->status ?? $this->data->errorId ?? null;
57
    }
58
}
59