AbstractRedirectRequest::sendData()   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 1
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\ResponseInterface;
18
19
abstract class AbstractRedirectRequest extends AbstractRequest
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $optionalParams = array(
25
26
    );
27
28
    /**
29
     * @return array
30
     */
31 2
    public function getData()
32
    {
33 2
        $this->validate('merchantId', 'transactionId', 'sign');
34
35
        $data = array(
36 2
            'merchantId' => $this->getMerchantId(),
37 2
            'refno'      => $this->getTransactionId(),
38 2
            'amount'     => $this->getAmountInteger(),
39 2
            'currency'   => $this->getCurrency(),
40 2
            'sign'       => $this->getSign()
41 2
        );
42
43 2
        foreach ($this->optionalParams as $param) {
44
            $value = $this->getParameter($param);
45
46
            if ($value !== '') {
47
                $data[$param] = $value;
48
            }
49 2
        }
50
51 2
        $data['successUrl'] = $this->getReturnUrl();
52 2
        $data['cancelUrl'] = $this->getCancelUrl();
53 2
        $data['errorUrl'] = $this->getErrorUrl();
54 2
        $data['cancelUrl'] = $this->getCancelUrl();
55
56 2
        return $data;
57
    }
58
59
    /**
60
     * @param $value
61
     * @return string
62
     */
63 2
    public function setErrorUrl($value)
64
    {
65 2
        return $this->setParameter('errorUrl', $value);
66
    }
67
68
    /**
69
     * @return string
70
     */
71 2
    public function getErrorUrl()
72
    {
73 2
        return $this->getParameter('errorUrl');
74
    }
75
76
    /**
77
     * @return ResponseInterface
78
     */
79 1
    public function send()
80
    {
81 1
        return $this->sendData($this->getData());
82
    }
83
84
    /**
85
     * Send the request with specified data
86
     *
87
     * @param  mixed $data The data to send
88
     * @return ResponseInterface
89
     */
90 1
    public function sendData($data)
91
    {
92 1
        return $this->response = new PurchaseResponse($this, $data);
93
    }
94
}
95