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.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / gateways / bacs / class-wc-gateway-bacs.php
woocommerce / includes / gateways / bacs Last commit date
class-wc-gateway-bacs.php 3 years ago
class-wc-gateway-bacs.php
463 lines
1 <?php
2 /**
3 * Class WC_Gateway_BACS file.
4 *
5 * @package WooCommerce\Gateways
6 */
7
8 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 * Gateway instructions that will be added to the thank you page and emails.
33 *
34 * @var string
35 */
36 public $instructions;
37
38 /**
39 * Account details.
40 *
41 * @var array
42 */
43 public $account_details;
44
45 /**
46 * Constructor for the gateway.
47 */
48 public function __construct() {
49
50 $this->id = 'bacs';
51 $this->icon = apply_filters( 'woocommerce_bacs_icon', '' );
52 $this->has_fields = false;
53 $this->method_title = __( 'Direct bank transfer', 'woocommerce' );
54 $this->method_description = __( 'Take payments in person via BACS. More commonly known as direct bank/wire transfer.', 'woocommerce' );
55
56 // Load the settings.
57 $this->init_form_fields();
58 $this->init_settings();
59
60 // Define user set variables.
61 $this->title = $this->get_option( 'title' );
62 $this->description = $this->get_option( 'description' );
63 $this->instructions = $this->get_option( 'instructions' );
64
65 // BACS account fields shown on the thanks page and in emails.
66 $this->account_details = get_option(
67 'woocommerce_bacs_accounts',
68 array(
69 array(
70 'account_name' => $this->get_option( 'account_name' ),
71 'account_number' => $this->get_option( 'account_number' ),
72 'sort_code' => $this->get_option( 'sort_code' ),
73 'bank_name' => $this->get_option( 'bank_name' ),
74 'iban' => $this->get_option( 'iban' ),
75 'bic' => $this->get_option( 'bic' ),
76 ),
77 )
78 );
79
80 // Actions.
81 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
82 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) );
83 add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) );
84
85 // Customer Emails.
86 add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
87 }
88
89 /**
90 * Initialise Gateway Settings Form Fields.
91 */
92 public function init_form_fields() {
93
94 $this->form_fields = array(
95 'enabled' => array(
96 'title' => __( 'Enable/Disable', 'woocommerce' ),
97 'type' => 'checkbox',
98 'label' => __( 'Enable bank transfer', 'woocommerce' ),
99 'default' => 'no',
100 ),
101 'title' => array(
102 'title' => __( 'Title', 'woocommerce' ),
103 'type' => 'safe_text',
104 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
105 'default' => __( 'Direct bank transfer', 'woocommerce' ),
106 'desc_tip' => true,
107 ),
108 'description' => array(
109 'title' => __( 'Description', 'woocommerce' ),
110 'type' => 'textarea',
111 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),
112 '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' ),
113 'desc_tip' => true,
114 ),
115 'instructions' => array(
116 'title' => __( 'Instructions', 'woocommerce' ),
117 'type' => 'textarea',
118 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),
119 'default' => '',
120 'desc_tip' => true,
121 ),
122 'account_details' => array(
123 'type' => 'account_details',
124 ),
125 );
126
127 }
128
129 /**
130 * Generate account details html.
131 *
132 * @return string
133 */
134 public function generate_account_details_html() {
135
136 ob_start();
137
138 $country = WC()->countries->get_base_country();
139 $locale = $this->get_country_locale();
140
141 // Get sortcode label in the $locale array and use appropriate one.
142 $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
143
144 ?>
145 <tr valign="top">
146 <th scope="row" class="titledesc"><?php esc_html_e( 'Account details:', 'woocommerce' ); ?></th>
147 <td class="forminp" id="bacs_accounts">
148 <div class="wc_input_table_wrapper">
149 <table class="widefat wc_input_table sortable" cellspacing="0">
150 <thead>
151 <tr>
152 <th class="sort">&nbsp;</th>
153 <th><?php esc_html_e( 'Account name', 'woocommerce' ); ?></th>
154 <th><?php esc_html_e( 'Account number', 'woocommerce' ); ?></th>
155 <th><?php esc_html_e( 'Bank name', 'woocommerce' ); ?></th>
156 <th><?php echo esc_html( $sortcode ); ?></th>
157 <th><?php esc_html_e( 'IBAN', 'woocommerce' ); ?></th>
158 <th><?php esc_html_e( 'BIC / Swift', 'woocommerce' ); ?></th>
159 </tr>
160 </thead>
161 <tbody class="accounts">
162 <?php
163 $i = -1;
164 if ( $this->account_details ) {
165 foreach ( $this->account_details as $account ) {
166 $i++;
167
168 echo '<tr class="account">
169 <td class="sort"></td>
170 <td><input type="text" value="' . esc_attr( wp_unslash( $account['account_name'] ) ) . '" name="bacs_account_name[' . esc_attr( $i ) . ']" /></td>
171 <td><input type="text" value="' . esc_attr( $account['account_number'] ) . '" name="bacs_account_number[' . esc_attr( $i ) . ']" /></td>
172 <td><input type="text" value="' . esc_attr( wp_unslash( $account['bank_name'] ) ) . '" name="bacs_bank_name[' . esc_attr( $i ) . ']" /></td>
173 <td><input type="text" value="' . esc_attr( $account['sort_code'] ) . '" name="bacs_sort_code[' . esc_attr( $i ) . ']" /></td>
174 <td><input type="text" value="' . esc_attr( $account['iban'] ) . '" name="bacs_iban[' . esc_attr( $i ) . ']" /></td>
175 <td><input type="text" value="' . esc_attr( $account['bic'] ) . '" name="bacs_bic[' . esc_attr( $i ) . ']" /></td>
176 </tr>';
177 }
178 }
179 ?>
180 </tbody>
181 <tfoot>
182 <tr>
183 <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>
184 </tr>
185 </tfoot>
186 </table>
187 </div>
188 <script type="text/javascript">
189 jQuery(function() {
190 jQuery('#bacs_accounts').on( 'click', 'a.add', function(){
191
192 var size = jQuery('#bacs_accounts').find('tbody .account').length;
193
194 jQuery('<tr class="account">\
195 <td class="sort"></td>\
196 <td><input type="text" name="bacs_account_name[' + size + ']" /></td>\
197 <td><input type="text" name="bacs_account_number[' + size + ']" /></td>\
198 <td><input type="text" name="bacs_bank_name[' + size + ']" /></td>\
199 <td><input type="text" name="bacs_sort_code[' + size + ']" /></td>\
200 <td><input type="text" name="bacs_iban[' + size + ']" /></td>\
201 <td><input type="text" name="bacs_bic[' + size + ']" /></td>\
202 </tr>').appendTo('#bacs_accounts table tbody');
203
204 return false;
205 });
206 });
207 </script>
208 </td>
209 </tr>
210 <?php
211 return ob_get_clean();
212
213 }
214
215 /**
216 * Save account details table.
217 */
218 public function save_account_details() {
219
220 $accounts = array();
221
222 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verification already handled in WC_Admin_Settings::save()
223 if ( isset( $_POST['bacs_account_name'] ) && isset( $_POST['bacs_account_number'] ) && isset( $_POST['bacs_bank_name'] )
224 && isset( $_POST['bacs_sort_code'] ) && isset( $_POST['bacs_iban'] ) && isset( $_POST['bacs_bic'] ) ) {
225
226 $account_names = wc_clean( wp_unslash( $_POST['bacs_account_name'] ) );
227 $account_numbers = wc_clean( wp_unslash( $_POST['bacs_account_number'] ) );
228 $bank_names = wc_clean( wp_unslash( $_POST['bacs_bank_name'] ) );
229 $sort_codes = wc_clean( wp_unslash( $_POST['bacs_sort_code'] ) );
230 $ibans = wc_clean( wp_unslash( $_POST['bacs_iban'] ) );
231 $bics = wc_clean( wp_unslash( $_POST['bacs_bic'] ) );
232
233 foreach ( $account_names as $i => $name ) {
234 if ( ! isset( $account_names[ $i ] ) ) {
235 continue;
236 }
237
238 $accounts[] = array(
239 'account_name' => $account_names[ $i ],
240 'account_number' => $account_numbers[ $i ],
241 'bank_name' => $bank_names[ $i ],
242 'sort_code' => $sort_codes[ $i ],
243 'iban' => $ibans[ $i ],
244 'bic' => $bics[ $i ],
245 );
246 }
247 }
248 // phpcs:enable
249
250 do_action( 'woocommerce_update_option', array( 'id' => 'woocommerce_bacs_accounts' ) );
251 update_option( 'woocommerce_bacs_accounts', $accounts );
252 }
253
254 /**
255 * Output for the order received page.
256 *
257 * @param int $order_id Order ID.
258 */
259 public function thankyou_page( $order_id ) {
260
261 if ( $this->instructions ) {
262 echo wp_kses_post( wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ) );
263 }
264 $this->bank_details( $order_id );
265
266 }
267
268 /**
269 * Add content to the WC emails.
270 *
271 * @param WC_Order $order Order object.
272 * @param bool $sent_to_admin Sent to admin.
273 * @param bool $plain_text Email format: plain text or HTML.
274 */
275 public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
276 /**
277 * Filter the email instructions order status.
278 *
279 * @since 7.4
280 * @param string $terms The order status.
281 * @param object $order The order object.
282 */
283 if ( ! $sent_to_admin && 'bacs' === $order->get_payment_method() && $order->has_status( apply_filters( 'woocommerce_bacs_email_instructions_order_status', 'on-hold', $order ) ) ) {
284 if ( $this->instructions ) {
285 echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
286 }
287 $this->bank_details( $order->get_id() );
288 }
289
290 }
291
292 /**
293 * Get bank details and place into a list format.
294 *
295 * @param int $order_id Order ID.
296 */
297 private function bank_details( $order_id = '' ) {
298
299 if ( empty( $this->account_details ) ) {
300 return;
301 }
302
303 // Get order and store in $order.
304 $order = wc_get_order( $order_id );
305
306 // Get the order country and country $locale.
307 $country = $order->get_billing_country();
308 $locale = $this->get_country_locale();
309
310 // Get sortcode label in the $locale array and use appropriate one.
311 $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
312
313 $bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details, $order_id );
314
315 if ( ! empty( $bacs_accounts ) ) {
316 $account_html = '';
317 $has_details = false;
318
319 foreach ( $bacs_accounts as $bacs_account ) {
320 $bacs_account = (object) $bacs_account;
321
322 if ( $bacs_account->account_name ) {
323 $account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;
324 }
325
326 $account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;
327
328 // BACS account fields shown on the thanks page and in emails.
329 $account_fields = apply_filters(
330 'woocommerce_bacs_account_fields',
331 array(
332 'bank_name' => array(
333 'label' => __( 'Bank', 'woocommerce' ),
334 'value' => $bacs_account->bank_name,
335 ),
336 'account_number' => array(
337 'label' => __( 'Account number', 'woocommerce' ),
338 'value' => $bacs_account->account_number,
339 ),
340 'sort_code' => array(
341 'label' => $sortcode,
342 'value' => $bacs_account->sort_code,
343 ),
344 'iban' => array(
345 'label' => __( 'IBAN', 'woocommerce' ),
346 'value' => $bacs_account->iban,
347 ),
348 'bic' => array(
349 'label' => __( 'BIC', 'woocommerce' ),
350 'value' => $bacs_account->bic,
351 ),
352 ),
353 $order_id
354 );
355
356 foreach ( $account_fields as $field_key => $field ) {
357 if ( ! empty( $field['value'] ) ) {
358 $account_html .= '<li class="' . esc_attr( $field_key ) . '">' . wp_kses_post( $field['label'] ) . ': <strong>' . wp_kses_post( wptexturize( $field['value'] ) ) . '</strong></li>' . PHP_EOL;
359 $has_details = true;
360 }
361 }
362
363 $account_html .= '</ul>';
364 }
365
366 if ( $has_details ) {
367 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>';
368 }
369 }
370
371 }
372
373 /**
374 * Process the payment and return the result.
375 *
376 * @param int $order_id Order ID.
377 * @return array
378 */
379 public function process_payment( $order_id ) {
380
381 $order = wc_get_order( $order_id );
382
383 if ( $order->get_total() > 0 ) {
384 // Mark as on-hold (we're awaiting the payment).
385 $order->update_status( apply_filters( 'woocommerce_bacs_process_payment_order_status', 'on-hold', $order ), __( 'Awaiting BACS payment', 'woocommerce' ) );
386 } else {
387 $order->payment_complete();
388 }
389
390 // Remove cart.
391 WC()->cart->empty_cart();
392
393 // Return thankyou redirect.
394 return array(
395 'result' => 'success',
396 'redirect' => $this->get_return_url( $order ),
397 );
398
399 }
400
401 /**
402 * Get country locale if localized.
403 *
404 * @return array
405 */
406 public function get_country_locale() {
407
408 if ( empty( $this->locale ) ) {
409
410 // Locale information to be used - only those that are not 'Sort Code'.
411 $this->locale = apply_filters(
412 'woocommerce_get_bacs_locale',
413 array(
414 'AU' => array(
415 'sortcode' => array(
416 'label' => __( 'BSB', 'woocommerce' ),
417 ),
418 ),
419 'CA' => array(
420 'sortcode' => array(
421 'label' => __( 'Bank transit number', 'woocommerce' ),
422 ),
423 ),
424 'IN' => array(
425 'sortcode' => array(
426 'label' => __( 'IFSC', 'woocommerce' ),
427 ),
428 ),
429 'IT' => array(
430 'sortcode' => array(
431 'label' => __( 'Branch sort', 'woocommerce' ),
432 ),
433 ),
434 'NZ' => array(
435 'sortcode' => array(
436 'label' => __( 'Bank code', 'woocommerce' ),
437 ),
438 ),
439 'SE' => array(
440 'sortcode' => array(
441 'label' => __( 'Bank code', 'woocommerce' ),
442 ),
443 ),
444 'US' => array(
445 'sortcode' => array(
446 'label' => __( 'Routing number', 'woocommerce' ),
447 ),
448 ),
449 'ZA' => array(
450 'sortcode' => array(
451 'label' => __( 'Branch code', 'woocommerce' ),
452 ),
453 ),
454 )
455 );
456
457 }
458
459 return $this->locale;
460
461 }
462 }
463