The skeleton files for OnePay Domestic

This commit is contained in:
htdat
2017-04-17 21:46:56 +07:00
parent 7f87b70d6c
commit 3eeb71bf69
3 changed files with 170 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* The class to handle the domestic OnePay gateway https://mtf.onepay.vn/developer/?page=modul_noidia
*
*
* @author htdat
* @since 1.3
*
*/
class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->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__ );
}
*/
}
+71
View File
@@ -0,0 +1,71 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// @todo - ver 1.3 - check all texts
/**
* Settings for 1Pay Gateway.
*/
return array(
'enabled' => 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' ), '<a href="http://onepay.com.vn/home/en/contact-us.html">', '</a>' ),
),
'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' )
),
*/
);
+13
View File
@@ -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' );