Issues (942)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

includes/gateways/bacs/class-wc-gateway-bacs.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Class WC_Gateway_BACS file.
4
 *
5
 * @package WooCommerce\Gateways
6
 */
7
8 1
if ( ! defined( 'ABSPATH' ) ) {
9
	exit; // Exit if accessed directly.
10
}
11
12
/**
13
 * Bank Transfer Payment Gateway.
14
 *
15
 * Provides a Bank Transfer Payment Gateway. Based on code by Mike Pepper.
16
 *
17
 * @class       WC_Gateway_BACS
18
 * @extends     WC_Payment_Gateway
19
 * @version     2.1.0
20
 * @package     WooCommerce/Classes/Payment
21
 */
22
class WC_Gateway_BACS extends WC_Payment_Gateway {
23
24
	/**
25
	 * Array of locales
26
	 *
27
	 * @var array
28
	 */
29
	public $locale;
30
31
	/**
32
	 * Constructor for the gateway.
33
	 */
34 1
	public function __construct() {
35
36 1
		$this->id                 = 'bacs';
37 1
		$this->icon               = apply_filters( 'woocommerce_bacs_icon', '' );
38 1
		$this->has_fields         = false;
39 1
		$this->method_title       = __( 'Direct bank transfer', 'woocommerce' );
40 1
		$this->method_description = __( 'Take payments in person via BACS. More commonly known as direct bank/wire transfer', 'woocommerce' );
41
42
		// Load the settings.
43 1
		$this->init_form_fields();
44 1
		$this->init_settings();
45
46
		// Define user set variables.
47 1
		$this->title        = $this->get_option( 'title' );
48 1
		$this->description  = $this->get_option( 'description' );
49 1
		$this->instructions = $this->get_option( 'instructions' );
50
51
		// BACS account fields shown on the thanks page and in emails.
52 1
		$this->account_details = get_option(
53 1
			'woocommerce_bacs_accounts',
54
			array(
55
				array(
56 1
					'account_name'   => $this->get_option( 'account_name' ),
57 1
					'account_number' => $this->get_option( 'account_number' ),
58 1
					'sort_code'      => $this->get_option( 'sort_code' ),
59 1
					'bank_name'      => $this->get_option( 'bank_name' ),
60 1
					'iban'           => $this->get_option( 'iban' ),
61 1
					'bic'            => $this->get_option( 'bic' ),
62
				),
63
			)
64
		);
65
66
		// Actions.
67 1
		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
68 1
		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) );
69 1
		add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) );
70
71
		// Customer Emails.
72 1
		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
73
	}
74
75
	/**
76
	 * Initialise Gateway Settings Form Fields.
77
	 */
78 1 View Code Duplication
	public function init_form_fields() {
0 ignored issues
show
This method seems to be duplicated in 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...
79
80 1
		$this->form_fields = array(
81
			'enabled'         => array(
82 1
				'title'   => __( 'Enable/Disable', 'woocommerce' ),
83 1
				'type'    => 'checkbox',
84 1
				'label'   => __( 'Enable bank transfer', 'woocommerce' ),
85 1
				'default' => 'no',
86
			),
87
			'title'           => array(
88 1
				'title'       => __( 'Title', 'woocommerce' ),
89 1
				'type'        => 'text',
90 1
				'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
91 1
				'default'     => __( 'Direct bank transfer', 'woocommerce' ),
92
				'desc_tip'    => true,
93
			),
94
			'description'     => array(
95 1
				'title'       => __( 'Description', 'woocommerce' ),
96 1
				'type'        => 'textarea',
97 1
				'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),
98 1
				'default'     => __( 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.', 'woocommerce' ),
99
				'desc_tip'    => true,
100
			),
101
			'instructions'    => array(
102 1
				'title'       => __( 'Instructions', 'woocommerce' ),
103 1
				'type'        => 'textarea',
104 1
				'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),
105 1
				'default'     => '',
106
				'desc_tip'    => true,
107
			),
108
			'account_details' => array(
109
				'type' => 'account_details',
110
			),
111
		);
112
113
	}
114
115
	/**
116
	 * Generate account details html.
117
	 *
118
	 * @return string
119
	 */
120
	public function generate_account_details_html() {
121
122
		ob_start();
123
124
		$country = WC()->countries->get_base_country();
125
		$locale  = $this->get_country_locale();
126
127
		// Get sortcode label in the $locale array and use appropriate one.
128
		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
129
130
		?>
131
		<tr valign="top">
132
			<th scope="row" class="titledesc"><?php esc_html_e( 'Account details:', 'woocommerce' ); ?></th>
133
			<td class="forminp" id="bacs_accounts">
134
				<div class="wc_input_table_wrapper">
135
					<table class="widefat wc_input_table sortable" cellspacing="0">
136
						<thead>
137
							<tr>
138
								<th class="sort">&nbsp;</th>
139
								<th><?php esc_html_e( 'Account name', 'woocommerce' ); ?></th>
140
								<th><?php esc_html_e( 'Account number', 'woocommerce' ); ?></th>
141
								<th><?php esc_html_e( 'Bank name', 'woocommerce' ); ?></th>
142
								<th><?php echo esc_html( $sortcode ); ?></th>
143
								<th><?php esc_html_e( 'IBAN', 'woocommerce' ); ?></th>
144
								<th><?php esc_html_e( 'BIC / Swift', 'woocommerce' ); ?></th>
145
							</tr>
146
						</thead>
147
						<tbody class="accounts">
148
							<?php
149
							$i = -1;
150
							if ( $this->account_details ) {
151
								foreach ( $this->account_details as $account ) {
152
									$i++;
153
154
									echo '<tr class="account">
155
										<td class="sort"></td>
156
										<td><input type="text" value="' . esc_attr( wp_unslash( $account['account_name'] ) ) . '" name="bacs_account_name[' . esc_attr( $i ) . ']" /></td>
157
										<td><input type="text" value="' . esc_attr( $account['account_number'] ) . '" name="bacs_account_number[' . esc_attr( $i ) . ']" /></td>
158
										<td><input type="text" value="' . esc_attr( wp_unslash( $account['bank_name'] ) ) . '" name="bacs_bank_name[' . esc_attr( $i ) . ']" /></td>
159
										<td><input type="text" value="' . esc_attr( $account['sort_code'] ) . '" name="bacs_sort_code[' . esc_attr( $i ) . ']" /></td>
160
										<td><input type="text" value="' . esc_attr( $account['iban'] ) . '" name="bacs_iban[' . esc_attr( $i ) . ']" /></td>
161
										<td><input type="text" value="' . esc_attr( $account['bic'] ) . '" name="bacs_bic[' . esc_attr( $i ) . ']" /></td>
162
									</tr>';
163
								}
164
							}
165
							?>
166
						</tbody>
167
						<tfoot>
168
							<tr>
169
								<th colspan="7"><a href="#" class="add button"><?php esc_html_e( '+ Add account', 'woocommerce' ); ?></a> <a href="#" class="remove_rows button"><?php esc_html_e( 'Remove selected account(s)', 'woocommerce' ); ?></a></th>
170
							</tr>
171
						</tfoot>
172
					</table>
173
				</div>
174
				<script type="text/javascript">
175
					jQuery(function() {
176
						jQuery('#bacs_accounts').on( 'click', 'a.add', function(){
177
178
							var size = jQuery('#bacs_accounts').find('tbody .account').length;
179
180
							jQuery('<tr class="account">\
181
									<td class="sort"></td>\
182
									<td><input type="text" name="bacs_account_name[' + size + ']" /></td>\
183
									<td><input type="text" name="bacs_account_number[' + size + ']" /></td>\
184
									<td><input type="text" name="bacs_bank_name[' + size + ']" /></td>\
185
									<td><input type="text" name="bacs_sort_code[' + size + ']" /></td>\
186
									<td><input type="text" name="bacs_iban[' + size + ']" /></td>\
187
									<td><input type="text" name="bacs_bic[' + size + ']" /></td>\
188
								</tr>').appendTo('#bacs_accounts table tbody');
189
190
							return false;
191
						});
192
					});
193
				</script>
194
			</td>
195
		</tr>
196
		<?php
197
		return ob_get_clean();
198
199
	}
200
201
	/**
202
	 * Save account details table.
203
	 */
204
	public function save_account_details() {
205
206
		$accounts = array();
207
208
		// phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification -- Nonce verification already handled in WC_Admin_Settings::save()
209
		if ( isset( $_POST['bacs_account_name'] ) && isset( $_POST['bacs_account_number'] ) && isset( $_POST['bacs_bank_name'] )
210
			 && isset( $_POST['bacs_sort_code'] ) && isset( $_POST['bacs_iban'] ) && isset( $_POST['bacs_bic'] ) ) {
211
212
			$account_names   = wc_clean( wp_unslash( $_POST['bacs_account_name'] ) );
213
			$account_numbers = wc_clean( wp_unslash( $_POST['bacs_account_number'] ) );
214
			$bank_names      = wc_clean( wp_unslash( $_POST['bacs_bank_name'] ) );
215
			$sort_codes      = wc_clean( wp_unslash( $_POST['bacs_sort_code'] ) );
216
			$ibans           = wc_clean( wp_unslash( $_POST['bacs_iban'] ) );
217
			$bics            = wc_clean( wp_unslash( $_POST['bacs_bic'] ) );
218
219
			foreach ( $account_names as $i => $name ) {
220
				if ( ! isset( $account_names[ $i ] ) ) {
221
					continue;
222
				}
223
224
				$accounts[] = array(
225
					'account_name'   => $account_names[ $i ],
226
					'account_number' => $account_numbers[ $i ],
227
					'bank_name'      => $bank_names[ $i ],
228
					'sort_code'      => $sort_codes[ $i ],
229
					'iban'           => $ibans[ $i ],
230
					'bic'            => $bics[ $i ],
231
				);
232
			}
233
		}
234
		// phpcs:enable
235
236
		update_option( 'woocommerce_bacs_accounts', $accounts );
237
	}
238
239
	/**
240
	 * Output for the order received page.
241
	 *
242
	 * @param int $order_id Order ID.
243
	 */
244
	public function thankyou_page( $order_id ) {
245
246
		if ( $this->instructions ) {
247
			echo wp_kses_post( wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ) );
248
		}
249
		$this->bank_details( $order_id );
250
251
	}
252
253
	/**
254
	 * Add content to the WC emails.
255
	 *
256
	 * @param WC_Order $order Order object.
257
	 * @param bool     $sent_to_admin Sent to admin.
258
	 * @param bool     $plain_text Email format: plain text or HTML.
259
	 */
260
	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
0 ignored issues
show
The parameter $plain_text is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
261
262
		if ( ! $sent_to_admin && 'bacs' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
263
			if ( $this->instructions ) {
264
				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
265
			}
266
			$this->bank_details( $order->get_id() );
267
		}
268
269
	}
270
271
	/**
272
	 * Get bank details and place into a list format.
273
	 *
274
	 * @param int $order_id Order ID.
275
	 */
276
	private function bank_details( $order_id = '' ) {
277
278
		if ( empty( $this->account_details ) ) {
279
			return;
280
		}
281
282
		// Get order and store in $order.
283
		$order = wc_get_order( $order_id );
284
285
		// Get the order country and country $locale.
286
		$country = $order->get_billing_country();
287
		$locale  = $this->get_country_locale();
288
289
		// Get sortcode label in the $locale array and use appropriate one.
290
		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
291
292
		$bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details );
293
294
		if ( ! empty( $bacs_accounts ) ) {
295
			$account_html = '';
296
			$has_details  = false;
297
298
			foreach ( $bacs_accounts as $bacs_account ) {
299
				$bacs_account = (object) $bacs_account;
300
301
				if ( $bacs_account->account_name ) {
302
					$account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;
303
				}
304
305
				$account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;
306
307
				// BACS account fields shown on the thanks page and in emails.
308
				$account_fields = apply_filters(
309
					'woocommerce_bacs_account_fields',
310
					array(
311
						'bank_name'      => array(
312
							'label' => __( 'Bank', 'woocommerce' ),
313
							'value' => $bacs_account->bank_name,
314
						),
315
						'account_number' => array(
316
							'label' => __( 'Account number', 'woocommerce' ),
317
							'value' => $bacs_account->account_number,
318
						),
319
						'sort_code'      => array(
320
							'label' => $sortcode,
321
							'value' => $bacs_account->sort_code,
322
						),
323
						'iban'           => array(
324
							'label' => __( 'IBAN', 'woocommerce' ),
325
							'value' => $bacs_account->iban,
326
						),
327
						'bic'            => array(
328
							'label' => __( 'BIC', 'woocommerce' ),
329
							'value' => $bacs_account->bic,
330
						),
331
					),
332
					$order_id
333
				);
334
335
				foreach ( $account_fields as $field_key => $field ) {
336
					if ( ! empty( $field['value'] ) ) {
337
						$account_html .= '<li class="' . esc_attr( $field_key ) . '">' . wp_kses_post( $field['label'] ) . ': <strong>' . wp_kses_post( wptexturize( $field['value'] ) ) . '</strong></li>' . PHP_EOL;
338
						$has_details   = true;
339
					}
340
				}
341
342
				$account_html .= '</ul>';
343
			}
344
345
			if ( $has_details ) {
346
				echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . esc_html__( 'Our bank details', 'woocommerce' ) . '</h2>' . wp_kses_post( PHP_EOL . $account_html ) . '</section>';
347
			}
348
		}
349
350
	}
351
352
	/**
353
	 * Process the payment and return the result.
354
	 *
355
	 * @param int $order_id Order ID.
356
	 * @return array
357
	 */
358 View Code Duplication
	public function process_payment( $order_id ) {
359
360
		$order = wc_get_order( $order_id );
361
362
		if ( $order->get_total() > 0 ) {
363
			// Mark as on-hold (we're awaiting the payment).
364
			$order->update_status( apply_filters( 'woocommerce_bacs_process_payment_order_status', 'on-hold', $order ), __( 'Awaiting BACS payment', 'woocommerce' ) );
365
		} else {
366
			$order->payment_complete();
367
		}
368
369
		// Remove cart.
370
		WC()->cart->empty_cart();
371
372
		// Return thankyou redirect.
373
		return array(
374
			'result'   => 'success',
375
			'redirect' => $this->get_return_url( $order ),
376
		);
377
378
	}
379
380
	/**
381
	 * Get country locale if localized.
382
	 *
383
	 * @return array
384
	 */
385
	public function get_country_locale() {
386
387
		if ( empty( $this->locale ) ) {
388
389
			// Locale information to be used - only those that are not 'Sort Code'.
390
			$this->locale = apply_filters(
391
				'woocommerce_get_bacs_locale',
392
				array(
393
					'AU' => array(
394
						'sortcode' => array(
395
							'label' => __( 'BSB', 'woocommerce' ),
396
						),
397
					),
398
					'CA' => array(
399
						'sortcode' => array(
400
							'label' => __( 'Bank transit number', 'woocommerce' ),
401
						),
402
					),
403
					'IN' => array(
404
						'sortcode' => array(
405
							'label' => __( 'IFSC', 'woocommerce' ),
406
						),
407
					),
408
					'IT' => array(
409
						'sortcode' => array(
410
							'label' => __( 'Branch sort', 'woocommerce' ),
411
						),
412
					),
413
					'NZ' => array(
414
						'sortcode' => array(
415
							'label' => __( 'Bank code', 'woocommerce' ),
416
						),
417
					),
418
					'SE' => array(
419
						'sortcode' => array(
420
							'label' => __( 'Bank code', 'woocommerce' ),
421
						),
422
					),
423
					'US' => array(
424
						'sortcode' => array(
425
							'label' => __( 'Routing number', 'woocommerce' ),
426
						),
427
					),
428
					'ZA' => array(
429
						'sortcode' => array(
430
							'label' => __( 'Branch code', 'woocommerce' ),
431
						),
432
					),
433
				)
434
			);
435
436
		}
437
438
		return $this->locale;
439
440
	}
441
}
442