Completed
Push — master ( 620307...8ff95d )
by Dominik
03:16
created

XmlSettlementRequest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 147
Duplicated Lines 4.76 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 2
dl 7
loc 147
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
B getData() 7 31 4
A setUppTransactionId() 0 3 1
A getUppTransactionId() 0 3 1
A setRequestType() 0 3 1
A getRequestType() 0 3 1
A getTransactionType() 0 3 1
A createResponse() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * w-vision
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the GNU General Public License version 3 (GPLv3)
8
 * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
9
 * files that are distributed with this source code.
10
 *
11
 * @copyright  Copyright (c) 2016 Woche-Pass AG (http://www.w-vision.ch)
12
 * @license    GNU General Public License version 3 (GPLv3)
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 = [
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
    public function getData()
90
    {
91
        $this->validate('merchantId', 'transactionId', 'sign', 'uppTransactionId');
92
93
        $requestType = $this->getRequestType();
94
95
        if(is_null($requestType)) {
96
            $requestType = self::DATATRANS_REQUEST_TYPE_COA;
97
        }
98
99
        $data = array(
100
            'merchantId'        => $this->getMerchantId(),
101
            'sign'              => $this->getSign(),
102
            'amount'            => $this->getAmountInteger(),
103
            'currency'          => $this->getCurrency(),
104
            'uppTransactionId'  => $this->getUppTransactionId(),
105
            'refno'             => $this->getTransactionId(),
106
            'reqtype'           => $requestType,
107
            'transtype'         => $this->getTransactionType()
108
        );
109
110 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
            $value = $this->getParameter($param);
112
113
            if ($value) {
114
                $data[$param] = $value;
115
            }
116
        }
117
118
        return $data;
119
    }
120
121
   /**
122
     * @param $value
123
     *
124
     * @return static
125
     */
126
    public function setUppTransactionId($value) {
127
        return $this->setParameter("uppTransactionId", $value);
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    public function getUppTransactionId() {
134
        return $this->getParameter("uppTransactionId");
135
    }
136
137
    /**
138
     * @param $value
139
     *
140
     * @return static
141
     */
142
    public function setRequestType($value) {
143
        return $this->setParameter("requestType", $value);
144
    }
145
146
    /**
147
     * @return string
148
     */
149
    public function getRequestType() {
150
        return $this->getParameter("requestType");
151
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getTransactionType() {
157
        return static::DATATRANS_TRANSACTION_TYPE_DEBIT;
158
    }
159
160
    /**
161
     * @param $data
162
     * @return XmlResponse
163
     */
164
    protected function createResponse($data)
165
    {
166
        return $this->response = new XmlResponse($this, $data);
167
    }
168
}
169