Overview
  • Namespace
  • Class

Namespaces

  • None
  • WC_POS
    • Admin
      • Settings
        • Receipt
    • API
    • Gateways
    • Integrations
    • Products

Classes

  • WC_POS\Activator
  • WC_POS\Admin
  • WC_POS\Admin\Gateways
  • WC_POS\Admin\Menu
  • WC_POS\Admin\Notices
  • WC_POS\Admin\Orders
  • WC_POS\Admin\Page
  • WC_POS\Admin\Permalink
  • WC_POS\Admin\Plugins
  • WC_POS\Admin\Products
  • WC_POS\Admin\Settings
  • WC_POS\Admin\Settings\Access
  • WC_POS\Admin\Settings\Checkout
  • WC_POS\Admin\Settings\Customers
  • WC_POS\Admin\Settings\Gateways
  • WC_POS\Admin\Settings\General
  • WC_POS\Admin\Settings\HotKeys
  • WC_POS\Admin\Settings\Page
  • WC_POS\Admin\Settings\Receipt\Options
  • WC_POS\Admin\Settings\Receipt\Template
  • WC_POS\Admin\Settings\Receipts
  • WC_POS\Admin\Settings\Status
  • WC_POS\Admin\Settings\Tools
  • WC_POS\Admin\Status
  • WC_POS\Ajax
  • WC_POS\API
  • WC_POS\API\Coupons
  • WC_POS\API\Customers
  • WC_POS\API\Gateways
  • WC_POS\API\i18n
  • WC_POS\API\Orders
  • WC_POS\API\Params
  • WC_POS\API\Payload
  • WC_POS\API\Products
  • WC_POS\API\Settings
  • WC_POS\API\Support
  • WC_POS\API\Templates
  • WC_POS\Customers
  • WC_POS\Deactivator
  • WC_POS\Gateways
  • WC_POS\Gateways\Card
  • WC_POS\Gateways\Cash
  • WC_POS\i18n
  • WC_POS\Integrations\Bookings
  • WC_POS\Products
  • WC_POS\Products\Visibility
  • WC_POS\Setup
  • WC_POS\Status
  • WC_POS\Tax
  • WC_POS\Template

Functions

  • is_pos
  • is_pos_admin
  • wc_pos_get_option
  • wc_pos_json_encode
  • wc_pos_locate_template
  • wc_pos_trim_html_string
  • wc_pos_update_option
  • wc_pos_url
  1 <?php
  2 
  3 /**
  4  * Provides a Cash Payment Gateway.
  5  *
  6  * @class       WC_POS_Gateways_Cash
  7  * @package     WooCommerce POS
  8  * @author      Paul Kilmurray <paul@kilbot.com.au>
  9  * @link        http://www.woopos.com.au
 10  * @extends     WC_Payment_Gateway
 11  */
 12 
 13 namespace WC_POS\Gateways;
 14 
 15 use WC_Order;
 16 use WC_Payment_Gateway;
 17 use WC_POS\API;
 18 
 19 class Cash extends WC_Payment_Gateway {
 20 
 21   /**
 22    * Constructor for the gateway.
 23    */
 24   public function __construct() {
 25     $this->id          = 'pos_cash';
 26     $this->title       = __( 'Cash', 'woocommerce-pos' );
 27     $this->description = '';
 28     $this->icon        = apply_filters( 'woocommerce_pos_cash_icon', '' );
 29     $this->has_fields  = true;
 30 
 31     // Actions
 32     add_action( 'woocommerce_pos_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
 33     add_action( 'woocommerce_thankyou_pos_cash', array( $this, 'calculate_change' ) );
 34   }
 35 
 36   /**
 37    * Display the payment fields on the checkout modal
 38    */
 39   public function payment_fields() {
 40 
 41     if ( $this->description ) {
 42       echo '<p>' . wp_kses_post( $this->description ) . '</p>';
 43     }
 44 
 45     $currency_pos = get_option( 'woocommerce_currency_pos' );
 46 
 47     if( $currency_pos == 'left' || 'left_space') {
 48       $left_addon = '<span class="input-group-addon">'. get_woocommerce_currency_symbol( get_woocommerce_currency() ) .'</span>';
 49       $right_addon = '';
 50     } else {
 51       $left_addon = '';
 52       $right_addon = '<span class="input-group-addon">'. get_woocommerce_currency_symbol( get_woocommerce_currency() ) .'</span>';
 53     }
 54 
 55 
 56     echo '
 57       <div class="form-row" id="pos-cash-tendered_field">
 58         <label for="pos-cash-tendered" class="">'. __('Amount Tendered', 'woocommerce-pos') .'</label>
 59         <div class="input-group">
 60         '. $left_addon .'
 61           <input type="text" class="form-control" name="pos-cash-tendered" id="pos-cash-tendered" maxlength="20" data-numpad="cash" data-label="'. __('Amount Tendered', 'woocommerce-pos') .'" data-placement="bottom" data-value="{{total}}">
 62         '. $right_addon .'
 63         </div>
 64       </div>
 65     ';
 66 
 67   }
 68 
 69   public function process_payment( $order_id ) {
 70 
 71     // get order object
 72     $order = new WC_Order( $order_id );
 73 
 74     // update pos_cash data
 75     $data = API::get_raw_data();
 76     $tendered = isset( $data['payment_details']['pos-cash-tendered'] ) ? wc_format_decimal( $data['payment_details']['pos-cash-tendered'] ) : 0 ;
 77     $change = isset( $data['payment_details']['pos-cash-change'] ) ? wc_format_decimal( $data['payment_details']['pos-cash-change'] ) : 0 ;
 78     update_post_meta( $order_id, '_pos_cash_amount_tendered', $tendered );
 79     update_post_meta( $order_id, '_pos_cash_change', $change );
 80 
 81     // payment complete
 82     $order->payment_complete();
 83 
 84     // Return thankyou redirect
 85     return array(
 86       'result' => 'success'
 87     );
 88   }
 89 
 90   public function calculate_change( $order_id ) {
 91     $message = '';
 92     $tendered = get_post_meta( $order_id, '_pos_cash_amount_tendered', true );
 93     $change = get_post_meta( $order_id, '_pos_cash_change', true );
 94 
 95     // construct message
 96     if( $tendered && $change ) {
 97       $message = __('Amount Tendered', 'woocommerce-pos') .': ';
 98       $message .= wc_price($tendered) .'<br>';
 99       $message .= _x('Change', 'Money returned from cash sale', 'woocommerce-pos') .': ';
100       $message .= wc_price($change);
101     }
102 
103     echo $message;
104   }
105 
106   static public function payment_details( $order ) {
107     return array(
108       'tendered'  => get_post_meta( $order->id, '_pos_cash_amount_tendered', true ),
109       'change'    => get_post_meta( $order->id, '_pos_cash_change', true )
110     );
111   }
112 
113 }
API documentation generated by ApiGen