diff --git a/includes/gateways.php b/includes/gateways.php
index d12fee0c..7e26bb8f 100644
--- a/includes/gateways.php
+++ b/includes/gateways.php
@@ -53,7 +53,8 @@ public function payment_gateways( array $gateways ) {
return array_merge($gateways, array(
'WC_POS\Gateways\Cash',
- 'WC_POS\Gateways\Card'
+ 'WC_POS\Gateways\Card',
+ 'WC_POS\Gateways\Check'
));
}
@@ -64,9 +65,9 @@ public function payment_gateways( array $gateways ) {
*/
public function load_gateways( $gateways ) {
foreach( $gateways as $gateway ){
- $gateway->pos = in_array( $gateway->id, array( 'pos_cash', 'pos_card', 'paypal' ) );
+ $gateway->pos = in_array( $gateway->id, array( 'pos_cash', 'pos_card', 'pos_check', 'paypal' ) );
}
return $gateways;
}
-}
\ No newline at end of file
+}
diff --git a/includes/gateways/check.php b/includes/gateways/check.php
new file mode 100644
index 00000000..602db815
--- /dev/null
+++ b/includes/gateways/check.php
@@ -0,0 +1,133 @@
+
+ * @link http://www.wcpos.com
+ * @extends WC_Payment_Gateway
+ */
+
+ //Simply copied from card.php and all references to card were changed to check.
+
+namespace WC_POS\Gateways;
+
+use WC_Order;
+use WC_Payment_Gateway;
+use WC_POS\API;
+
+class Check extends WC_Payment_Gateway {
+
+ /**
+ * Constructor for the gateway.
+ */
+ public function __construct() {
+ $this->id = 'pos_check';
+ $this->title = __( 'Check', 'woocommerce-pos' );
+ $this->description = '';
+ $this->icon = apply_filters( 'woocommerce_pos_check_icon', '' );
+ $this->has_fields = true;
+
+ // Actions
+ add_action( 'woocommerce_pos_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
+ add_action( 'woocommerce_thankyou_pos_check', array( $this, 'calculate_cashback' ) );
+
+ }
+
+ /**
+ * Display the payment fields in the checkout
+ */
+ public function payment_fields() {
+
+ if ( $this->description ) {
+ echo '
' . wp_kses_post( $this->description ) . '
';
+ }
+
+ $currency_pos = get_option( 'woocommerce_currency_pos' );
+
+ if( $currency_pos == 'left' || 'left_space') {
+ $left_addon = ''. get_woocommerce_currency_symbol( get_woocommerce_currency() ) .'';
+ $right_addon = '';
+ } else {
+ $left_addon = '';
+ $right_addon = ''. get_woocommerce_currency_symbol( get_woocommerce_currency() ) .'';
+ }
+
+ echo '
+
+ ';
+
+ }
+
+ /**
+ * @param int $order_id
+ * @return array
+ */
+ public function process_payment( $order_id ) {
+
+ // get order object
+ $order = new WC_Order( $order_id );
+
+ // update pos_cash data
+ $data = API::get_raw_data();
+ $cashback = isset( $data['payment_details']['pos-cashback'] ) ? wc_format_decimal( $data['payment_details']['pos-cashback'] ) : 0 ;
+
+ if( $cashback !== 0 ) {
+
+ // add order meta
+ update_post_meta( $order_id, '_pos_check_cashback', $cashback );
+
+ // add cashback as fee line item
+ // TODO: this should be handled by $order->add_fee after WC 2.2
+ $item_id = wc_add_order_item( $order_id, array(
+ 'order_item_name' => __('Cashback', 'woocommerce-pos'),
+ 'order_item_type' => 'fee'
+ ) );
+
+ if ( $item_id ) {
+ wc_add_order_item_meta( $item_id, '_line_total', $cashback );
+ wc_add_order_item_meta( $item_id, '_line_tax', 0 );
+ wc_add_order_item_meta( $item_id, '_line_subtotal', $cashback );
+ wc_add_order_item_meta( $item_id, '_line_subtotal_tax', 0 );
+ wc_add_order_item_meta( $item_id, '_tax_class', 'zero-rate' );
+ }
+
+ // update the order total to include fee
+ $order_total = get_post_meta( $order_id, '_order_total', true );
+ $order_total += $cashback;
+ update_post_meta( $order_id, '_order_total', $order_total );
+
+ }
+
+ // payment complete
+ $order->payment_complete();
+
+ // success
+ return array(
+ 'result' => 'success'
+ );
+ }
+
+ public function calculate_cashback( $order_id ) {
+ $message = '';
+ $cashback = get_post_meta( $order_id, '_pos_check_cashback', true );
+
+ // construct message
+ if( $cashback ) {
+ $message = __('Cashback', 'woocommerce-pos') . ': ';
+ $message .= wc_price($cashback);
+ }
+
+ echo $message;
+ }
+
+}
diff --git a/languages/woocommerce-pos.pot b/languages/woocommerce-pos.pot
index 43ee6de6..fb149a63 100644
--- a/languages/woocommerce-pos.pot
+++ b/languages/woocommerce-pos.pot
@@ -444,6 +444,17 @@ msgstr ""
msgid "Amount Tendered"
msgstr ""
+#: includes/gateways/class-wc-pos-check.php:28
+msgid "Check"
+msgstr ""
+
+#: includes/gateways/class-wc-pos-check.php:60
+#: includes/gateways/class-wc-pos-check.php:63
+#: includes/gateways/class-wc-pos-check.php:92
+#: includes/gateways/class-wc-pos-check.php:126
+msgid "Cashback"
+msgstr ""
+
#: includes/products/class-wc-pos-visibility.php:23
msgid "POS & Online"
msgstr ""
@@ -613,4 +624,4 @@ msgstr ""
#: includes/views/print/tmpl-receipt.php:225
msgctxt "abbreviation for includes (tax)"
msgid "incl."
-msgstr ""
\ No newline at end of file
+msgstr ""