Completed
Push — develop ( 3e5c71...511324 )
by Remco
03:23
created

Adyen::get_shared_secret()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Adyen
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
/**
14
 * Adyen
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.0.0
18
 * @since   1.0.0
19
 * @link    https://github.com/adyenpayments/php/blob/master/generatepaymentform.php
20
 */
21
class Adyen {
22
	/**
23
	 * The payment server URL
24
	 *
25
	 * @var string
26
	 */
27
	private $payment_server_url;
28
29
	//////////////////////////////////////////////////
30
31
	/**
32
	 * Constructs and initialize a iDEAL kassa object
33
	 */
34
	public function __construct() {
35
36
	}
37
38
	//////////////////////////////////////////////////
39
40
	/**
41
	 * Get the payment server URL
42
	 *
43
	 * @return the payment server URL
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\Gateways\Adyen\the was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
	 */
45
	public function get_payment_server_url() {
46
		return $this->payment_server_url;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->payment_server_url returns the type string which is incompatible with the documented return type Pronamic\WordPress\Pay\Gateways\Adyen\the.
Loading history...
47
	}
48
49
	/**
50
	 * Set the payment server URL
51
	 *
52
	 * @param string $url an URL
53
	 */
54
	public function set_payment_server_url( $url ) {
55
		$this->payment_server_url = $url;
56
	}
57
58
	//////////////////////////////////////////////////
59
60
	public function get_merchant_reference() {
61
		return $this->merchant_reference;
62
	}
63
64
	public function set_merchant_reference( $merchant_reference ) {
65
		$this->merchant_reference = $merchant_reference;
0 ignored issues
show
Bug Best Practice introduced by
The property merchant_reference does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
66
	}
67
68
	//////////////////////////////////////////////////
69
70
	public function get_payment_amount() {
71
		return $this->payment_amount;
72
	}
73
74
	public function set_payment_amount( $payment_amount ) {
75
		$this->payment_amount = $payment_amount;
0 ignored issues
show
Bug Best Practice introduced by
The property payment_amount does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
76
	}
77
78
	//////////////////////////////////////////////////
79
80
	public function get_currency_code() {
81
		return $this->currency_code;
82
	}
83
84
	public function set_currency_code( $currency_code ) {
85
		$this->currency_code = $currency_code;
0 ignored issues
show
Bug Best Practice introduced by
The property currency_code does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
86
	}
87
88
	//////////////////////////////////////////////////
89
90
	public function get_ship_before_date() {
91
		return $this->ship_before_date;
92
	}
93
94
	public function set_ship_before_date( DateTime $date ) {
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\Gateways\Adyen\DateTime was not found. Did you mean DateTime? If so, make sure to prefix the type with \.
Loading history...
95
		$this->ship_before_date = $date;
0 ignored issues
show
Bug Best Practice introduced by
The property ship_before_date does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
96
	}
97
98
	//////////////////////////////////////////////////
99
100
	public function get_skin_code() {
101
		return $this->skin_code;
102
	}
103
104
	public function set_skin_code( $skin_code ) {
105
		$this->skin_code = $skin_code;
0 ignored issues
show
Bug Best Practice introduced by
The property skin_code does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
106
	}
107
108
	//////////////////////////////////////////////////
109
110
	public function get_merchant_account() {
111
		return $this->merchant_account;
112
	}
113
114
	public function set_merchant_account( $merchant_account ) {
115
		$this->merchant_account = $merchant_account;
0 ignored issues
show
Bug Best Practice introduced by
The property merchant_account does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
116
	}
117
118
	//////////////////////////////////////////////////
119
120
	public function get_shopper_locale() {
121
		return $this->shopper_locale;
122
	}
123
124
	public function set_shopper_locale( $shopper_locale ) {
125
		$this->shopper_locale = $shopper_locale;
0 ignored issues
show
Bug Best Practice introduced by
The property shopper_locale does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
126
	}
127
128
	//////////////////////////////////////////////////
129
130
	public function get_order_data() {
131
		return $this->order_data;
132
	}
133
134
	public function set_order_data( $order_data ) {
135
		$this->order_data = $order_data;
0 ignored issues
show
Bug Best Practice introduced by
The property order_data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
136
	}
137
138
	//////////////////////////////////////////////////
139
140
	public function get_session_validity() {
141
		return $this->session_validity;
142
	}
143
144
	public function set_session_validity( DateTime $session_validity = null ) {
145
		$this->session_validity = $session_validity;
0 ignored issues
show
Bug Best Practice introduced by
The property session_validity does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
146
	}
147
148
	//////////////////////////////////////////////////
149
150
	public function get_shopper_email() {
151
		return $this->shopper_email;
152
	}
153
154
	public function set_shopper_email( $email ) {
155
		$this->shopper_email = $email;
0 ignored issues
show
Bug Best Practice introduced by
The property shopper_email does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
156
	}
157
158
	//////////////////////////////////////////////////
159
160
	public function get_shopper_reference() {
161
		return $this->shopper_reference;
162
	}
163
164
	public function set_shopper_reference( $reference ) {
165
		$this->shopper_reference = $reference;
0 ignored issues
show
Bug Best Practice introduced by
The property shopper_reference does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
166
	}
167
168
	//////////////////////////////////////////////////
169
170
	public function get_shared_secret() {
171
		return $this->shared_secret;
172
	}
173
174
	public function set_shared_secret( $shared_secret ) {
175
		$this->shared_secret = $shared_secret;
0 ignored issues
show
Bug Best Practice introduced by
The property shared_secret does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
176
	}
177
178
	//////////////////////////////////////////////////
179
180
	public function get_signature() {
181
		$data = array(
182
			Pronamic_WP_Util::amount_to_cents( $this->get_payment_amount() ),
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\G...\Adyen\Pronamic_WP_Util was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
183
			$this->get_currency_code(),
184
			Pronamic_WP_Util::format_date( 'Y-m-d', $this->get_ship_before_date() ),
185
			$this->get_merchant_reference(),
186
			$this->get_skin_code(),
187
			$this->get_merchant_account(),
188
			Pronamic_WP_Util::format_date( DATE_ATOM, $this->get_session_validity() ),
189
			$this->get_shopper_email(),
190
			$this->get_shopper_reference(),
191
		);
192
193
		$data = implode( '', $data );
194
195
		$signature = base64_encode( hash_hmac( 'sha1', $data, $this->get_shared_secret(), true ) );
196
197
		return $signature;
198
	}
199
200
	//////////////////////////////////////////////////
201
202
	/**
203
	 * Get HTML fields
204
	 *
205
	 * @return string
206
	 */
207
	public function get_html_fields() {
208
		return Pronamic_IDeal_IDeal::htmlHiddenFields( array(
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\G...en\Pronamic_IDeal_IDeal was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
209
			Pronamic_Gateways_Adyen_Parameters::MERCHANT_REFERENCE => $this->get_merchant_reference(),
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\G...teways_Adyen_Parameters was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
210
			Pronamic_Gateways_Adyen_Parameters::PAYMENT_AMOUNT     => Pronamic_WP_Util::amount_to_cents( $this->get_payment_amount() ),
211
			Pronamic_Gateways_Adyen_Parameters::CURRENCY_CODE      => $this->get_currency_code(),
212
			Pronamic_Gateways_Adyen_Parameters::SHIP_BEFORE_DATE   => Pronamic_WP_Util::format_date( 'Y-m-d', $this->get_ship_before_date() ),
213
			Pronamic_Gateways_Adyen_Parameters::SKIN_CODE          => $this->get_skin_code(),
214
			Pronamic_Gateways_Adyen_Parameters::MERCHANT_ACCOUNT   => $this->get_merchant_account(),
215
			Pronamic_Gateways_Adyen_Parameters::SHOPPER_LOCALE     => $this->get_shopper_locale(),
216
			Pronamic_Gateways_Adyen_Parameters::ORDER_DATA         => base64_encode( gzencode( $this->get_order_data() ) ),
217
			Pronamic_Gateways_Adyen_Parameters::SESSION_VALIDITY   => Pronamic_WP_Util::format_date( DATE_ATOM, $this->get_session_validity() ),
218
			Pronamic_Gateways_Adyen_Parameters::MERCHANT_SIGNATURE => $this->get_signature(),
219
			Pronamic_Gateways_Adyen_Parameters::SHOPPER_EMAIL      => $this->get_shopper_email(),
220
			Pronamic_Gateways_Adyen_Parameters::SHOPPER_REFERENCE  => $this->get_shopper_reference(),
221
		) );
222
	}
223
}
224