2011-08-10 17:11:11 +00:00
< ? php
2013-02-20 17:14:46 +00:00
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
2011-08-10 17:11:11 +00:00
/**
* Bank Transfer Payment Gateway
2012-08-15 18:15:06 +00:00
*
2011-09-22 14:14:55 +00:00
* Provides a Bank Transfer Payment Gateway . Based on code by Mike Pepper .
2011-08-10 17:11:11 +00:00
*
2012-12-31 18:25:09 +00:00
* @ class WC_Gateway_BACS
2012-08-15 18:15:06 +00:00
* @ extends WC_Payment_Gateway
2012-12-31 18:25:09 +00:00
* @ version 2.0 . 0
2012-08-15 18:15:06 +00:00
* @ package WooCommerce / Classes / Payment
* @ author WooThemes
2011-08-10 17:11:11 +00:00
*/
2012-12-31 18:25:09 +00:00
class WC_Gateway_BACS extends WC_Payment_Gateway {
2011-08-10 17:11:11 +00:00
2012-08-15 18:15:06 +00:00
/**
* Constructor for the gateway .
*
* @ access public
* @ return void
*/
public function __construct () {
2011-11-03 09:34:53 +00:00
$this -> id = 'bacs' ;
$this -> icon = apply_filters ( 'woocommerce_bacs_icon' , '' );
2011-09-22 14:14:55 +00:00
$this -> has_fields = false ;
2012-01-31 12:35:01 +00:00
$this -> method_title = __ ( 'Bacs' , 'woocommerce' );
2012-08-15 18:15:06 +00:00
2011-09-22 14:14:55 +00:00
// Load the settings.
2013-01-02 13:38:33 +00:00
$this -> init_form_fields ();
2011-09-22 14:14:55 +00:00
$this -> init_settings ();
2012-08-15 18:15:06 +00:00
2011-09-22 14:14:55 +00:00
// Define user set variables
2012-12-31 12:07:43 +00:00
$this -> title = $this -> get_option ( 'title' );
$this -> description = $this -> get_option ( 'description' );
$this -> account_name = $this -> get_option ( 'account_name' );
$this -> account_number = $this -> get_option ( 'account_number' );
$this -> sort_code = $this -> get_option ( 'sort_code' );
$this -> bank_name = $this -> get_option ( 'bank_name' );
$this -> iban = $this -> get_option ( 'iban' );
$this -> bic = $this -> get_option ( 'bic' );
2012-08-15 18:15:06 +00:00
2013-05-22 11:20:47 +00:00
// BACS account fields shown on the thanks page and in emails
$this -> account_fields = array (
'account_name' => __ ( 'Account Name' , 'woocommerce' ),
'account_number' => __ ( 'Account Number' , 'woocommerce' ),
'sort_code' => __ ( 'Sort Code' , 'woocommerce' ),
'bank_name' => __ ( 'Bank Name' , 'woocommerce' ),
'iban' => __ ( 'IBAN' , 'woocommerce' ),
'bic' => __ ( 'BIC' , 'woocommerce' )
);
2011-09-22 14:14:55 +00:00
// Actions
2012-12-31 18:25:09 +00:00
add_action ( 'woocommerce_update_options_payment_gateways_' . $this -> id , array ( $this , 'process_admin_options' ) );
2012-12-15 11:53:32 +00:00
add_action ( 'woocommerce_thankyou_bacs' , array ( $this , 'thankyou_page' ) );
2012-08-15 18:15:06 +00:00
2011-11-02 20:32:35 +00:00
// Customer Emails
2012-12-15 11:53:32 +00:00
add_action ( 'woocommerce_email_before_order_table' , array ( $this , 'email_instructions' ), 10 , 2 );
2012-08-15 18:15:06 +00:00
}
2011-08-10 17:11:11 +00:00
2012-08-15 18:15:06 +00:00
/**
2011-09-22 14:14:55 +00:00
* Initialise Gateway Settings Form Fields
2012-08-15 18:15:06 +00:00
*
* @ access public
* @ return void
2011-09-22 14:14:55 +00:00
*/
function init_form_fields () {
2012-08-15 18:15:06 +00:00
2013-04-16 09:58:03 +00:00
$this -> form_fields = array (
2011-09-22 14:14:55 +00:00
'enabled' => array (
2012-08-15 18:15:06 +00:00
'title' => __ ( 'Enable/Disable' , 'woocommerce' ),
'type' => 'checkbox' ,
'label' => __ ( 'Enable Bank Transfer' , 'woocommerce' ),
2011-09-22 14:14:55 +00:00
'default' => 'yes'
2012-08-15 18:15:06 +00:00
),
2011-09-22 14:14:55 +00:00
'title' => array (
2012-08-15 18:15:06 +00:00
'title' => __ ( 'Title' , 'woocommerce' ),
'type' => 'text' ,
'description' => __ ( 'This controls the title which the user sees during checkout.' , 'woocommerce' ),
2013-01-18 12:10:19 +00:00
'default' => __ ( 'Direct Bank Transfer' , 'woocommerce' ),
'desc_tip' => true ,
2011-09-22 14:14:55 +00:00
),
'description' => array (
2012-08-15 18:15:06 +00:00
'title' => __ ( 'Customer Message' , 'woocommerce' ),
'type' => 'textarea' ,
'description' => __ ( 'Give the customer instructions for paying via BACS, and let them know that their order won\'t be shipping until the money is received.' , 'woocommerce' ),
2012-10-16 09:45:33 +00:00
'default' => __ ( 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order wont be shipped until the funds have cleared in our account.' , 'woocommerce' )
2011-09-22 14:14:55 +00:00
),
2012-07-26 14:11:29 +00:00
'account_details' => array (
2012-08-15 18:15:06 +00:00
'title' => __ ( 'Account Details' , 'woocommerce' ),
'type' => 'title' ,
'description' => __ ( 'Optionally enter your bank details below for customers to pay into.' , 'woocommerce' ),
2012-07-26 14:11:29 +00:00
'default' => ''
),
2011-09-22 14:14:55 +00:00
'account_name' => array (
2013-04-16 09:58:03 +00:00
'title' => __ ( 'Account Name' , 'woocommerce' ),
2012-08-15 18:15:06 +00:00
'type' => 'text' ,
'description' => '' ,
2011-09-22 14:14:55 +00:00
'default' => ''
),
'account_number' => array (
2013-04-16 09:58:03 +00:00
'title' => __ ( 'Account Number' , 'woocommerce' ),
2012-08-15 18:15:06 +00:00
'type' => 'text' ,
'description' => '' ,
2011-09-22 14:14:55 +00:00
'default' => ''
),
'sort_code' => array (
2013-04-16 09:58:03 +00:00
'title' => __ ( 'Sort Code' , 'woocommerce' ),
2012-08-15 18:15:06 +00:00
'type' => 'text' ,
'description' => '' ,
2011-09-22 14:14:55 +00:00
'default' => ''
),
'bank_name' => array (
2013-04-16 09:58:03 +00:00
'title' => __ ( 'Bank Name' , 'woocommerce' ),
2012-08-15 18:15:06 +00:00
'type' => 'text' ,
'description' => '' ,
2011-09-22 14:14:55 +00:00
'default' => ''
),
'iban' => array (
2013-04-16 09:58:03 +00:00
'title' => __ ( 'IBAN' , 'woocommerce' ),
2012-08-15 18:15:06 +00:00
'type' => 'text' ,
2011-09-22 14:14:55 +00:00
'default' => ''
),
'bic' => array (
2013-04-16 09:58:03 +00:00
'title' => __ ( 'BIC (formerly Swift)' , 'woocommerce' ),
2012-08-15 18:15:06 +00:00
'type' => 'text' ,
2011-09-22 14:14:55 +00:00
'default' => ''
),
2011-08-10 17:11:11 +00:00
2013-04-16 09:58:03 +00:00
);
2012-08-15 18:15:06 +00:00
}
2011-09-22 14:14:55 +00:00
/**
2012-08-15 18:15:06 +00:00
* Admin Panel Options
2011-09-22 14:14:55 +00:00
* - Options for bits like 'title' and availability on a country - by - country basis
*
2012-08-15 18:15:06 +00:00
* @ access public
* @ return void
2011-09-22 14:14:55 +00:00
*/
public function admin_options () {
?>
2012-10-16 09:45:33 +00:00
< h3 >< ? php _e ( 'BACS Payment' , 'woocommerce' ); ?> </h3>
< p >< ? php _e ( 'Allows payments by BACS (Bank Account Clearing System), more commonly known as direct bank/wire transfer.' , 'woocommerce' ); ?> </p>
2011-09-22 14:14:55 +00:00
< table class = " form-table " >
< ? php
// Generate the HTML For the settings form.
$this -> generate_settings_html ();
?>
</ table ><!--/. form - table -->
< ? php
2012-08-15 18:15:06 +00:00
}
2011-08-10 17:11:11 +00:00
2012-08-15 18:15:06 +00:00
/**
* Output for the order received page .
*
* @ access public
* @ return void
*/
2013-05-22 11:20:47 +00:00
function thankyou_page ( $order_id ) {
2012-08-15 18:15:06 +00:00
if ( $description = $this -> get_description () )
2012-10-17 12:46:35 +00:00
echo wpautop ( wptexturize ( wp_kses_post ( $description ) ) );
2012-08-15 18:15:06 +00:00
2012-10-17 12:46:35 +00:00
echo '<h2>' . __ ( 'Our Details' , 'woocommerce' ) . '</h2>' ;
echo '<ul class="order_details bacs_details">' ;
2012-08-15 18:15:06 +00:00
2013-05-22 11:20:47 +00:00
$fields = apply_filters ( 'woocommerce_bacs_fields' , $this -> account_fields , $order_id );
2012-08-15 18:15:06 +00:00
2012-10-17 12:46:35 +00:00
foreach ( $fields as $key => $value ) {
if ( ! empty ( $this -> $key ) ) {
echo '<li class="' . esc_attr ( $key ) . '">' . esc_attr ( $value ) . ': <strong>' . wptexturize ( $this -> $key ) . '</strong></li>' ;
}
}
2012-08-15 18:15:06 +00:00
2012-10-17 12:46:35 +00:00
echo '</ul>' ;
2011-11-02 20:32:35 +00:00
}
2012-08-15 18:15:06 +00:00
2011-11-02 20:32:35 +00:00
/**
2012-08-15 18:15:06 +00:00
* Add content to the WC emails .
*
* @ access public
* @ param WC_Order $order
* @ param bool $sent_to_admin
* @ return void
*/
2011-11-02 20:32:35 +00:00
function email_instructions ( $order , $sent_to_admin ) {
2012-08-15 18:15:06 +00:00
2011-11-02 20:32:35 +00:00
if ( $sent_to_admin ) return ;
2012-08-15 18:15:06 +00:00
2011-11-02 20:32:35 +00:00
if ( $order -> status !== 'on-hold' ) return ;
2012-08-15 18:15:06 +00:00
2011-11-02 20:32:35 +00:00
if ( $order -> payment_method !== 'bacs' ) return ;
2012-08-15 18:15:06 +00:00
if ( $description = $this -> get_description () )
2012-06-29 18:44:33 +00:00
echo wpautop ( wptexturize ( $description ) );
2012-08-15 18:15:06 +00:00
2012-10-16 09:45:33 +00:00
?> <h2><?php _e( 'Our Details', 'woocommerce' ) ?></h2><ul class="order_details bacs_details"><?php
2012-08-15 18:15:06 +00:00
2013-05-22 11:20:47 +00:00
$fields = apply_filters ( 'woocommerce_bacs_fields' , $this -> account_fields , $order -> id );
2012-08-15 18:15:06 +00:00
2011-11-02 20:32:35 +00:00
foreach ( $fields as $key => $value ) :
2011-11-08 10:26:27 +00:00
if ( ! empty ( $this -> $key )) :
echo '<li class="' . $key . '">' . $value . ': <strong>' . wptexturize ( $this -> $key ) . '</strong></li>' ;
endif ;
2011-11-02 20:32:35 +00:00
endforeach ;
2012-08-15 18:15:06 +00:00
2011-11-02 20:32:35 +00:00
?> </ul><?php
2011-08-10 17:11:11 +00:00
}
2012-08-15 18:15:06 +00:00
2011-08-10 17:11:11 +00:00
/**
2012-08-15 18:15:06 +00:00
* Process the payment and return the result
*
* @ access public
* @ param int $order_id
* @ return array
*/
2011-08-10 17:11:11 +00:00
function process_payment ( $order_id ) {
2011-09-06 11:11:22 +00:00
global $woocommerce ;
2012-08-15 18:15:06 +00:00
2012-01-27 16:38:39 +00:00
$order = new WC_Order ( $order_id );
2012-08-15 18:15:06 +00:00
2011-09-06 11:11:22 +00:00
// Mark as on-hold (we're awaiting the payment)
2012-10-16 09:45:33 +00:00
$order -> update_status ( 'on-hold' , __ ( 'Awaiting BACS payment' , 'woocommerce' ));
2012-08-15 18:15:06 +00:00
2011-11-26 22:22:25 +00:00
// Reduce stock levels
$order -> reduce_order_stock ();
2011-09-06 11:11:22 +00:00
// Remove cart
$woocommerce -> cart -> empty_cart ();
2012-08-15 18:15:06 +00:00
2011-09-06 11:11:22 +00:00
// Return thankyou redirect
return array (
'result' => 'success' ,
2012-01-12 00:54:45 +00:00
'redirect' => add_query_arg ( 'key' , $order -> order_key , add_query_arg ( 'order' , $order -> id , get_permalink ( woocommerce_get_page_id ( 'thanks' ))))
2011-09-06 11:11:22 +00:00
);
2011-08-10 17:11:11 +00:00
}
2013-04-16 09:58:03 +00:00
}