mirror of
https://github.com/10h30/woo-viet.git
synced 2026-07-11 18:56:13 +09:00
Add the draft code for the 1Pay Bank Charging gateway
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The class to handle the payment gateway 1Pay https://1pay.vn/home/
|
||||
*
|
||||
*
|
||||
* @author htdat
|
||||
* @since 1.3
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class WooViet_1Pay extends WC_Payment_Gateway {
|
||||
/**
|
||||
* Constructor for the gateway.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->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 )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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' => __( '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'
|
||||
),
|
||||
);
|
||||
@@ -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' );
|
||||
|
||||
Reference in New Issue
Block a user