diff --git a/banner-772x250.png b/banner-772x250.png new file mode 100644 index 0000000..400d75b Binary files /dev/null and b/banner-772x250.png differ diff --git a/icon-128x128.png b/icon-128x128.png new file mode 100644 index 0000000..08819c0 Binary files /dev/null and b/icon-128x128.png differ diff --git a/inc/class-wooviet-admin-page.php b/inc/class-wooviet-admin-page.php index b022f64..4f10bc4 100644 --- a/inc/class-wooviet-admin-page.php +++ b/inc/class-wooviet-admin-page.php @@ -106,7 +106,7 @@ class WooViet_Admin_Page { if ( 'VND' == get_woocommerce_currency() ) { _e( 'OnePay can work on your site.', 'woo-viet' ); echo '
'; - echo sprintf( __( 'Please configure this gateway under WooCommerce -> Settings -> Checkout.', 'woo-viet' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ); + echo sprintf( __( 'Please configure this gateway under WooCommerce -> Settings -> Checkout.', 'woo-viet' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wooviet_onepay_domestic' ) ); } else { _e( 'This gateway is not active on your site. Because OnePay supports VND only.', 'woo-viet' ); } diff --git a/inc/class-wooviet-notices.php b/inc/class-wooviet-notices.php new file mode 100644 index 0000000..ebb0588 --- /dev/null +++ b/inc/class-wooviet-notices.php @@ -0,0 +1,107 @@ + 0, + 'displaying_survey_after_4_weeks' => 'not_yet', + ); + + /** + * WooViet_Notices constructor. + */ + public function __construct() { + $this->settings = self::get_settings(); + $this->set_installation_time(); + $this->manage_displaying_survey_after_4_weeks(); + + } + + public function get_settings() { + $settings = get_option( 'woo-viet_notices', self::$default_settings ); + $settings = wp_parse_args( $settings, self::$default_settings ); + + return $settings; + } + + /** + * Set the installation time + */ + public function set_installation_time() { + if ( ! $this->settings['installation_time'] ) { + $this->settings['installation_time'] = time(); + $this->save_settings(); + } + } + + /** + * Save settings for this classe + */ + public function save_settings() { + update_option( 'woo-viet_notices', $this->settings ); + } + + /** + * Manage the notice 'displaying_survey_after_4_weeks' + */ + public function manage_displaying_survey_after_4_weeks() { + $display_time = $this->settings['installation_time'] + ( 4 * 7 * 24 * 60 * 60 ); // 4 weeks; 7 days; 24 hours; 60 mins; 60 secs + + // Manage the dismiss action + if ( isset( $_GET['wooviet_dismiss'] ) + && + ( 'displaying_survey_after_4_weeks' == $_GET['wooviet_dismiss'] ) + ) { + $this->settings['displaying_survey_after_4_weeks'] = 'done'; + $this->save_settings(); + } + + // Display the message + if ( $display_time < time() && + 'not_yet' == $this->settings['displaying_survey_after_4_weeks'] + ) { + + add_action( 'admin_notices', array( $this, 'add_displaying_survey_after_4_weeks' ) ); + + } + } + + /** + * The HTML code to display in the admin notice + */ + public function add_displaying_survey_after_4_weeks() { + + $line1 = __( 'Please help us to improve Woo Viet.', 'woo-viet' ); + $line2 = __( 'Rate us!', 'woo-viet' ); + $line3 = __( 'Or run a short survery:', 'woo-viet' ); + $line4 = 'tiếng Việt - English'; + $line5 = __( 'Dismiss this notice', 'woo-viet' ); + $link = admin_url( 'admin.php?page=woo-viet&wooviet_dismiss=displaying_survey_after_4_weeks' ); + + printf( ' +
+

%1$s

+

+ %2$s %3$s %4$s +

+

+ %5$s +

+
+ ', $line1, $line2, $line3, $line4, $line5, $link ); + } + +} \ No newline at end of file diff --git a/inc/class-wooviet-onepay-domestic.php b/inc/class-wooviet-onepay-domestic.php index b5e1afb..ad39401 100644 --- a/inc/class-wooviet-onepay-domestic.php +++ b/inc/class-wooviet-onepay-domestic.php @@ -12,6 +12,12 @@ if ( ! defined( 'ABSPATH' ) ) { * */ 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. */ @@ -39,6 +45,9 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway { $this->secure_secret = $this->get_option( 'secure_secret' ); $this->user = $this->get_option( 'user' ); $this->password = $this->get_option( 'password' ); + $this->debug = 'yes' === $this->get_option( 'debug', 'no' ); + + self::$log_enabled = $this->debug; // Process the admin options add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( @@ -96,9 +105,9 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway { 'Title' => __( 'OnePay Payment Title', 'woo-viet' ), 'vpc_Merchant' => $this->merchant_id, 'vpc_AccessCode' => $this->access_code, - 'vpc_MerchTxnRef' => sprintf( '%1$s_%2$s', $order->id, date( 'YmdHis' ) ), + 'vpc_MerchTxnRef' => sprintf( '%1$s_%2$s', $order->get_id(), date( 'YmdHis' ) ), 'vpc_OrderInfo' => substr( - sprintf( 'Order #%1$s - %2$s', $order->id, get_home_url() ), + sprintf( 'Order #%1$s - %2$s', $order->get_id(), get_home_url() ), 0, 32 ), // Limit 32 characters 'vpc_Amount' => $order->get_total() * 100, // Multiplying 100 is a requirement from OnePay @@ -120,6 +129,10 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway { $args['vpc_SecureHash'] = $vpc_SecureHash; $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 ) { return 'https://mtf.onepay.vn/onecomm-pay/vpc.op?' . $http_args; } else { @@ -246,7 +259,11 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway { if ( "0" == $vpc_TxnResponseCode ) { $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 ) { 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; } + // 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 $http_response = wp_remote_get( $http_link ); 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__ ) ); + } + } + } diff --git a/inc/onepay/domestic-settings.php b/inc/onepay/domestic-settings.php index 9ac09bc..7dbadc5 100644 --- a/inc/onepay/domestic-settings.php +++ b/inc/onepay/domestic-settings.php @@ -89,5 +89,15 @@ return array( sprintf( 'URL: %s', WooViet_OnePay_Domestic::get_onepay_ipn_url() ) . '

' . sprintf( __( '%sContact OnePay%s to configure this URL on its site. This is required based on its guidelines.', 'woo-viet' ), '', '' ), ), + /** + * @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' ), '' . WC_Log_Handler_File::get_log_file_path( 'WooViet_OnePay_Domestic' ) . '' ), + ), ); \ No newline at end of file diff --git a/readme.md b/readme.md index 690b885..eb3db7a 100644 --- a/readme.md +++ b/readme.md @@ -74,6 +74,11 @@ Follow these steps to install and use the plugin: ## Changelog +### 1.3.1 - 2017.07.09 +* Improve the OnePay domestic gateway. +* Add the plugin icon and banner. +* Add the questionnaire after 4 weeks of installation. + ### 1.3 - 2017.04.22 * Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/) diff --git a/readme.txt b/readme.txt index 77f0a15..2dd7308 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: htdat Tags: OnePay WooCommerce, OnePay Vietnam, WooCommerce Vietnam, vietnam, vietnamese, vietnam provinces, paypal for vietnam dong, vnd, vietnam dong, vietnam currency, vietnam customization Requires at least: 4.3 Tested up to: 4.8 -Stable tag: 1.3 +Stable tag: 1.3.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -13,7 +13,7 @@ Add features to WooCommerce stores having anything related to Vietnam: currency, **"Woo Viet - WooCommerce for Vietnam" brings the features that help to run WooCommerce stores and customize them for Vietnam much easier.** -Xem phiên bản tiếng Việt tại đây https://vi.wordpress.org/plugins/woo-viet/ +Xem phiên bản tiếng Việt tại đây [https://vi.wordpress.org/plugins/woo-viet/](https://vi.wordpress.org/plugins/woo-viet/) **NEW FEATURE**: Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/). @@ -25,7 +25,7 @@ Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/). * Add districts to Vietnam provinces. * Convert `000` of prices to `K` (or anything). E.g: `50000` (VND) will be `50K` (VND), or `50 thousand` (VND). * Support `VND` for [the PayPal Standard gateway](https://docs.woocommerce.com/document/paypal-standard/). Convert `VND` prices to any PayPal supported currency before sending visitors to the PayPal pages. -* Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/). +* Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/). Implement all methods in [the official documents](https://mtf.onepay.vn/developer/?page=modul_noidia_php): QueryDR, IPN, and Return URL. = ROAD MAP = @@ -71,9 +71,15 @@ Follow these steps to install and use the plugin: 2. Prices are changed to "K", and the symbol is now "VND". 3. List provinces and districts when selecting Vietnam. 4. Let clients know about the currency conversion before switching to the PayPal pages. +5. OnePay domestic (local ATM cards) gateway. == Changelog == += 1.3.1 - 2017.07.092 = +* Improve the OnePay domestic gateway. +* Add the plugin icon and banner. +* Add the questionnaire after 4 weeks of installation. + = 1.3 - 2017.04.22 = * Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/). diff --git a/screenshot-5.png b/screenshot-5.png new file mode 100644 index 0000000..d37d681 Binary files /dev/null and b/screenshot-5.png differ diff --git a/woo-viet.php b/woo-viet.php index 522435d..60f0403 100644 --- a/woo-viet.php +++ b/woo-viet.php @@ -7,7 +7,7 @@ * Author URI: https://profiles.wordpress.org/htdat * Text Domain: woo-viet * Domain Path: /languages - * Version: 1.3 + * Version: 1.3.1 * License: GPLv2+ */ @@ -92,7 +92,7 @@ class WooViet { public function notice_if_not_woocommerce() { $class = 'notice notice-error'; - $message = __( 'Woo Viet is not running because WooCommerce is not active. Please activate both plugins', + $message = __( 'Woo Viet is not running because WooCommerce is not active. Please activate both plugins.', 'woo-viet' ); printf( '

%2$s

', $class, $message ); @@ -133,6 +133,10 @@ class WooViet { include( WOO_VIET_DIR . 'inc/class-wooviet-admin-page.php' ); $this->Admin_Page = new WooViet_Admin_Page(); + // Add the notices class + include( WOO_VIET_DIR . 'inc/class-wooviet-notices.php' ); + new WooViet_Notices(); + } $settings = self::get_settings();