AbstractResponse::getRedirectUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * w-vision
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the MIT License
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that are distributed with this source code.
10
 *
11
 * @copyright  Copyright (c) 2016 Woche-Pass AG (http://www.w-vision.ch)
12
 * @license    MIT License
13
 */
14
15
namespace Omnipay\Datatrans\Message;
16
17
use Omnipay\Common\Message\AbstractResponse as OmnipayAbstractResponse;
18
use Omnipay\Common\Message\RedirectResponseInterface;
19
20
/**
21
 * Datatrans purchase redirect response
22
 */
23
abstract class AbstractResponse extends OmnipayAbstractResponse implements RedirectResponseInterface
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $productionEndpoint = 'https://pay.datatrans.com/upp/jsp/upStart.jsp';
29
30
    /**
31
     * @var string
32
     */
33
    protected $testEndpoint = 'https://pay.sandbox.datatrans.com/upp/jsp/upStart.jsp';
34
35
    /*** STATUS CODES ****/
36
    /**
37
     * success code in response
38
     */
39
    const DATATRANS_SUCCESS = '01';
40
41
    /**
42
     * error code in response
43
     */
44
    const DATATRANS_ERROR = '02';
45
46
    /**** ALIAS ERRORS ****/
47
48
    /**
49
     * CC alias update error
50
     */
51
    const DATATRANS_ALIAS_UPDATE_ERROR = '-885';
52
53
    /**
54
     * CC alias insert error
55
     */
56
    const DATATRANS_ALIAS_INSERT_ERROR = '-886';
57
58
    /**
59
     * CC alias does not match with cardno
60
     */
61
    const DATATRANS_ALIAS_CARD_NO = '-887';
62
63
    /**
64
     * CC alias not found
65
     */
66
    const DATATRANS_ALIAS_NOT_FOUND = '-888';
67
68
    /**
69
     * CC alias error / input parameters missing
70
     */
71
    const DATATRANS_ALIAS_ERROR = '-889';
72
73
    /**
74
     * CC alias service is not supported
75
     */
76
    const DATATRANS_ALIAS_SERVICE_NOT_SUPPORTED = '-900';
77
78
    /**
79
     * generel error
80
     */
81
    const DATATRANS_ALIAS_GENEREL_ERROR = '-999';
82
83
    /**
84
     * @return bool
85
     */
86 1
    public function isRedirect()
87
    {
88 1
        return true;
89
    }
90
91
    /**
92
     * @return bool
93
     */
94 1
    public function isSuccessful()
95
    {
96 1
        return false;
97
    }
98
99
    /**
100
     * Gets the redirect target url.
101
     */
102 1
    public function getRedirectUrl()
103
    {
104 1
        return $this->getCheckoutEndpoint();
105
    }
106
107
    /**
108
     * Get the required redirect method (either GET or POST).
109
     */
110 1
    public function getRedirectMethod()
111
    {
112 1
        return 'POST';
113
    }
114
115
    /**
116
     * Gets the redirect form data array, if the redirect method is POST.
117
     */
118 1
    public function getRedirectData()
119
    {
120
        // Build the post data as expected by Datatrans.
121 1
        $params = $this->getData();
122 1
        $getData = array();
123 1
        foreach ($params as $key => $value) {
124 1
            $getData[$key] = $value;
125 1
        }
126
127 1
        return $getData;
128
    }
129
130
    /**
131
     * @return string
132
     */
133 1
    protected function getCheckoutEndpoint()
134
    {
135 1
        $req = $this->getRequest();
136
137 1
        if ($req->getTestMode()) {
138 1
            return $this->testEndpoint;
139
        }
140
141
        return $this->productionEndpoint;
142
    }
143
144
    /**
145
     * @return string
146
     */
147 1
    public function getMessage()
148
    {
149 1
        if (!$this->isSuccessful()) {
150
            return $this->data['responseMessage'];
151
        }
152
153 1
        return '';
154
    }
155
156
    /**
157
     * @return string
158
     */
159 1
    public function getTransactionReference()
160
    {
161 1
        return isset($this->data['refno']) ? $this->data['refno'] : '';
162
    }
163
164
    /**
165
     * @return mixed
166
     */
167 3
    public function getStatus()
168
    {
169 3
        return $this->data['status'];
170
    }
171
172
    /**
173
     * @return mixed
174
     */
175
    public function getCode()
176
    {
177
        return $this->data['code'];
178
    }
179
}
180