From 698fc6b77b1d70ea5a709d220702fad1e883ca76 Mon Sep 17 00:00:00 2001 From: htdat Date: Sun, 2 Apr 2017 16:32:42 +0700 Subject: [PATCH] Add the draft code for the 1Pay Bank Charging gateway --- inc/class-wooviet-1pay.php | 77 +++++++++++++++++++++++++++++++++++ inc/wooviet-1pay/settings.php | 40 ++++++++++++++++++ woo-viet.php | 13 ++++++ 3 files changed, 130 insertions(+) create mode 100644 inc/class-wooviet-1pay.php create mode 100644 inc/wooviet-1pay/settings.php diff --git a/inc/class-wooviet-1pay.php b/inc/class-wooviet-1pay.php new file mode 100644 index 0000000..8d2c901 --- /dev/null +++ b/inc/class-wooviet-1pay.php @@ -0,0 +1,77 @@ +id = 'wooviet_1pay'; + $this->has_fields = false; + $this->order_button_text = __( 'Proceed to 1Pay', 'woo-viet' ); + $this->method_title = __( '1Pay supported by Woo Viet', 'woo-viet' ); + + // @todo - check the method description + $this->method_description = __( '1Pay supported many ways for the payment in Vietnam - need to check!.', 'woo-viet' ); + $this->supports = array( + 'products', + 'refunds' + ); + + // Load the settings. + $this->init_form_fields(); + $this->init_settings(); + + // Define user set variables. + $this->title = $this->get_option( 'title' ); + $this->description = $this->get_option( 'description' ); + + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + + } + + + /** + * Initialise Gateway Settings Form Fields. + */ + public function init_form_fields() { + $this->form_fields = include( 'wooviet-1pay/settings.php' ); + } + + /** + * Process the payment. + */ + function process_payment( $order_id ) { + global $woocommerce; + $order = new WC_Order( $order_id ); + + // Mark as on-hold (we're awaiting the cheque) + $order->update_status('on-hold', __( 'Awaiting your payment', 'woo-viet' )); + + // Reduce stock levels + $order->reduce_order_stock(); + + // Remove cart + $woocommerce->cart->empty_cart(); + + // Return thankyou redirect + return array( + 'result' => 'success', + 'redirect' => $this->get_return_url( $order ) + ); + } +} + + diff --git a/inc/wooviet-1pay/settings.php b/inc/wooviet-1pay/settings.php new file mode 100644 index 0000000..c4f0aa9 --- /dev/null +++ b/inc/wooviet-1pay/settings.php @@ -0,0 +1,40 @@ + array( + 'title' => __( 'Enable/Disable', 'woo-viet' ), + 'type' => 'checkbox', + 'label' => __( '1Pay supported by Woo Viet', 'woo-viet' ), + 'default' => 'yes' + ), + 'title' => array( + 'title' => __( 'Title', 'woo-viet' ), + 'type' => 'text', + 'description' => __( 'This controls the title which the user sees during checkout.', 'woo-viet' ), + 'default' => __( '1Pay supported by Woo Viet', 'woo-viet' ), + 'desc_tip' => true, + ), + 'description' => array( + 'title' => __( 'Description', 'woo-viet' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => __( 'This controls the description which the user sees during checkout.', 'woo-viet' ), + 'default' => __( 'Pay via 1Pay; you can have many options to choose from.', 'woo-viet' ) + ), + 'email' => array( + 'title' => __( 'PayPal Email', 'woo-viet' ), + 'type' => 'email', + 'description' => __( 'Please enter your PayPal email address; this is needed in order to take payment.', 'woocommerce' ), + 'default' => get_option( 'admin_email' ), + 'desc_tip' => true, + 'placeholder' => 'you@youremail.com' + ), +); diff --git a/woo-viet.php b/woo-viet.php index e056150..97a300d 100644 --- a/woo-viet.php +++ b/woo-viet.php @@ -119,11 +119,24 @@ class WooViet { load_plugin_textdomain( 'woo-viet', false, basename( dirname( __FILE__ ) ) . '/languages/' ); } + + public function add_gateway_class( $methods ) { + $methods[] = 'WooViet_1Pay'; + return $methods; + + } + /** * The main method to load the components */ public function main() { + // @todo: ver 1.3 check this + add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway_class' ) ); + + include( 'inc/class-wooviet-1pay.php'); + + if ( is_admin() ) { // Add the admin setting page include( WOO_VIET_DIR . 'inc/class-wooviet-admin-page.php' );