Passed
Push — feature/post-pay ( ced2a4...83b78e )
by Remco
05:28
created
src/Request.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 	 * @param string      $merchant_id    Merchant ID.
38 38
 	 * @param string|null $shop_id        Shop ID.
39 39
 	 */
40
-	public function __construct( $merchant_id, $shop_id = null ) {
41
-		$this->set_parameter( 'merchantid', $merchant_id );
42
-		$this->set_parameter( 'shopid', $shop_id );
40
+	public function __construct($merchant_id, $shop_id = null) {
41
+		$this->set_parameter('merchantid', $merchant_id);
42
+		$this->set_parameter('shopid', $shop_id);
43 43
 	}
44 44
 
45 45
 	/**
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 	 * @param string $parameter Parameter.
49 49
 	 * @return string|null
50 50
 	 */
51
-	public function get_parameter( $parameter ) {
52
-		if ( isset( $this->parameters[ $parameter ] ) ) {
53
-			return $this->parameters[ $parameter ];
51
+	public function get_parameter($parameter) {
52
+		if (isset($this->parameters[$parameter])) {
53
+			return $this->parameters[$parameter];
54 54
 		}
55 55
 
56 56
 		return null;
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @param string      $parameter Parameter.
63 63
 	 * @param string|null $value     Value.
64 64
 	 */
65
-	public function set_parameter( $parameter, $value ) {
66
-		$this->parameters[ $parameter ] = $value;
65
+	public function set_parameter($parameter, $value) {
66
+		$this->parameters[$parameter] = $value;
67 67
 	}
68 68
 
69 69
 	/**
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @param array $parameters Parameters.
82 82
 	 */
83
-	public function merge_parameters( $parameters ) {
84
-		$this->parameters = array_merge( $this->parameters, $parameters );
83
+	public function merge_parameters($parameters) {
84
+		$this->parameters = array_merge($this->parameters, $parameters);
85 85
 	}
86 86
 
87 87
 	/**
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 	 * @param string $merchant_key Merchant key.
100 100
 	 * @return string
101 101
 	 */
102
-	public function get_signature( $merchant_key ) {
102
+	public function get_signature($merchant_key) {
103 103
 		$data = $this->get_signature_data();
104 104
 
105 105
 		$data[] = $merchant_key;
106 106
 
107
-		$string = implode( '', $data );
107
+		$string = implode('', $data);
108 108
 
109
-		$signature = sha1( $string );
109
+		$signature = sha1($string);
110 110
 
111 111
 		return $signature;
112 112
 	}
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	 *
117 117
 	 * @param string $merchant_key Merchant key.
118 118
 	 */
119
-	public function sign( $merchant_key ) {
120
-		$signature = $this->get_signature( $merchant_key );
119
+	public function sign($merchant_key) {
120
+		$signature = $this->get_signature($merchant_key);
121 121
 
122
-		$this->set_parameter( 'sha1', $signature );
122
+		$this->set_parameter('sha1', $signature);
123 123
 	}
124 124
 }
Please login to merge, or discard this patch.
src/Gateway.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -37,17 +37,17 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param Config $config Config.
39 39
 	 */
40
-	public function __construct( Config $config ) {
41
-		parent::__construct( $config );
40
+	public function __construct(Config $config) {
41
+		parent::__construct($config);
42 42
 
43 43
 		$this->supports = array(
44 44
 			'payment_status_request',
45 45
 		);
46 46
 
47
-		$this->set_method( self::METHOD_HTTP_REDIRECT );
47
+		$this->set_method(self::METHOD_HTTP_REDIRECT);
48 48
 
49
-		$this->client = new Client( $config->merchant_id, $config->merchant_key );
50
-		$this->client->set_test_mode( self::MODE_TEST === $config->mode );
49
+		$this->client = new Client($config->merchant_id, $config->merchant_key);
50
+		$this->client->set_test_mode(self::MODE_TEST === $config->mode);
51 51
 	}
52 52
 
53 53
 	/**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
 		$result = $this->client->get_directory();
62 62
 
63
-		if ( $result ) {
63
+		if ($result) {
64 64
 			$groups[] = array(
65 65
 				'options' => $result,
66 66
 			);
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @param Payment $payment Payment.
113 113
 	 */
114
-	public function start( Payment $payment ) {
114
+	public function start(Payment $payment) {
115 115
 		// Order and purchase ID.
116 116
 		$order_id    = $payment->get_order_id();
117
-		$purchase_id = strval( empty( $order_id ) ? $payment->get_id() : $order_id );
117
+		$purchase_id = strval(empty($order_id) ? $payment->get_id() : $order_id);
118 118
 
119 119
 		// Maximum length for purchase ID is 16 characters, otherwise an error will occur:
120 120
 		// ideal_sisow_error - purchaseid too long (16).
121
-		$purchase_id = substr( $purchase_id, 0, 16 );
121
+		$purchase_id = substr($purchase_id, 0, 16);
122 122
 
123 123
 		// New transaction request.
124 124
 		$request = new TransactionRequest(
@@ -128,12 +128,12 @@  discard block
 block discarded – undo
128 128
 
129 129
 		$request->merge_parameters(
130 130
 			array(
131
-				'payment'      => Methods::transform( $payment->get_method(), $payment->get_method() ),
132
-				'purchaseid'   => substr( $purchase_id, 0, 16 ),
131
+				'payment'      => Methods::transform($payment->get_method(), $payment->get_method()),
132
+				'purchaseid'   => substr($purchase_id, 0, 16),
133 133
 				'entrancecode' => $payment->get_entrance_code(),
134 134
 				'amount'       => $payment->get_amount()->get_cents(),
135
-				'description'  => substr( $payment->get_description(), 0, 32 ),
136
-				'testmode'     => ( self::MODE_TEST === $this->config->mode ) ? 'true' : 'false',
135
+				'description'  => substr($payment->get_description(), 0, 32),
136
+				'testmode'     => (self::MODE_TEST === $this->config->mode) ? 'true' : 'false',
137 137
 				'returnurl'    => $payment->get_return_url(),
138 138
 				'cancelurl'    => $payment->get_return_url(),
139 139
 				'notifyurl'    => $payment->get_return_url(),
@@ -145,15 +145,15 @@  discard block
 block discarded – undo
145 145
 		);
146 146
 
147 147
 		// Payment method.
148
-		$this->set_payment_method( null === $payment->get_method() ? PaymentMethods::IDEAL : $payment->get_method() );
148
+		$this->set_payment_method(null === $payment->get_method() ? PaymentMethods::IDEAL : $payment->get_method());
149 149
 
150 150
 		// Additional parameters for payment method.
151
-		if ( PaymentMethods::IDEALQR === $payment->get_method() ) {
152
-			$request->set_parameter( 'qrcode', 'true' );
151
+		if (PaymentMethods::IDEALQR === $payment->get_method()) {
152
+			$request->set_parameter('qrcode', 'true');
153 153
 		}
154 154
 
155 155
 		// Customer.
156
-		if ( null !== $payment->get_customer() ) {
156
+		if (null !== $payment->get_customer()) {
157 157
 			$customer = $payment->get_customer();
158 158
 
159 159
 			$request->merge_parameters(
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
 				)
165 165
 			);
166 166
 
167
-			if ( null !== $customer->get_birth_date() ) {
168
-				$request->set_parameter( 'birth_date', $customer->get_birth_date()->format( 'ddmmYYYY' ) );
167
+			if (null !== $customer->get_birth_date()) {
168
+				$request->set_parameter('birth_date', $customer->get_birth_date()->format('ddmmYYYY'));
169 169
 			}
170 170
 		}
171 171
 
172 172
 		// Billing address.
173
-		if ( null !== $payment->get_billing_address() ) {
173
+		if (null !== $payment->get_billing_address()) {
174 174
 			$address = $payment->get_billing_address();
175 175
 
176
-			if ( null !== $address->get_name() ) {
176
+			if (null !== $address->get_name()) {
177 177
 				$name = $address->get_name();
178 178
 
179 179
 				$request->merge_parameters(
@@ -201,10 +201,10 @@  discard block
 block discarded – undo
201 201
 		}
202 202
 
203 203
 		// Shipping address.
204
-		if ( null !== $payment->get_shipping_address() ) {
204
+		if (null !== $payment->get_shipping_address()) {
205 205
 			$address = $payment->get_shipping_address();
206 206
 
207
-			if ( null !== $address->get_name() ) {
207
+			if (null !== $address->get_name()) {
208 208
 				$name = $address->get_name();
209 209
 
210 210
 				$request->merge_parameters(
@@ -231,16 +231,16 @@  discard block
 block discarded – undo
231 231
 		}
232 232
 
233 233
 		// Lines.
234
-		if ( null !== $payment->get_lines() ) {
234
+		if (null !== $payment->get_lines()) {
235 235
 			$lines = $payment->get_lines();
236 236
 
237 237
 			$x = 1;
238 238
 
239
-			foreach ( $lines as $line ) {
240
-				$net_price = ( null === $line->get_unit_price() ) ? null : $line->get_unit_price()->get_cents();
241
-				$total     = ( null === $line->get_total_amount() ) ? null : $line->get_total_amount()->get_cents();
242
-				$tax       = ( null === $line->get_tax_amount() ) ? null : $line->get_tax_amount()->get_cents();
243
-				$net_total = ( $total - $tax );
239
+			foreach ($lines as $line) {
240
+				$net_price = (null === $line->get_unit_price()) ? null : $line->get_unit_price()->get_cents();
241
+				$total     = (null === $line->get_total_amount()) ? null : $line->get_total_amount()->get_cents();
242
+				$tax       = (null === $line->get_tax_amount()) ? null : $line->get_tax_amount()->get_cents();
243
+				$net_total = ($total - $tax);
244 244
 
245 245
 				$request->merge_parameters(
246 246
 					array(
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
 		}
261 261
 
262 262
 		// Create transaction.
263
-		$result = $this->client->create_transaction( $request );
263
+		$result = $this->client->create_transaction($request);
264 264
 
265
-		if ( false !== $result ) {
266
-			$payment->set_transaction_id( $result->id );
267
-			$payment->set_action_url( $result->issuer_url );
265
+		if (false !== $result) {
266
+			$payment->set_transaction_id($result->id);
267
+			$payment->set_action_url($result->issuer_url);
268 268
 		} else {
269 269
 			$this->error = $this->client->get_error();
270 270
 		}
@@ -275,16 +275,16 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @param Payment $payment Payment.
277 277
 	 */
278
-	public function update_status( Payment $payment ) {
278
+	public function update_status(Payment $payment) {
279 279
 		$request = new StatusRequest(
280 280
 			$payment->get_transaction_id(),
281 281
 			$this->config->merchant_id,
282 282
 			$this->config->shop_id
283 283
 		);
284 284
 
285
-		$result = $this->client->get_status( $request );
285
+		$result = $this->client->get_status($request);
286 286
 
287
-		if ( false === $result ) {
287
+		if (false === $result) {
288 288
 			$this->error = $this->client->get_error();
289 289
 
290 290
 			return;
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
 
293 293
 		$transaction = $result;
294 294
 
295
-		$payment->set_status( $transaction->status );
296
-		$payment->set_consumer_name( $transaction->consumer_name );
297
-		$payment->set_consumer_account_number( $transaction->consumer_account );
298
-		$payment->set_consumer_city( $transaction->consumer_city );
295
+		$payment->set_status($transaction->status);
296
+		$payment->set_consumer_name($transaction->consumer_name);
297
+		$payment->set_consumer_account_number($transaction->consumer_account);
298
+		$payment->set_consumer_city($transaction->consumer_city);
299 299
 	}
300 300
 }
Please login to merge, or discard this patch.
src/Client.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 * @param string $merchant_id  Merchant ID.
69 69
 	 * @param string $merchant_key Merchant key.
70 70
 	 */
71
-	public function __construct( $merchant_id, $merchant_key ) {
71
+	public function __construct($merchant_id, $merchant_key) {
72 72
 		$this->merchant_id  = $merchant_id;
73 73
 		$this->merchant_key = $merchant_key;
74 74
 	}
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @param boolean $test_mode True if test mode, false otherwise.
89 89
 	 */
90
-	public function set_test_mode( $test_mode ) {
90
+	public function set_test_mode($test_mode) {
91 91
 		$this->test_mode = $test_mode;
92 92
 	}
93 93
 
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
 	 * @param Request|null $request Request.
99 99
 	 * @return false|SimpleXMLElement
100 100
 	 */
101
-	private function send_request( $method, Request $request = null ) {
101
+	private function send_request($method, Request $request = null) {
102 102
 		$url = self::API_URL . '/' . $method;
103 103
 
104
-		if ( null !== $request ) {
105
-			$request->sign( $this->merchant_key );
104
+		if (null !== $request) {
105
+			$request->sign($this->merchant_key);
106 106
 		}
107 107
 
108 108
 		$result = Core_Util::remote_get_body(
@@ -110,24 +110,24 @@  discard block
 block discarded – undo
110 110
 			200,
111 111
 			array(
112 112
 				'method' => 'POST',
113
-				'body'   => ( null === $request ) ? null : $request->get_parameters(),
113
+				'body'   => (null === $request) ? null : $request->get_parameters(),
114 114
 			)
115 115
 		);
116 116
 
117
-		if ( $result instanceof WP_Error ) {
117
+		if ($result instanceof WP_Error) {
118 118
 			$this->error = $result;
119 119
 
120 120
 			return false;
121 121
 		}
122 122
 
123
-		if ( ! is_string( $result ) ) {
123
+		if ( ! is_string($result)) {
124 124
 			return false;
125 125
 		}
126 126
 
127 127
 		// XML.
128
-		$xml = Core_Util::simplexml_load_string( $result );
128
+		$xml = Core_Util::simplexml_load_string($result);
129 129
 
130
-		if ( $xml instanceof WP_Error ) {
130
+		if ($xml instanceof WP_Error) {
131 131
 			$this->error = $xml;
132 132
 
133 133
 			return false;
@@ -142,31 +142,31 @@  discard block
 block discarded – undo
142 142
 	 * @param SimpleXMLElement $document Document.
143 143
 	 * @return WP_Error|Transaction|Error
144 144
 	 */
145
-	private function parse_document( SimpleXMLElement $document ) {
145
+	private function parse_document(SimpleXMLElement $document) {
146 146
 		$this->error = null;
147 147
 
148 148
 		$name = $document->getName();
149 149
 
150
-		switch ( $name ) {
150
+		switch ($name) {
151 151
 			case 'errorresponse':
152
-				$sisow_error = ErrorParser::parse( $document->error );
152
+				$sisow_error = ErrorParser::parse($document->error);
153 153
 
154
-				$this->error = new WP_Error( 'ideal_sisow_error', $sisow_error->message, $sisow_error );
154
+				$this->error = new WP_Error('ideal_sisow_error', $sisow_error->message, $sisow_error);
155 155
 
156 156
 				return $sisow_error;
157 157
 			case 'transactionrequest':
158
-				$transaction = TransactionParser::parse( $document->transaction );
158
+				$transaction = TransactionParser::parse($document->transaction);
159 159
 
160 160
 				return $transaction;
161 161
 			case 'statusresponse':
162
-				$transaction = TransactionParser::parse( $document->transaction );
162
+				$transaction = TransactionParser::parse($document->transaction);
163 163
 
164 164
 				return $transaction;
165 165
 			default:
166 166
 				return new WP_Error(
167 167
 					'ideal_sisow_error',
168 168
 					/* translators: %s: XML document element name */
169
-					sprintf( __( 'Unknwon Sisow message (%s)', 'pronamic_ideal' ), $name )
169
+					sprintf(__('Unknwon Sisow message (%s)', 'pronamic_ideal'), $name)
170 170
 				);
171 171
 		}
172 172
 	}
@@ -177,27 +177,27 @@  discard block
 block discarded – undo
177 177
 	 * @return array|false
178 178
 	 */
179 179
 	public function get_directory() {
180
-		if ( $this->test_mode ) {
180
+		if ($this->test_mode) {
181 181
 			return array(
182
-				'99' => __( 'Sisow Bank (test)', 'pronamic_ideal' ),
182
+				'99' => __('Sisow Bank (test)', 'pronamic_ideal'),
183 183
 			);
184 184
 		}
185 185
 
186 186
 		// Request.
187
-		$result = $this->send_request( RequestMethods::DIRECTORY_REQUEST );
187
+		$result = $this->send_request(RequestMethods::DIRECTORY_REQUEST);
188 188
 
189
-		if ( false === $result ) {
189
+		if (false === $result) {
190 190
 			return false;
191 191
 		}
192 192
 
193 193
 		// Parse.
194 194
 		$directory = array();
195 195
 
196
-		foreach ( $result->directory->issuer as $issuer ) {
196
+		foreach ($result->directory->issuer as $issuer) {
197 197
 			$id   = (string) $issuer->issuerid;
198 198
 			$name = (string) $issuer->issuername;
199 199
 
200
-			$directory[ $id ] = $name;
200
+			$directory[$id] = $name;
201 201
 		}
202 202
 
203 203
 		return $directory;
@@ -209,18 +209,18 @@  discard block
 block discarded – undo
209 209
 	 * @param TransactionRequest $request Transaction request.
210 210
 	 * @return Transaction|false
211 211
 	 */
212
-	public function create_transaction( TransactionRequest $request ) {
212
+	public function create_transaction(TransactionRequest $request) {
213 213
 		// Request.
214
-		$response = $this->send_request( RequestMethods::TRANSACTION_REQUEST, $request );
214
+		$response = $this->send_request(RequestMethods::TRANSACTION_REQUEST, $request);
215 215
 
216
-		if ( false === $response ) {
216
+		if (false === $response) {
217 217
 			return false;
218 218
 		}
219 219
 
220 220
 		// Parse.
221
-		$message = $this->parse_document( $response );
221
+		$message = $this->parse_document($response);
222 222
 
223
-		if ( $message instanceof Transaction ) {
223
+		if ($message instanceof Transaction) {
224 224
 			return $message;
225 225
 		}
226 226
 
@@ -233,18 +233,18 @@  discard block
 block discarded – undo
233 233
 	 * @param StatusRequest $request Status request object.
234 234
 	 * @return Transaction|false
235 235
 	 */
236
-	public function get_status( StatusRequest $request ) {
236
+	public function get_status(StatusRequest $request) {
237 237
 		// Request.
238
-		$response = $this->send_request( RequestMethods::STATUS_REQUEST, $request );
238
+		$response = $this->send_request(RequestMethods::STATUS_REQUEST, $request);
239 239
 
240
-		if ( false === $response ) {
240
+		if (false === $response) {
241 241
 			return false;
242 242
 		}
243 243
 
244 244
 		// Parse.
245
-		$message = $this->parse_document( $response );
245
+		$message = $this->parse_document($response);
246 246
 
247
-		if ( $message instanceof Transaction ) {
247
+		if ($message instanceof Transaction) {
248 248
 			return $message;
249 249
 		}
250 250
 
Please login to merge, or discard this patch.