diff --git a/inc/class-wooviet-onepay-domestic.php b/inc/class-wooviet-onepay-domestic.php new file mode 100644 index 0000000..8a6666b --- /dev/null +++ b/inc/class-wooviet-onepay-domestic.php @@ -0,0 +1,86 @@ +id = 'wooviet_onepay_domestic'; + $this->has_fields = false; + $this->order_button_text = __( 'Proceed to OnePay', 'woo-viet' ); + $this->method_title = __( 'OnePay Domestic Gateway (by Woo Viet)', 'woo-viet' ); + // @todo - check the method description + $this->method_description = __( 'OnePay supports all major bank ATMs in Vietnam.', 'woo-viet' ); + $this->supports = array( + 'products', + ); + // 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' ); + $this->merchant_id = $this->get_option( 'merchant_id' ); + $this->access_code = $this->get_option( 'access_code' ); + $this->secure_secret = $this->get_option( 'secure_secret' ); + + // @todo: the sandbox option + + 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( 'onepay/domestic-settings.php' ); + } + /** + * Process the payment. + */ + public function process_payment( $order_id ) { + $order = wc_get_order( $order_id ); + return array( + 'result' => 'success', + 'redirect' => $this->get_pay_url( $order ) + ); + } + /** + * Get the OnePay pay URL for an order. + * @param WC_Order $order + * @return string + */ + public function get_pay_url ( $order ) { + $access_key = $this->access_key; + $secret = $this->secret; // require your secret key from 1pay + $return_url = $this->get_1pay_return_url(); + $command = 'request_transaction'; + $amount = $order->get_total(); // >10000 + $order_id = $order->id; + $order_info = sprintf( 'The payment for the order number %1$s on the site: %2$s', $order->id, get_home_url()); + + // @todo: review and see the file do.php in the demo files + + } + + // @todo review this function + /* + public function static get_return_url(){ + return WC()->api_request_url( __CLASS__ ); + } + */ +} diff --git a/inc/onepay/domestic-settings.php b/inc/onepay/domestic-settings.php new file mode 100644 index 0000000..baa53d4 --- /dev/null +++ b/inc/onepay/domestic-settings.php @@ -0,0 +1,71 @@ + array( + 'title' => __( 'Enable/Disable', 'woo-viet' ), + 'type' => 'checkbox', + 'label' => __( 'OnePay Domestic Gateway (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' => __( 'OnePay Domestic Gateway', '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' => __( 'With OnePay Bank, you can make payment by using any local Vietnam ATM card.', 'woo-viet' ) + ), + 'api_details' => array( + 'title' => __( 'API Credentials', 'woo-viet' ), + 'type' => 'title', + 'description' => sprintf( __( 'Enter your OnePay API credentials. Contact OnePay to have your credentials %shere%s.', 'woo-viet' ), '', '' ), + ), + 'merchant_id' => array( + 'title' => __( 'Merchant ID', 'woo-viet' ), + 'type' => 'text', + 'description' => __( 'Get your Merchant ID from OnePay.', 'woo-viet' ), + 'default' => '', + 'desc_tip' => true, + 'placeholder' => __( 'Required. Provided by OnePay.', 'woo-viet' ) + ), + 'access code' => array( + 'title' => __( 'Access Code', 'woocommerce' ), + 'type' => 'text', + 'description' => __( 'Get your Access Code from from OnePay.', 'woo-viet' ), + 'default' => '', + 'desc_tip' => true, + 'placeholder' => __( 'Required. Provided by OnePay.', 'woo-viet' ) + ), + 'secure_secret' => array( + 'title' => __( 'Secure Secret', 'woocommerce' ), + 'type' => 'text', + 'description' => __( 'Get your Secure Secret from from OnePay.', 'woo-viet' ), + 'default' => '', + 'desc_tip' => true, + 'placeholder' => __( 'Required. Provided by OnePay.', 'woo-viet' ) + ), + /* + // @todo: Add more help info later + + 'help_title' => array( + 'title' => __( 'More info about 1Pay', 'woo-viet' ), + 'type' => 'title', + 'description' => __( 'You can see more info at this link.', 'woo-viet' ) + ), + */ + +); \ No newline at end of file diff --git a/woo-viet.php b/woo-viet.php index e056150..2b4b469 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_OnePay_Domestic'; + 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-onepay-domestic.php'); + + if ( is_admin() ) { // Add the admin setting page include( WOO_VIET_DIR . 'inc/class-wooviet-admin-page.php' );