Skip to content

Commit

Permalink
Merge pull request #32 from htdat/1.3.1-dev
Browse files Browse the repository at this point in the history
Merge 1.3.1
  • Loading branch information
htdat authored Jul 9, 2017
2 parents 12fae4d + 26d9e4b commit d6ecbfe
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 8 deletions.
Binary file added banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion inc/class-wooviet-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function admin_page_html() {
if ( 'VND' == get_woocommerce_currency() ) {
_e( 'OnePay can work on your site.', 'woo-viet' );
echo '<br/>';
echo sprintf( __( 'Please configure this gateway under <a href="%s">WooCommerce -> Settings -> Checkout</a>.', 'woo-viet' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) );
echo sprintf( __( 'Please configure this gateway under <a href="%s">WooCommerce -> Settings -> Checkout</a>.', 'woo-viet' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wooviet_onepay_domestic' ) );
} else {
_e( '<span style="color: red" ">This gateway is not active on your site. Because OnePay supports VND only.</span>', 'woo-viet' );
}
Expand Down
107 changes: 107 additions & 0 deletions inc/class-wooviet-notices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Manage the notices of the plugin
*
* @author htdat
* @since 1.3.1
*
*/
class WooViet_Notices {

var $settings = '';

static $default_settings = array(
'installation_time' => 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 = '<a href="https://goo.gl/forms/QIMkNrRIxgERBBcm2" target="_blank">tiếng Việt</a> - <a href="https://goo.gl/forms/N4GxvBtaIg6iryx43" target="_blank">English</a>';
$line5 = __( 'Dismiss this notice', 'woo-viet' );
$link = admin_url( 'admin.php?page=woo-viet&wooviet_dismiss=displaying_survey_after_4_weeks' );

printf( '
<div class="notice notice-success">
<p><strong>%1$s</strong></p>
<p><strong>
<a href="https://wordpress.org/support/plugin/woo-viet/reviews/?filter=5#new-post" target="_blank">%2$s</a> %3$s %4$s
</strong></p>
<p>
<a href="%6$s">%5$s</a>
</p>
</div>
', $line1, $line2, $line3, $line4, $line5, $link );
}

}
42 changes: 40 additions & 2 deletions inc/class-wooviet-onepay-domestic.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
*
*/
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.
*/
Expand Down Expand Up @@ -39,6 +45,9 @@ public function __construct() {
$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(
Expand Down Expand Up @@ -96,9 +105,9 @@ public function get_pay_url( $order ) {
'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
Expand All @@ -120,6 +129,10 @@ public function get_pay_url( $order ) {
$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 {
Expand Down Expand Up @@ -246,7 +259,11 @@ public function process_onepay_response_data( $args, $type ) {
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':
Expand Down Expand Up @@ -391,6 +408,10 @@ public function handle_onepay_querydr( $vpc_MerchTxnRef ) {
$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 );
Expand All @@ -400,4 +421,21 @@ public function handle_onepay_querydr( $vpc_MerchTxnRef ) {

}

/**
* 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 changes: 10 additions & 0 deletions inc/onepay/domestic-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,15 @@
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>' ),
),
/**
* @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>' ),
),

);
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand Down
12 changes: 9 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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/).
Expand All @@ -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 =

Expand Down Expand Up @@ -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/).

Expand Down
Binary file added screenshot-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions woo-viet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
*/

Expand Down Expand Up @@ -92,7 +92,7 @@ public function __construct() {
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( '<div class="%1$s"><p><strong>%2$s</strong></p></div>', $class, $message );
Expand Down Expand Up @@ -133,6 +133,10 @@ public function main() {
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();
Expand Down

0 comments on commit d6ecbfe

Please sign in to comment.