mirror of
https://github.com/10h30/woo-viet.git
synced 2026-07-12 03:06:29 +09:00
Compare commits
3 Commits
1.2
...
1.3-dev-1pay-bank
| Author | SHA1 | Date | |
|---|---|---|---|
| bb53031bc7 | |||
| 6a753591e1 | |||
| 698fc6b77b |
@@ -0,0 +1,105 @@
|
||||
<?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_Bank extends WC_Payment_Gateway {
|
||||
|
||||
/**
|
||||
* Constructor for the gateway.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'wooviet_1pay_bank';
|
||||
$this->has_fields = false;
|
||||
$this->order_button_text = __( 'Proceed to 1Pay', 'woo-viet' );
|
||||
$this->method_title = __( '1Pay Bank (by Woo Viet)', 'woo-viet' );
|
||||
|
||||
// @todo - check the method description
|
||||
$this->method_description = __( '1Pay Bank supports all local banks 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->access_key = $this->get_option( 'access_key' );
|
||||
$this->secret = $this->get_option( 'secret' );
|
||||
|
||||
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.
|
||||
*/
|
||||
public function process_payment( $order_id ) {
|
||||
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => $this->get_pay_url( $order )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 1Pay 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());
|
||||
|
||||
$data = "access_key=".$access_key."&amount=".$amount."&command=".$command."&order_id=".$order_id."&order_info=".$order_info."&return_url=".$return_url;
|
||||
$signature = hash_hmac("sha256", $data, $secret);
|
||||
$data.= "&signature=".$signature;
|
||||
|
||||
// @todo: make the POST request to get pay_url
|
||||
/*
|
||||
$json_bankCharging = execPostRequest('http://api.1pay.vn/bank-charging/service', $data);
|
||||
//Ex: {"pay_url":"http://api.1pay.vn/bank-charging/sml/nd/order?token=LuNIFOeClp9d8SI7XWNG7O%2BvM8GsLAO%2BAHWJVsaF0%3D", "status":"init", "trans_ref":"16aa72d82f1940144b533e788a6bcb6"}
|
||||
$decode_bankCharging=json_decode($json_bankCharging,true); // decode json
|
||||
$pay_url = $decode_bankCharging["pay_url"];
|
||||
header("Location: $pay_url");
|
||||
*/
|
||||
}
|
||||
|
||||
public function get_1pay_return_url(){
|
||||
return WC()->api_request_url( __CLASS__ );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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 Bank (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 Bank', '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 1Pay 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 1Pay API credentials. Contact 1Pay to have your credentials %shere%s.', 'woo-viet' ), '<a href="https://1pay.vn/home/contact.html">', '</a>' ),
|
||||
),
|
||||
'access_key' => array(
|
||||
'title' => __( 'Access key', 'woo-viet' ),
|
||||
'type' => 'text',
|
||||
'description' => __( 'Get your access key from 1Pay.', 'woo-viet' ),
|
||||
'default' => '',
|
||||
'desc_tip' => true,
|
||||
'placeholder' => __( 'Required', 'woocommerce' )
|
||||
),
|
||||
'secret' => array(
|
||||
'title' => __( 'Secret', 'woocommerce' ),
|
||||
'type' => 'password',
|
||||
'description' => __( 'Get your 1Pay Secret info.', 'woo-viet' ),
|
||||
'default' => '',
|
||||
'desc_tip' => true,
|
||||
'placeholder' => __( 'Required', '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' )
|
||||
),
|
||||
*/
|
||||
|
||||
);
|
||||
@@ -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_Bank';
|
||||
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-bank.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