mirror of
https://github.com/10h30/woo-viet.git
synced 2026-07-11 18:56:13 +09:00
Reformat code by PHPStorm
This commit is contained in:
@@ -92,7 +92,8 @@ class WooViet_Admin_Page {
|
||||
<th scope="row"><?php _e( 'Add the OnePay Domestic Gateway', 'woo-viet' ) ?></th>
|
||||
<td>
|
||||
<input name="settings[add_onepay_domestic][enabled]" type="hidden" value="no">
|
||||
<input name="settings[add_onepay_domestic][enabled]" type="checkbox" id="add_onepay_domestic" value="yes"
|
||||
<input name="settings[add_onepay_domestic][enabled]" type="checkbox"
|
||||
id="add_onepay_domestic" value="yes"
|
||||
<?php if ( 'yes' == $settings['add_onepay_domestic']['enabled'] )
|
||||
echo 'checked="checked"' ?>>
|
||||
<label for="add_onepay_domestic"><?php _e( 'Enabled', 'woo-viet' ) ?></label>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The class to handle the domestic OnePay gateway https://mtf.onepay.vn/developer/?page=modul_noidia
|
||||
*
|
||||
@@ -10,7 +11,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* @since 1.3
|
||||
*
|
||||
*/
|
||||
|
||||
class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
/**
|
||||
* Constructor for the gateway.
|
||||
@@ -40,7 +40,10 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
$this->password = $this->get_option( 'password' );
|
||||
|
||||
// Process the admin options
|
||||
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array(
|
||||
$this,
|
||||
'process_admin_options'
|
||||
) );
|
||||
|
||||
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'handle_onepay_return_url' ) );
|
||||
|
||||
@@ -49,6 +52,7 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
// @todo: check whether or not this can be lodded in the cron job
|
||||
add_action( 'wooviet_handle_onepay_querydr', array( $this, 'handle_onepay_querydr' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise Gateway Settings Form Fields.
|
||||
*/
|
||||
@@ -56,40 +60,36 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
$this->form_fields = include( 'onepay/domestic-settings.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the IPN URL for OnePay
|
||||
* Format: http://my-site.com/wc-api/WooViet_OnePay_Domestic/
|
||||
*/
|
||||
static function get_onepay_ipn_url() {
|
||||
return WC()->api_request_url( __CLASS__ );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the payment
|
||||
*
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function process_payment( $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => $this->get_pay_url( $order )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cron job running queryDR in 20 mintues
|
||||
* Because the OnePay payment timeout is 15 minutes
|
||||
*
|
||||
* @param string $vpc_MerchTxnRef
|
||||
*/
|
||||
public function set_onepay_querydr_cron( $vpc_MerchTxnRef ) {
|
||||
|
||||
wp_schedule_single_event(
|
||||
time() + 20 * 60,
|
||||
'wooviet_handle_onepay_querydr',
|
||||
array( $vpc_MerchTxnRef ) // @todo check this
|
||||
);
|
||||
|
||||
}
|
||||
/**
|
||||
* Get the OnePay pay URL for an order
|
||||
* AND set the queryDR cron for this transaction
|
||||
*
|
||||
* @param WC_Order $order
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_pay_url( $order ) {
|
||||
@@ -130,11 +130,19 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the IPN URL for OnePay
|
||||
* Format: http://my-site.com/wc-api/WooViet_OnePay_Domestic/
|
||||
* Set the cron job running queryDR in 20 mintues
|
||||
* Because the OnePay payment timeout is 15 minutes
|
||||
*
|
||||
* @param string $vpc_MerchTxnRef
|
||||
*/
|
||||
static function get_onepay_ipn_url(){
|
||||
return WC()->api_request_url( __CLASS__ );
|
||||
public function set_onepay_querydr_cron( $vpc_MerchTxnRef ) {
|
||||
|
||||
wp_schedule_single_event(
|
||||
time() + 20 * 60,
|
||||
'wooviet_handle_onepay_querydr',
|
||||
array( $vpc_MerchTxnRef ) // @todo check this
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,6 +150,7 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
* @see https://mtf.onepay.vn/developer/?page=modul_noidia_php
|
||||
*
|
||||
* @param array $args
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function create_vpc_SecureHash( $args ) {
|
||||
@@ -164,26 +173,6 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
return strtoupper( hash_hmac( 'SHA256', $stringHashData, pack( 'H*', $this->secure_secret ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the arguments and a provided $vpc_SecureHash are the same
|
||||
*
|
||||
* @see https://mtf.onepay.vn/developer/?page=modul_noidia_php
|
||||
*
|
||||
* @param $args
|
||||
* @param $vpc_SecureHash
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check_vpc_SecureHash ($args, $vpc_SecureHash) {
|
||||
// Generate the "vpc_SecureHash" value from $args
|
||||
$vpc_SecureHash_from_args = $this->create_vpc_SecureHash($args);
|
||||
|
||||
if ($vpc_SecureHash_from_args == $vpc_SecureHash ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handle the return URL - GET request from OnePay
|
||||
*/
|
||||
@@ -196,53 +185,9 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the IPN POST request from OnePay
|
||||
*/
|
||||
public function handle_onepay_ipn() {
|
||||
|
||||
if (isset($_REQUEST['vpc_SecureHash'])) {
|
||||
|
||||
$this->process_onepay_response_data( $_REQUEST, 'ipn' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the queryDR request
|
||||
* @param string $vpc_MerchTxnRef
|
||||
*/
|
||||
public function handle_onepay_querydr( $vpc_MerchTxnRef ) {
|
||||
// Build the queryDR link
|
||||
$args = array(
|
||||
'vpc_Command' => 'queryDR',
|
||||
'vpc_Version' => '1',
|
||||
'vpc_MerchTxnRef' => $vpc_MerchTxnRef,
|
||||
'vpc_Merchant' => $this->merchant_id,
|
||||
'vpc_AccessCode' => $this->access_code,
|
||||
'vpc_User' => $this->user,
|
||||
'vpc_Password' => $this->password,
|
||||
);
|
||||
|
||||
$http_args = http_build_query( $args, '', '&' );
|
||||
|
||||
if ( $this->testmode ) {
|
||||
$http_link = 'https://mtf.onepay.vn/onecomm-pay/Vpcdps.op?' . $http_args;
|
||||
} else {
|
||||
$http_link = 'https://onepay.vn/onecomm-pay/Vpcdps.op?' . $http_args;
|
||||
}
|
||||
|
||||
// Connect to OnePay to get the queryDR info
|
||||
$http_response = wp_remote_get( $http_link );
|
||||
parse_str( wp_remote_retrieve_body( $http_response ), $args_response );
|
||||
|
||||
// Process the data
|
||||
$this->process_onepay_response_data($args_response, 'querydr');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the repsonse data from OnePay
|
||||
*
|
||||
* @param string $args the response data from OnePay
|
||||
* @param string $type
|
||||
*/
|
||||
@@ -299,8 +244,9 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
$order->add_order_note( $order_note );
|
||||
|
||||
// If the payment is successful, update the order
|
||||
if ("0" == $vpc_TxnResponseCode )
|
||||
if ( "0" == $vpc_TxnResponseCode ) {
|
||||
$order->payment_complete();
|
||||
}
|
||||
|
||||
switch ( $type ) {
|
||||
|
||||
@@ -318,12 +264,34 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( 'ipn' == $type )
|
||||
if ( 'ipn' == $type ) {
|
||||
exit( 'responsecode=0&desc=confirm-success' );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the arguments and a provided $vpc_SecureHash are the same
|
||||
*
|
||||
* @see https://mtf.onepay.vn/developer/?page=modul_noidia_php
|
||||
*
|
||||
* @param $args
|
||||
* @param $vpc_SecureHash
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check_vpc_SecureHash( $args, $vpc_SecureHash ) {
|
||||
// Generate the "vpc_SecureHash" value from $args
|
||||
$vpc_SecureHash_from_args = $this->create_vpc_SecureHash( $args );
|
||||
|
||||
if ( $vpc_SecureHash_from_args == $vpc_SecureHash ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response description based on the response code
|
||||
* This is code is from OnePay
|
||||
@@ -383,7 +351,54 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
|
||||
default :
|
||||
$result = "Giao dịch thất bại - Failured";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the IPN POST request from OnePay
|
||||
*/
|
||||
public function handle_onepay_ipn() {
|
||||
|
||||
if ( isset( $_REQUEST['vpc_SecureHash'] ) ) {
|
||||
|
||||
$this->process_onepay_response_data( $_REQUEST, 'ipn' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the queryDR request
|
||||
*
|
||||
* @param string $vpc_MerchTxnRef
|
||||
*/
|
||||
public function handle_onepay_querydr( $vpc_MerchTxnRef ) {
|
||||
// Build the queryDR link
|
||||
$args = array(
|
||||
'vpc_Command' => 'queryDR',
|
||||
'vpc_Version' => '1',
|
||||
'vpc_MerchTxnRef' => $vpc_MerchTxnRef,
|
||||
'vpc_Merchant' => $this->merchant_id,
|
||||
'vpc_AccessCode' => $this->access_code,
|
||||
'vpc_User' => $this->user,
|
||||
'vpc_Password' => $this->password,
|
||||
);
|
||||
|
||||
$http_args = http_build_query( $args, '', '&' );
|
||||
|
||||
if ( $this->testmode ) {
|
||||
$http_link = 'https://mtf.onepay.vn/onecomm-pay/Vpcdps.op?' . $http_args;
|
||||
} else {
|
||||
$http_link = 'https://onepay.vn/onecomm-pay/Vpcdps.op?' . $http_args;
|
||||
}
|
||||
|
||||
// Connect to OnePay to get the queryDR info
|
||||
$http_response = wp_remote_get( $http_link );
|
||||
parse_str( wp_remote_retrieve_body( $http_response ), $args_response );
|
||||
|
||||
// Process the data
|
||||
$this->process_onepay_response_data( $args_response, 'querydr' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user