woocommerce/classes/gateways/gateway-cheque.php

123 lines
5.4 KiB
PHP
Raw Normal View History

2011-08-10 17:11:11 +00:00
<?php
/**
* Cheque Payment Gateway
*
* Provides a Cheque Payment Gateway for testing purposes. Created by Andrew Benbow (andrew@chromeorange.co.uk)
*
* @class woocommerce_cheque
* @package WooCommerce
* @category Payment Gateways
* @author WooThemes
*/
class woocommerce_cheque extends woocommerce_payment_gateway {
public function __construct() {
$this->id = 'cheque';
$this->icon = '';
$this->has_fields = false;
$this->enabled = get_option('woocommerce_cheque_enabled');
$this->title = get_option('woocommerce_cheque_title');
$this->description = get_option('woocommerce_cheque_description');
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
2011-08-10 17:11:11 +00:00
add_option('woocommerce_cheque_enabled', 'yes');
add_option('woocommerce_cheque_title', __('Cheque Payment', 'woothemes') );
add_option('woocommerce_cheque_description', __('Please send your cheque to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'woothemes'));
2011-09-21 15:15:55 +00:00
add_action('woocommerce_thankyou_cheque', array(&$this, 'thankyou_page'));
2011-08-10 17:11:11 +00:00
}
/**
* Admin Panel Options
* - Options for bits like 'title' and availability on a country-by-country basis
**/
public function admin_options() {
?>
2011-08-13 13:57:48 +00:00
<h3><?php _e('Cheque Payment', 'woothemes'); ?></h3>
<p><?php _e('Allows cheque payments. Why would you take cheques in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases without having to use the sandbox area of a payment gateway which is useful for demonstrating to clients and for testing order emails and the \'success\' pages etc.', 'woothemes'); ?></p>
<table class="form-table">
2011-08-18 23:14:35 +00:00
<tr valign="top">
2011-08-13 16:07:10 +00:00
<th scope="row" class="titledesc"><?php _e('Enable/disable', 'woothemes') ?></th>
2011-08-13 13:57:48 +00:00
<td class="forminp">
2011-08-13 16:07:10 +00:00
<fieldset><legend class="screen-reader-text"><span><?php _e('Enable/disable', 'woothemes') ?></span></legend>
<label for="woocommerce_cheque_enabled">
<input name="woocommerce_cheque_enabled" id="woocommerce_cheque_enabled" type="checkbox" value="1" <?php checked(get_option('woocommerce_cheque_enabled'), 'yes'); ?> /> <?php _e('Enable Cheque Payment', 'woothemes') ?></label><br>
</fieldset>
2011-08-13 13:57:48 +00:00
</td>
</tr>
2011-08-18 23:14:35 +00:00
<tr valign="top">
2011-08-13 16:07:10 +00:00
<th scope="row" class="titledesc"><?php _e('Method Title', 'woothemes') ?></th>
2011-08-13 13:57:48 +00:00
<td class="forminp">
2011-08-13 16:07:10 +00:00
<input class="input-text" type="text" name="woocommerce_cheque_title" id="woocommerce_cheque_title" value="<?php if ($value = get_option('woocommerce_cheque_title')) echo $value; else echo 'Cheque Payment'; ?>" /> <span class="description"><?php _e('This controls the title which the user sees during checkout.', 'woothemes') ?></span>
2011-08-13 13:57:48 +00:00
</td>
</tr>
2011-08-18 23:14:35 +00:00
<tr valign="top">
2011-08-13 16:07:10 +00:00
<th scope="row" class="titledesc"><?php _e('Customer Message', 'woothemes') ?></th>
2011-08-13 13:57:48 +00:00
<td class="forminp">
<input class="input-text wide-input" type="text" name="woocommerce_cheque_description" id="woocommerce_cheque_description" value="<?php echo esc_attr( get_option( 'woocommerce_cheque_description' ) ); ?>" /> <span class="description"><?php _e('Let the customer know the payee and where they should be sending the cheque too and that their order won\'t be shipping until you receive it.', 'woothemes') ?></span>
2011-08-13 13:57:48 +00:00
</td>
</tr>
</table>
2011-08-10 17:11:11 +00:00
<?php
}
/**
* There are no payment fields for cheques, but we want to show the description if set.
**/
function payment_fields() {
if ($this->description) echo wpautop(wptexturize($this->description));
}
function thankyou_page() {
if ($this->description) echo wpautop(wptexturize($this->description));
}
/**
* Admin Panel Options Processing
* - Saves the options to the DB
**/
public function process_admin_options() {
2011-08-13 16:07:10 +00:00
if(isset($_POST['woocommerce_cheque_enabled'])) update_option('woocommerce_cheque_enabled', 'yes'); else update_option('woocommerce_cheque_enabled', 'no');
2011-09-03 22:52:11 +00:00
if(isset($_POST['woocommerce_cheque_title'])) update_option('woocommerce_cheque_title', woocommerce_clean($_POST['woocommerce_cheque_title'])); else delete_option('woocommerce_cheque_title');
if(isset($_POST['woocommerce_cheque_description'])) update_option('woocommerce_cheque_description', woocommerce_clean($_POST['woocommerce_cheque_description'])); else delete_option('woocommerce_cheque_description');
2011-08-10 17:11:11 +00:00
}
/**
* Process the payment and return the result
**/
function process_payment( $order_id ) {
global $woocommerce;
2011-08-10 17:11:11 +00:00
$order = &new woocommerce_order( $order_id );
// Mark as on-hold (we're awaiting the cheque)
$order->update_status('on-hold', __('Awaiting cheque payment', 'woothemes'));
// Remove cart
$woocommerce->cart->empty_cart();
2011-08-11 22:39:02 +00:00
// Empty awaiting payment session
unset($_SESSION['order_awaiting_payment']);
2011-08-10 17:11:11 +00:00
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id'))))
);
}
}
/**
* Add the gateway to WooCommerce
**/
function add_cheque_gateway( $methods ) {
$methods[] = 'woocommerce_cheque'; return $methods;
}
add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );