Save the log. See the PayPal Standard gateway #24

This commit is contained in:
htdat
2017-07-02 17:59:13 +07:00
parent 2e4c7b6265
commit fac3a9709f
2 changed files with 48 additions and 0 deletions
+38
View File
@@ -12,6 +12,12 @@ if ( ! defined( 'ABSPATH' ) ) {
* *
*/ */
class WooViet_OnePay_Domestic extends WC_Payment_Gateway { class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
/** @var bool Whether or not logging is enabled */
public static $log_enabled = false;
/** @var WC_Logger Logger instance */
public static $log = false;
/** /**
* Constructor for the gateway. * Constructor for the gateway.
*/ */
@@ -39,6 +45,9 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
$this->secure_secret = $this->get_option( 'secure_secret' ); $this->secure_secret = $this->get_option( 'secure_secret' );
$this->user = $this->get_option( 'user' ); $this->user = $this->get_option( 'user' );
$this->password = $this->get_option( 'password' ); $this->password = $this->get_option( 'password' );
$this->debug = 'yes' === $this->get_option( 'debug', 'no' );
self::$log_enabled = $this->debug;
// Process the admin options // Process the admin options
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array(
@@ -120,6 +129,10 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
$args['vpc_SecureHash'] = $vpc_SecureHash; $args['vpc_SecureHash'] = $vpc_SecureHash;
$http_args = http_build_query( $args, '', '&' ); $http_args = http_build_query( $args, '', '&' );
// Log data
$message_log = sprintf('get_pay_url - Order ID: %1$s - http_args: %2$s', $order->get_id(), print_r($args, true) );
self::log( $message_log);
if ( $this->testmode ) { if ( $this->testmode ) {
return 'https://mtf.onepay.vn/onecomm-pay/vpc.op?' . $http_args; return 'https://mtf.onepay.vn/onecomm-pay/vpc.op?' . $http_args;
} else { } else {
@@ -246,7 +259,11 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
if ( "0" == $vpc_TxnResponseCode ) { if ( "0" == $vpc_TxnResponseCode ) {
$order->payment_complete(); $order->payment_complete();
} }
// Log data
$message_log = sprintf('process_onepay_response_data - Order ID: %1$s - Order Note: %2$s - http_args: %3$s', $order_id, $order_note, print_r($args, true) );
self::log( $message_log);
// Return the info
switch ( $type ) { switch ( $type ) {
case 'return': case 'return':
@@ -391,6 +408,10 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
$http_link = 'https://onepay.vn/onecomm-pay/Vpcdps.op?' . $http_args; $http_link = 'https://onepay.vn/onecomm-pay/Vpcdps.op?' . $http_args;
} }
// Log data
$message_log = sprintf('handle_onepay_querydr - http_link: %1$s - http_args: %2$s', $http_link, print_r($args, true) );
self::log( $message_log);
// Connect to OnePay to get the queryDR info // Connect to OnePay to get the queryDR info
$http_response = wp_remote_get( $http_link ); $http_response = wp_remote_get( $http_link );
parse_str( wp_remote_retrieve_body( $http_response ), $args_response ); parse_str( wp_remote_retrieve_body( $http_response ), $args_response );
@@ -400,4 +421,21 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
} }
/**
* Logging method. - Copied from the WC_Gateway_Paypal Class
*
* @since 1.3.1
* @param string $message Log message.
* @param string $level Optional. Default 'info'.
* emergency|alert|critical|error|warning|notice|info|debug
*/
public static function log( $message, $level = 'info' ) {
if ( self::$log_enabled ) {
if ( empty( self::$log ) ) {
self::$log = wc_get_logger();
}
self::$log->log( $level, $message, array( 'source' => __CLASS__ ) );
}
}
} }
+10
View File
@@ -89,5 +89,15 @@ return array(
sprintf( 'URL: <code>%s</code>', WooViet_OnePay_Domestic::get_onepay_ipn_url() ) . '<p/>' . sprintf( 'URL: <code>%s</code>', WooViet_OnePay_Domestic::get_onepay_ipn_url() ) . '<p/>' .
sprintf( __( '%sContact OnePay%s to configure this URL on its site. <strong>This is required based on its guidelines.</strong>', 'woo-viet' ), '<a href="http://onepay.com.vn/home/en/contact-us.html">', '</a>' ), sprintf( __( '%sContact OnePay%s to configure this URL on its site. <strong>This is required based on its guidelines.</strong>', 'woo-viet' ), '<a href="http://onepay.com.vn/home/en/contact-us.html">', '</a>' ),
), ),
/**
* @since 1.3.1
*/
'debug' => array(
'title' => __( 'Debug log', 'woo-viet' ),
'type' => 'checkbox',
'label' => __( 'Enable logging', 'woo-viet' ),
'default' => 'no',
'description' => sprintf( __( 'Log events, such as IPN requests, inside %s', 'woo-viet' ), '<code>' . WC_Log_Handler_File::get_log_file_path( 'WooViet_OnePay_Domestic' ) . '</code>' ),
),
); );