XmlSettlementRequest::createResponse()   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
/**
18
 * Class XmlSettlementRequest
19
 *
20
 * @package Omnipay\Datatrans\Message
21
 */
22
class XmlSettlementRequest extends XmlRequest
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $optionalParameters = array(
28
        'transtype', 'acqAuthorizationCode', 'errorEmail'
29
    );
30
31
    /**
32
     * @var string
33
     */
34
    protected $apiEndpoint = 'XML_processor.jsp';
35
36
    /**
37
     * @var string
38
     */
39
    protected $serviceName = 'paymentService';
40
41
    /**
42
     * @var int
43
     */
44
    protected $serviceVersion = 3;
45
46
    /**
47
     * Settlement Debit/Credit
48
     */
49
    const DATATRANS_REQUEST_TYPE_COA = 'COA';
50
51
    /**
52
     * Submission of acqAuthorizationCode after referral
53
     */
54
    const DATATRANS_REQUEST_TYPE_REF = 'REF';
55
56
    /**
57
     * Submission of acqAuthorizationCode after denial
58
     */
59
    const DATATRANS_REQUEST_TYPE_REC = 'REC';
60
61
    /**
62
     * Transaction status request
63
     */
64
    const DATATRANS_REQUEST_TYPE_STA = 'STA';
65
66
    /**
67
     * Transaction cancel request
68
     */
69
    const DATATRANS_REQUEST_TYPE_DOA = 'DOA';
70
71
    /**
72
     * Re-Authorization of old transaction
73
     */
74
    const DATATRANS_REQUEST_TYPE_REA = 'REA';
75
76
    /**
77
     * Debit Transaction
78
     */
79
    const DATATRANS_TRANSACTION_TYPE_DEBIT = '05';
80
81
    /**
82
     * Credit Transaction
83
     */
84
    const DATATRANS_TRANSACTION_TYPE_CREDIT = '06';
85
86
    /**
87
     * @return array
88
     */
89 6
    public function getData()
90
    {
91 6
        $this->validate('merchantId', 'transactionId', 'sign', 'uppTransactionId');
92
93 6
        $requestType = $this->getRequestType();
94
95 6
        if (is_null($requestType)) {
96 5
            $requestType = self::DATATRANS_REQUEST_TYPE_COA;
97 5
        }
98
99
        $data = array(
100 6
            'merchantId'        => $this->getMerchantId(),
101 6
            'sign'              => $this->getSign(),
102 6
            'amount'            => $this->getAmountInteger(),
103 6
            'currency'          => $this->getCurrency(),
104 6
            'uppTransactionId'  => $this->getUppTransactionId(),
105 6
            'refno'             => $this->getTransactionId(),
106 6
            'reqtype'           => $requestType,
107 6
            'transtype'         => $this->getTransactionType()
108 6
        );
109
110 6 View Code Duplication
        foreach ($this->optionalParameters as $param) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111 6
            $value = $this->getParameter($param);
112
113 6
            if ($value) {
114
                $data[$param] = $value;
115
            }
116 6
        }
117
118 6
        return $data;
119
    }
120
121
   /**
122
     * @param $value
123
     *
124
     * @return static
125
     */
126 8
    public function setUppTransactionId($value)
127
    {
128 8
        return $this->setParameter("uppTransactionId", $value);
129
    }
130
131
    /**
132
     * @return string
133
     */
134 8
    public function getUppTransactionId()
135
    {
136 8
        return $this->getParameter("uppTransactionId");
137
    }
138
139
    /**
140
     * @param $value
141
     *
142
     * @return static
143
     */
144
    public function setRequestType($value)
145
    {
146
        return $this->setParameter("requestType", $value);
147
    }
148
149
    /**
150
     * @return string
151
     */
152 5
    public function getRequestType()
153
    {
154 5
        return $this->getParameter("requestType");
155
    }
156
157
    /**
158
     * @return string
159
     */
160 2
    public function getTransactionType()
161
    {
162 2
        return static::DATATRANS_TRANSACTION_TYPE_DEBIT;
163
    }
164
165
    /**
166
     * @param $data
167
     * @return XmlResponse
168
     */
169 8
    protected function createResponse($data)
170
    {
171 8
        return $this->response = new XmlResponse($this, $data);
172
    }
173
}
174