AbstractRequest::setTestKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * InterKassa driver for the Omnipay PHP payment processing library
5
 *
6
 * @link      https://github.com/ange007/omnipay-interkassa
7
 * @package   omnipay-interkassa
8
 * @license   MIT
9
 * @copyright Copyright (c) 2017, ange007 ( original author: HiQDev - http://hiqdev.com/ )
10
 */
11
12
namespace Omnipay\InterKassa\Message;
13
14
/**
15
 * InterKassa Abstract Request.
16
 */
17
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
18
{
19
    /**
20
	 * {@inheritdoc}
21
	 */
22
	protected $zeroAmountAllowed = false;
23
24
	/**
25
	 * @var string
26
	 */
27
	protected $endpoint = 'https://sci.interkassa.com/';
28
29
	/**
30
	 * Get the unified purse.
31
	 *
32
	 * @return string merchant purse
33
	 */
34
	public function getPurse( )
35
	{
36
		return $this->getCheckoutId( );
37
	}
38
39
	/**
40
	 * Set the unified purse.
41
	 *
42
	 * @param $value
43
	 * @return self
44
	 */
45
	public function setPurse( $value )
46
	{
47
		return $this->setCheckoutId( $value );
48
	}
49
50
	/**
51
	 * Get the merchant purse.
52
	 *
53
	 * @return string merchant purse
54
	 */
55
	public function getCheckoutId( )
56
	{
57
		return $this->getParameter( 'checkoutId' );
58
	}
59
60
	/**
61
	 * Set the merchant purse.
62
	 *
63
	 * @param string $purse merchant purse
64
	 *
65
	 * @return self
66
	 */
67
	public function setCheckoutId( $purse )
68
	{
69
		return $this->setParameter( 'checkoutId', $purse );
70
	}
71
72
	/**
73
	 * Get the sign algorithm.
74
	 *
75
	 * @return string sign algorithm
76
	 */
77
	public function getSignAlgorithm( )
78
	{
79
		return strtolower( $this->getParameter( 'signAlgorithm' ) );
80
	}
81
82
	/**
83
	 * Set the sign algorithm.
84
	 *
85
	 * @param string $value sign algorithm
86
	 *
87
	 * @return self
88
	 */
89
	public function setSignAlgorithm( $value )
90
	{
91
		return $this->setParameter( 'signAlgorithm', $value );
92
	}
93
94
	/**
95
	 * Get the sign key.
96
	 *
97
	 * @return string sign key
98
	 */
99
	public function getSignKey( )
100
	{
101
		return $this->getParameter( 'signKey' );
102
	}
103
104
	/**
105
	 * Set the sign key.
106
	 *
107
	 * @param string $value sign key
108
	 *
109
	 * @return self
110
	 */
111
	public function setSignKey( $value )
112
	{
113
		return $this->setParameter( 'signKey', $value );
114
	}
115
116
	/**
117
	 * Get the test key.
118
	 *
119
	 * @return string test key
120
	 */
121
	public function getTestKey( )
122
	{
123
		return $this->getParameter( 'testKey' );
124
	}
125
126
	/**
127
	 * Set the test key.
128
	 *
129
	 * @param string $value test key
130
	 *
131
	 * @return self
132
	 */
133
	public function setTestKey( $value )
134
	{
135
		return $this->setParameter( 'testKey', $value );
136
	}
137
138
	/**
139
	 * Get the method for success return.
140
	 *
141
	 * @return mixed
142
	 */
143
	public function getReturnMethod( )
144
	{
145
		return $this->getParameter( 'returnMethod' );
146
	}
147
148
	/**
149
	 * Sets the method for success return.
150
	 *
151
	 * @param $returnMethod
152
	 * @return \Omnipay\Common\Message\AbstractRequest
153
	 */
154
	public function setReturnMethod( $returnMethod )
155
	{
156
		return $this->setParameter( 'returnMethod', $returnMethod );
157
	}
158
159
	/**
160
	 * Get the method for canceled payment return.
161
	 *
162
	 * @return mixed
163
	 */
164
	public function getCancelMethod( )
165
	{
166
		return $this->getParameter( 'cancelMethod' );
167
	}
168
169
	/**
170
	 * Sets the method for canceled payment return.
171
	 *
172
	 * @param $cancelMethod
173
	 * @return \Omnipay\Common\Message\AbstractRequest
174
	 */
175
	public function setCancelMethod( $cancelMethod )
176
	{
177
		return $this->setParameter( 'cancelMethod', $cancelMethod );
178
	}
179
180
	/**
181
	 * Get the method for request notify.
182
	 *
183
	 * @return mixed
184
	 */
185
	public function getNotifyMethod()
186
	{
187
		return $this->getParameter( 'notifyMethod' );
188
	}
189
190
	/**
191
	 * Sets the method for request notify.
192
	 *
193
	 * @param $notifyMethod
194
	 * @return \Omnipay\Common\Message\AbstractRequest
195
	 */
196
	public function setNotifyMethod( $notifyMethod )
197
	{
198
		return $this->setParameter( 'notifyMethod', $notifyMethod );
199
	}
200
201
	/**
202
     * Calculates sign for the $data.
203
     *
204
     * @param array $data
205
     * @param string $signKey
206
     * @return string
207
     */
208
    public function calculateSign( $data, $signKey )
209
	{
210
		unset( $data[ 'ik_sign' ] );
211
		ksort( $data, SORT_STRING );
212
		array_push( $data, $signKey );
213
		$signAlgorithm = $this->getSignAlgorithm( );
214
		$signString = implode( ':', $data );
215
		return base64_encode( hash( $signAlgorithm, $signString, true ) );
216
	}
217
218
	/**
219
	 * Get the data for this request.
220
	 * @throws InvalidResponseException
221
	 * @throws \Omnipay\Common\Exception\InvalidRequestException
222
	 * @return array request data
223
	 */
224
	public function getData( )
225
	{
226
		if( $this->getTestMode( ) )
227
		{
228
			$this->validate( 'testKey' );
229
		} 
230
		else
231
		{
232
			$this->validate( 'signKey' );
233
		}
234
235
		$result = [];
236
		$vars = array_merge( $this->httpRequest->query->all( ), $this->httpRequest->request->all( ) );
237
		foreach( $vars as $key => $parameter )
238
		{
239
			if( strpos( $key, 'ik_' ) === 0 )
240
			{
241
				$result[ $key ] = $parameter;
242
			}
243
		}
244
245
		return $result;
246
	}
247
}