Completed
Pull Request — master (#5)
by
unknown
04:36
created

AbstractRedirectRequest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 2
dl 0
loc 94
ccs 24
cts 28
cp 0.8571
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
B getData() 0 27 3
A setErrorUrl() 0 4 1
A getErrorUrl() 0 4 1
A send() 0 4 1
A sendData() 0 4 1
A setUppReturnMaskedCC() 0 4 1
A setUseAlias() 0 3 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
        'uppReturnMaskedCC',
26
        'useAlias'
27
    );
28
29
    /**
30
     * @return array
31 2
     */
32
    public function getData()
33 2
    {
34
        $this->validate('merchantId', 'transactionId', 'sign');
35
36 2
        $data = array(
37 2
            'merchantId' => $this->getMerchantId(),
38 2
            'refno'      => $this->getTransactionId(),
39 2
            'amount'     => $this->getAmountInteger(),
40 2
            'currency'   => $this->getCurrency(),
41 2
            'sign'       => $this->getSign()
42
        );
43 2
44
        foreach ($this->optionalParams as $param) {
45
            $value = $this->getParameter($param);
46
47
            if (!empty($value)) {
48
                $data[$param] = $value;
49 2
            }
50
        }
51 2
52 2
        $data['successUrl'] = $this->getReturnUrl();
53 2
        $data['cancelUrl'] = $this->getCancelUrl();
54 2
        $data['errorUrl'] = $this->getErrorUrl();
55
        $data['cancelUrl'] = $this->getCancelUrl();
56 2
57
        return $data;
58
    }
59
60
    /**
61
     * @param $value
62
     * @return string
63 2
     */
64
    public function setErrorUrl($value)
65 2
    {
66
        return $this->setParameter('errorUrl', $value);
67
    }
68
69
    /**
70
     * @return string
71 2
     */
72
    public function getErrorUrl()
73 2
    {
74
        return $this->getParameter('errorUrl');
75
    }
76
77
    /**
78
     * @return ResponseInterface
79 1
     */
80
    public function send()
81 1
    {
82
        return $this->sendData($this->getData());
83
    }
84
85
    /**
86
     * Send the request with specified data
87
     *
88
     * @param  mixed $data The data to send
89
     * @return ResponseInterface
90 1
     */
91
    public function sendData($data)
92 1
    {
93
        return $this->response = new PurchaseResponse($this, $data);
94
    }
95 1
96
    /**
97
     * @param $value
98
     * @return \Omnipay\Common\Message\AbstractRequest
99
     */
100
    public function setUppReturnMaskedCC($value)
101
    {
102
        return $this->setParameter('uppReturnMaskedCC', $value);
103
    }
104
105
    /**
106
     * @param $value
107
     * @return \Omnipay\Common\Message\AbstractRequest
108
     */
109
    public function setUseAlias($value){
110
        return $this->setParameter('useAlias', $value);
111
    }
112
}
113