35 Commits

Author SHA1 Message Date
Dat Hoang 832d8ea491 Add the development version 1.4.3 2018-05-12 20:04:29 +07:00
Dat Hoang 12649806c3 Fix fatal error when handling PayPal IPN #56 2018-05-12 09:48:47 +00:00
Dat Hoang 690312dd87 Revert this commit 1ad14ee9b8. Wrong approach 2018-05-12 07:28:54 +00:00
Dat Hoang 98d2a83cb1 Update 1.4.2 - Fix the fatal error when WooCommerce PayPal Express Checkout Gateway is not active
Related #53 and #54
2018-04-26 16:48:46 +07:00
Dat Hoang 64bac93cdf Merge pull request #52 from htdat/1.4-dev
Merge 1.4-dev to master
2018-04-24 23:39:55 +07:00
Dat Hoang 705e944b4e Clean up the readme.md file
Keep the full change log only, other info should be found on WordPress.org page
2018-04-24 23:36:37 +07:00
Dat Hoang 4eeb5c8d60 Add change logs and update the version 2018-04-24 23:34:25 +07:00
Dat Hoang 2441ff16a9 Ingore PHPStorm files 2018-04-24 23:30:06 +07:00
longnguyen 68752ae215 Support PayPal Express Checkout #27 (#46) 2018-04-24 22:36:04 +07:00
Dat Hoang 9c371f6d74 Add the comment to make clear for "switch ( $type )" 2018-04-22 21:10:20 +07:00
longnguyen 0e4e78a89a Fix bug OnePay domestic gateway #45 (#50) 2018-04-22 21:04:26 +07:00
longnguyen fe71559879 Add Settings link when plugin is active #41 (#48) 2018-04-18 21:57:32 +07:00
Dat Hoang 09611435de Change the notice to "warning", which is more correct 2018-04-17 16:32:15 +07:00
Dat Hoang ae4743a2f2 Fix the small typo - #33 2018-04-16 22:41:16 +07:00
Dat Hoang 137f0d2ac8 Clarify the purpose of the scripts 2018-04-16 22:19:32 +07:00
longnguyen cf7bf361c1 Improve order checkout page #17 (#43)
Issue #17 - Arrange the address fields to the Vietnam standard: Country - Province - District - Address
2018-04-16 21:59:23 +07:00
Long 1ad14ee9b8 Fix Order status error #37 2018-04-08 10:42:57 +07:00
Dat Hoang b9d69bf546 Start verion 1.4 2018-04-05 22:43:46 +07:00
Dat Hoang 730d464214 Add thutp90, thanks for her contribution with the icon and banner. 2017-07-09 14:17:09 +07:00
Dat Hoang f7f0c49698 Update the wrong date for 1.3.1 2017-07-09 12:15:00 +07:00
Dat Hoang d6ecbfe806 Merge pull request #32 from htdat/1.3.1-dev
Merge 1.3.1
2017-07-09 11:54:20 +07:00
htdat 26d9e4ba24 Add the changeling, update the stable tag 2017-07-09 11:52:03 +07:00
htdat 6c333e5abe Create the plugin icon #11 2017-07-09 11:47:33 +07:00
htdat 187dd5bf2b Increase the version number 2017-07-03 23:59:33 +07:00
htdat c22f935e96 Update survey links - #29 2017-07-03 23:58:37 +07:00
htdat 4e78194ba9 Add the questionnaire after 4 weeks - the coding part - #29 2017-07-03 14:15:04 +07:00
htdat d44605827a Small grammar fix 2017-07-03 12:32:13 +07:00
htdat 83a1dafdf0 Add the screenshot for OnePay #24 2017-07-03 12:00:40 +07:00
htdat 0c43ee467d Fix: Error in WooCommerce 3.0.x - order->id - #24 2017-07-02 18:08:37 +07:00
htdat fac3a9709f Save the log. See the PayPal Standard gateway #24 2017-07-02 17:59:13 +07:00
htdat 2e4c7b6265 Improve the link to the OnePay setting 2017-07-02 16:27:43 +07:00
htdat 53eec6c1eb Add more notes about the plugin implementing QueryDR, IPN and Return URL. Make sure to follow all guides. #24 2017-07-02 16:26:37 +07:00
htdat 282734961a File readme.txt in the new design of WordPress.org #25 2017-07-02 16:05:53 +07:00
Dat Hoang 12fae4d63f Update the compatible tag 4.8 2017-06-18 18:10:14 +07:00
Dat Hoang ad1cda5d85 Update the compatible tag 4.8 2017-06-18 18:09:48 +07:00
16 changed files with 679 additions and 107 deletions
+4
View File
@@ -6,3 +6,7 @@ Thumbs.db
# Temporary folders
/_temp
# PHPStorm
/.idea
+48
View File
@@ -0,0 +1,48 @@
.woocommerce-billing-fields__field-wrapper.active {
display: flex;
flex-wrap: wrap;
}
#billing_first_name_field {
order: 1;
}
#billing_last_name_field {
order: 2;
}
#billing_company_field {
order: 3;
}
#billing_country_field {
order: 4;
}
#billing_state_field {
order: 5;
}
#billing_city_field {
order: 6;
}
#billing_address_1_field {
order: 7;
}
#billing_address_2_field {
order: 8;
}
#billing_postcode_field {
order: 9;
}
#billing_phone_field {
order: 10;
}
#billing_email_field {
order: 11;
}
+14
View File
@@ -0,0 +1,14 @@
(function($) {
$('#billing_country_field').on('change', function() {
// Get country code
var country_code = $(this).find('#billing_country').val();
// Match country code with Vietnam
if(country_code == 'VN') {
$('.woocommerce-billing-fields__field-wrapper').addClass('active');
} else {
$('.woocommerce-billing-fields__field-wrapper').removeClass('active');
}
})
})(jQuery)
Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

+37 -1
View File
@@ -106,7 +106,7 @@ class WooViet_Admin_Page {
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' );
}
@@ -239,6 +239,42 @@ class WooViet_Admin_Page {
</td>
</tr>
<tr>
<th scope="row"><?php printf( __( 'Support VND for <a href="%s">the PayPal Express Checkout gateway</a>', 'woo-viet' ), 'https://docs.woocommerce.com/document/paypal-express-checkout/' ) ?></th>
<td>
<input name="settings[vnd_paypal_express_checkout][enabled]" type="hidden" value="no">
<input name="settings[vnd_paypal_express_checkout][enabled]" type="checkbox"
id="vnd_paypal_express_checkout" value="yes"
<?php if ( 'yes' == $settings['vnd_paypal_express_checkout']['enabled'] )
echo 'checked="checked"' ?>>
<label for="vnd_paypal_express_checkout"><?php _e( 'Enabled', 'woo-viet' ) ?></label>
<fieldset><br/>
<select name="settings[vnd_paypal_express_checkout][currency]"
id="vnd_paypal_express_checkout_currency">
<?php
foreach ( $paypal_supported_currencies as $currency ) {
if ( strtoupper( $currency ) == $settings['vnd_paypal_express_checkout']['currency'] ) {
printf( '<option selected="selected" value="%1$s">%1$s</option>', $currency );
} else {
printf( '<option value="%1$s">%1$s</option>', $currency );
}
}
?>
</select>
<label for="vnd_paypal_express_checkout_currency"><?php _e( 'Select a PayPal supported currency (like USD, EUR, etc), which is used to convert VND prices', 'woo-viet' ) ?></label>
<br/>
<br/>
<input name="settings[vnd_paypal_express_checkout][rate]" type="number" step="1" min="100"
id="vnd_paypal_express_checkout_rate" style="width: 70px;"
value="<?php echo $settings['vnd_paypal_express_checkout']['rate'] ?>"
<label for="vnd_paypal_express_checkout_rate"><?php _e( 'Insert the exchange rate of this currency to VND', 'woo-viet' ) ?></label>
</fieldset>
</td>
</tr>
</tbody>
</table>
+107
View File
@@ -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 survey:', '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 );
}
}
+78 -8
View File
@@ -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 {
@@ -242,18 +255,54 @@ 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 ) {
$order->payment_complete();
// Do action for the order based on the response code from OnePay
// This is an intentional DRY switch - refer to #DRY_vpc_TxnResponseCode below
switch ( $vpc_TxnResponseCode ) {
case '0':
// If the payment is successful, update the order
$order->payment_complete();
break;
case '99':
// If the user cancels payment, cancel the order
$order->cancel_order();
break;
default:
// For other cases, do nothing. By default, the order status is still "Pending Payment"
break;
}
// 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);
// Do the last actions based on $type
switch ( $type ) {
case 'return':
wp_redirect( $this->get_return_url( $order ) );
case 'return': // Add info from OnePay and redirect to the appropriate URLs
wc_add_notice( __( 'OnePay info: ', 'woo-viet') . $this->OnePay_getResponseDescription( $vpc_TxnResponseCode ), 'notice' );
// This is an intentional DRY switch - refer to #DRY_vpc_TxnResponseCode above
// I need to make sure that `ipn` case below and message_log can be executed as well.
switch ( $vpc_TxnResponseCode ) {
case '0':
// If the payment is successful, redirect to the order page
wp_redirect( $this->get_return_url( $order ) );
break;
case '99':
// If the user cancels payment, redirect to the canceled cart page
wp_redirect( $order->get_cancel_order_url_raw() );
break;
default:
// For other cases, redirect to the payment page
wp_redirect( $order->get_checkout_payment_url () );
break;
}
break;
case 'ipn':
case 'ipn': // Output the data to the page content
exit( 'responsecode=1&desc=confirm-success' );
break;
@@ -391,6 +440,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 +453,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__ ) );
}
}
}
+19 -3
View File
@@ -6,8 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* The class to handle Vietnam Provinces
*
* @todo Arrange the orders of fields displaying in the checkout page: Country - Province - District - Address
*
* @author htdat
* @since 1.0
*
@@ -21,6 +19,9 @@ class WooViet_Provinces {
add_filter( 'woocommerce_states', array( $this, 'add_provinces' ) );
add_filter( 'woocommerce_get_country_locale', array( $this, 'edit_vn_locale' ) );
add_filter( 'woocommerce_localisation_address_formats', array( $this, 'edit_vn_address_formats' ) );
// Enqueue province scripts
add_action( 'wp_enqueue_scripts', array( $this, 'load_provinces_scripts' ) );
}
/**
@@ -136,4 +137,19 @@ class WooViet_Provinces {
return $states;
}
}
/**
* Enqueue provinces scripts
*
* Arrange the address field orders to the Vietnam standard in the checkout page: Country - Province - District - Address
* @author Longkt
* @since 1.4
*/
public function load_provinces_scripts() {
// Enqueue province style
wp_enqueue_style( 'woo-viet-provinces-style', WOO_VIET_URL . 'assets/provinces.css' );
// Enqueue province script
wp_enqueue_script( 'woo-viet-provinces-script', WOO_VIET_URL . 'assets/provinces.js', array( 'jquery' ), '1.0', true );
}
}
@@ -0,0 +1,180 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* The class to add the support for VND when using the WooCommerce PayPal Express Checkout gateway
*
* @see https://docs.woocommerce.com/document/paypal-express-checkout/
*
* @author Longkt
* @since 1.4
*
*/
class WooViet_VND_PayPal_Express_Checkout {
/**
* @var int
*/
protected $ppec_exchange_rate;
/**
* @var string
*/
protected $ppec_currency;
/**
* @var string
*/
protected $ppec_description;
/**
* WooViet_VND_PayPal_Express_Checkout constructor
*
* @param int $ppec_exchange_rate
* @param string $ppec_currency
*/
public function __construct( $ppec_exchange_rate = 22770, $ppec_currency = 'USD' ) {
$this->ppec_exchange_rate = (int) $ppec_exchange_rate;
$this->ppec_currency = $ppec_currency;
$this->ppec_description = sprintf( __( 'The prices will be converted to %1$s in the PayPal Express Checkout pages with the exchange rate %2$s.', 'woo-viet' ),
"<span style='color:red'> $this->ppec_currency</span>",
"<span style='color:red'> $this->ppec_currency / VND = $this->ppec_exchange_rate</span>"
);
// Match response currency of PayPal with local order
add_action( 'woocommerce_paypal_express_checkout_valid_ipn_request', array( $this, 'ppec_match_currency_order' ) );
// Add exchange rate before send request to PayPal
add_filter( 'woocommerce_paypal_express_checkout_request_body', array( $this, 'ppec_convert_prices' ) );
// Load the method to add the exchange rate info for this gateway
$this->ppec_exchange_rate_info();
}
/**
* Match response currency from PayPal with the order
*
* @param $posted_data
*/
public function ppec_match_currency_order( $posted_data ) {
if( $posted_data['mc_currency'] ) {
$posted_data['mc_currency'] = $order->get_currency();
}
}
/**
* @param $params
* @return mixed
*/
public function ppec_convert_prices( $params ) {
if( isset( $params['PAYMENTREQUEST_0_CURRENCYCODE'] ) ) {
$params['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->ppec_currency;
if( isset( $params['PAYMENTREQUEST_0_AMT'] ) ) {
$params['PAYMENTREQUEST_0_AMT'] = round( $params['PAYMENTREQUEST_0_AMT'] / $this->ppec_exchange_rate, 2 );
}
if( isset( $params['PAYMENTREQUEST_0_ITEMAMT'] ) ) {
$params['PAYMENTREQUEST_0_ITEMAMT'] = round( $params['PAYMENTREQUEST_0_ITEMAMT'] / $this->ppec_exchange_rate, 2 );
}
if( isset( $params['PAYMENTREQUEST_0_SHIPPINGAMT'] ) ) {
$params['PAYMENTREQUEST_0_SHIPPINGAMT'] = round( $params['PAYMENTREQUEST_0_SHIPPINGAMT'] / $this->ppec_exchange_rate, 2 );
}
if( isset( $params['PAYMENTREQUEST_0_TAXAMT'] ) ) {
$params['PAYMENTREQUEST_0_TAXAMT'] = round( $params['PAYMENTREQUEST_0_TAXAMT'] / $this->ppec_exchange_rate, 2 );
}
if( isset( $params['PAYMENTREQUEST_0_SHIPDISCAMT'] ) ) {
$params['PAYMENTREQUEST_0_SHIPDISCAMT'] = round( $params['PAYMENTREQUEST_0_SHIPDISCAMT'] / $this->ppec_exchange_rate, 2 );
}
$count = 0;
while( isset( $params['L_PAYMENTREQUEST_0_AMT' . $count] ) ) {
$params['L_PAYMENTREQUEST_0_AMT' . $count] = round( $params['L_PAYMENTREQUEST_0_AMT' . $count] / $this->ppec_exchange_rate, 2 );
$count++;
}
}
return $params;
}
/**
* Add the exchange rate info in the suitable locations before proceeding in the PayPal pages
*/
public function ppec_exchange_rate_info() {
// Check if "Checkout on cart page" is enabled.
if( 'yes' === wc_gateway_ppec()->settings->cart_checkout_enabled ) {
add_action( 'woocommerce_proceed_to_checkout', array( $this, 'add_ppec_button_exchange_rate_info' ), 30 );
}
// Check if "Checkout on Single Product" is enabled.
if( 'yes' === wc_gateway_ppec()->settings->checkout_on_single_product_enabled ) {
add_action( 'woocommerce_after_add_to_cart_form', array( $this, 'add_ppec_button_exchange_rate_info' ), 30 );
}
// Check if "Enable PayPal Credit" is enabled.
if( 'yes' === wc_gateway_ppec()->settings->credit_enabled ) {
add_filter( 'woocommerce_paypal_express_checkout_settings', array( $this, 'add_paypal_credit_exchange_rate_info' ), 11 );
}
// Add the exchange rate info for PPEC in Checkout page
add_filter( 'option_woocommerce_ppec_paypal_settings', array( $this, 'add_ppec_checkout_exchange_rate_info' ), 11 );
}
/**
* Display the exchange rate info of PPEC in Cart and Single Product page
*/
public function add_ppec_button_exchange_rate_info() {
echo '<p class="ppec-exchange-rate-info">' . $this->ppec_description . '</p>';
}
/**
* Display the exchange rate info of PP Credit in Checkout page
*
* @param $value
* @return mixed
*/
public function add_paypal_credit_exchange_rate_info( $value ) {
if ( ! is_admin() ) {
$value['description']['default'] .= '<br />';
$value['description']['default'] .= $this->ppec_description;
}
return $value;
}
/**
* Display the exchange rate info of PPEC in Checkout page
*
* @param $value
* @return mixed
*/
public function add_ppec_checkout_exchange_rate_info( $value ) {
if ( ! is_admin() ) {
$value['description'] .= '<br />';
$value['description'] .= $this->ppec_description;
}
return $value;
}
}
+84
View File
@@ -25,6 +25,8 @@ class WooViet_VND_PayPal_Standard {
*/
protected $paypal_currency = 'USD';
//@todo - declare two vars
/**
* WooViet_VND_PayPal_Standard constructor.
*
@@ -43,6 +45,13 @@ class WooViet_VND_PayPal_Standard {
// Add the exchange rate info for this gateway in the checkout page before proceeding in the PayPal pages
add_filter( 'option_woocommerce_paypal_settings', array( $this, 'add_exchange_rate_info' ), 11 );
// Match currency and amount between Paypal and WC Order
add_action( 'valid-paypal-standard-ipn-request', array( $this, 'match_order_currency_and_amount' ), 5 );
// Restore currency and amount for WC Order
add_action( 'valid-paypal-standard-ipn-request', array( $this, 'restore_order_currency_and_amount' ), 15 );
}
/**
@@ -107,4 +116,79 @@ class WooViet_VND_PayPal_Standard {
return $value;
}
/*
* Match currency and amount from Paypal IPN with the order
*
* Topic https://wordpress.org/support/topic/loi-order-bi-on-hold/
*
* @author htdat
* @since 1.4.3
*/
public function match_order_currency_and_amount($posted) {
$order = ! empty( $posted['custom'] ) ? $this->get_paypal_order( $posted['custom'] ) : false;
if ( $order ) {
$this->original_order_currency = $order->get_currency();
$this->original_order_total = $order->get_total();
$order->set_currency( $posted['mc_currency'] );
$order->set_total( $posted['mc_gross'] );
$order->save();
}
}
/*
* Restore currency and amount of the order after the 'match_order_currency_and_amount' action
*
* @author htdat
* @since 1.4.3
*/
public function restore_order_currency_and_amount($posted) {
$order = ! empty( $posted['custom'] ) ? $this->get_paypal_order( $posted['custom'] ) : false;
if ( $order ) {
$order->set_currency( $this->original_order_currency );
$order->set_total( $this->original_order_total );
$order->save();
}
}
/**
* @see Grab this code from - can not call it directly https://github.com/woocommerce/woocommerce/blob/f5c2f89af6a9421af8edc2a4aa20d372e5be40f8/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php#L30
*
* @since 1.4.3
* @author htdat
*/
protected function get_paypal_order( $raw_custom ) {
// We have the data in the correct format, so get the order.
$custom = json_decode( $raw_custom );
if ( $custom && is_object( $custom ) ) {
$order_id = $custom->order_id;
$order_key = $custom->order_key;
} else {
// Nothing was found.
WC_Gateway_Paypal::log( 'Order ID and key were not found in "custom".', 'error' );
return false;
}
$order = wc_get_order( $order_id );
if ( ! $order ) {
// We have an invalid $order_id, probably because invoice_prefix has changed.
$order_id = wc_get_order_id_by_order_key( $order_key );
$order = wc_get_order( $order_id );
}
if ( ! $order || $order->get_order_key() !== $order_key ) {
WC_Gateway_Paypal::log( 'Order Keys do not match.', 'error' );
return false;
}
return $order;
}
}
+10
View File
@@ -89,5 +89,15 @@ return array(
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>' ),
),
);
+25 -69
View File
@@ -1,79 +1,35 @@
# Woo Viet - WooCommerce for Vietnam
| Name | Value |
|:---|:---|
| Contributors | htdat |
|Tags| 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.7 |
| Stable tag | 1.3 |
| License | GPLv2 or later |
| License URI | https://www.gnu.org/licenses/gpl-2.0.html |
Add features to WooCommerce stores having anything related to Vietnam: currency, shipping address, PayPal and more.
## Description
**"Woo Viet - WooCommerce for Vietnam" brings the features that help to run WooCommerce stores and customize them for Vietnam much easier.**
See here https://wordpress.org/plugins/woo-viet/
Xem phiên bản tiếng Việt tại đây https://vi.wordpress.org/plugins/woo-viet/
## FEATURES
* Change the VND currency symbol `đ` to anything, e.g: `VND`, `VNĐ`, `đồng`, etc.
* Add provinces for Vietnam when visitors select Vietnam as a country of the shipping (billing) address. This is not available in WooCommerce by default.
* 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/).
## ROAD MAP
In the future, this plugin will add more and more features for the Vietnam market:
* Integrate all districts to Vietnam provinces.
* Integrate at least one solution for collecting money by phone cards.
* Integrate the Vietnam payment gateways like 1Pay, OnePay, BaoKim, Ngan Luong, etc.
* Integrate the Vietnam shipping solutions like ShipChung, Giaohangnhanh, ViettelPost, etc.
## WHERE CAN I CONTRIBUTE MY CODE OR IDEA?
* You can report bugs or contribute code on [this GitHub repo](https://github.com/htdat/woo-viet).
* Please also do let us know if the "bug" is just a grammar/spelling error in both English and Vietnamese. We try to make our products as perfect as possible.
## INSTALLATION
Follow these steps to install and use the plugin:
1. Upload the plugin files to the `/wp-content/plugins/woo-viet` directory, or install the plugin through the WordPress plugins screen directly.
1. Activate the plugin through the `Plugins` screen in WordPress.
1. Go to the `WooCommerce -> Woo Viet` screen and configure the plugin.
## Installation
Follow these steps to install and use the plugin:
1. Upload the plugin files to the `/wp-content/plugins/woo-viet` directory, or install the plugin through the WordPress plugins screen directly.
1. Activate the plugin through the 'Plugins' screen in WordPress.
1. Go to the `WooCommerce -> Woo Viet` screen and configure the plugin.
## Frequently Asked Questions
### WHERE CAN I CONTRIBUTE MY CODE OR IDEA?
* You can report bugs or contribute code on [this GitHub repo](https://github.com/htdat/woo-viet).
* Please also do let us know if the "bug" is just a grammar/spelling error in both English and Vietnamese. We try to make our products as perfect as possible.
## Screenshots
1. The settings page under WooCommerce -> Woo Viet.
2. Prices are changed to "K", and the symbol is now "VND".
3. List provinces when selecting Vietnam.
4. Let clients know about the currency conversion before switching to the PayPal pages.
## Changelog
### 1.4.2 - 2018.04.26 =
* Fix the fatal error when WooCommerce PayPal Express Checkout Gateway is not active.
### 1.4.1 - 2018.04.26 =
* Fix the SVN command, missing some files on WP.org repo.
### 1.4 - 2018.04.24
* Fix the on-hold order issue with PayPal Standard.
* Fix the issue in OnePay Domestic gateway when users cancel payment.
* Add enhancement: arrange the address fields to the Vietnam standard: Country - Province - District - Address.
* Add supporting VND for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/).
* Add "Settings" link in the Plugins list page when the plugin is active.
### 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/)
@@ -87,4 +43,4 @@ Follow these steps to install and use the plugin:
### 1.0
* First release.
* Upload to WordPress.org
* Upload to WordPress.org
+28 -22
View File
@@ -1,9 +1,10 @@
=== Woo Viet - WooCommerce for Vietnam ===
Contributors: htdat
Contributors: htdat, thup90, longnguyen
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.7.4
Stable tag: 1.3
Tested up to: 4.9.5
Requires PHP: 5.6
Stable tag: 1.4.3-dev
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -13,25 +14,22 @@ 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/
**NEW FEATURE**:
Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/).
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/)
= FEATURES =
* Change the VND currency symbol `đ` to anything, e.g: `VND`, `VNĐ`, `đồng`, etc.
* Add provinces for Vietnam when visitors select Vietnam as a country of the shipping (billing) address. This is not available in WooCommerce by default.
* Add provinces for Vietnam when visitors select Vietnam as a country of the shipping (billing) address. Arrange the address fields to the Vietnam standard: Country - Province - District - Address.
* 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/).
* Support `VND` for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/).
* 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 =
In the future, this plugin will add more and more features for the Vietnam market:
* Integrate all districts to Vietnam provinces. (available since 1.2)
* Integrate at least one solution for collecting money by phone cards.
* Integrate the Vietnam payment gateways like 1Pay, OnePay, BaoKim, Ngan Luong, etc.
* Integrate the Vietnam shipping solutions like ShipChung, Giaohangnhanh, ViettelPost, etc.
@@ -71,28 +69,36 @@ 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 - 2017.04.22 =
* Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/).
= 1.4.2 - 2018.04.26 =
= 1.2 - 2017.03.03 =
* Integrate all districts to Vietnam provinces. Credits: [WC City Select by 8manos](https://github.com/8manos/wc-city-select) and [the Vietnam district data by 10h30](https://github.com/htdat/woo-viet/issues/4#issuecomment-277449462)
* Fix the fatal error when WooCommerce PayPal Express Checkout Gateway is not active.
= 1.1 =
* Replace all “WooCommerce for Vietnam” to “Woo Viet”
* Replace all “woocomerce-for-vietnam” to “woo-viet”
* Re-upload to WordPress.org
= 1.4.1 - 2018.04.26 =
= 1.0 =
* First release.
* Upload to WordPress.org
* Fix the SVN command, missing some files on WP.org repo.
= 1.4 - 2018.04.24 =
* Fix the on-hold order issue with PayPal Standard.
* Fix the issue in OnePay Domestic gateway when users cancel payment.
* Add enhancement: arrange the address fields to the Vietnam standard: Country - Province - District - Address.
* Add supporting VND for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/).
* Add "Settings" link in the Plugins list page when the plugin is active.
See all change logs on [GitHub repo](https://github.com/htdat/woo-viet#changelog).
== Upgrade Notice ==
= 1.4 =
Version 1.4 arranges the address fields to the Vietnam standard (Country - Province - District - Address), supports VND for PayPal Express Checkout, and fixes issues on PayPal Standard and OnePay Domestic gateways.
= 1.3 =
The new version 1.2 comes with the feature "Add the OnePay domestic (local ATM cards) gateway]"
The new version 1.3 comes with the feature "Add the OnePay domestic (local ATM cards) gateway]"
= 1.2 =
The new version 1.2 comes with the feature "Add districts to Vietnam provinces".
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

+45 -4
View File
@@ -7,7 +7,11 @@
* Author URI: https://profiles.wordpress.org/htdat
* Text Domain: woo-viet
* Domain Path: /languages
* Version: 1.3
* Version: 1.4.2
*
* WC requires at least: 2.6
* WC tested up to: 2.3
*
* License: GPLv2+
*/
@@ -64,6 +68,12 @@ class WooViet {
array(
'enabled' => 'yes',
),
'vnd_paypal_express_checkout' =>
array(
'enabled' => 'yes',
'currency' => 'USD',
'rate' => '22770',
),
);
/**
* The properties to manage all classes under the "inc/" folder
@@ -76,6 +86,7 @@ class WooViet {
protected $Currency;
protected $VND_PayPal_Standard;
protected $Admin_Page;
protected $VND_PayPal_Express_Checkout;
/**
* Setup class.
@@ -90,9 +101,9 @@ class WooViet {
* Throw a notice if WooCommerce is NOT active
*/
public function notice_if_not_woocommerce() {
$class = 'notice notice-error';
$class = 'notice notice-warning';
$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 );
@@ -109,6 +120,9 @@ class WooViet {
if ( class_exists( 'WooCommerce' ) ) {
// Run this plugin normally if WooCommerce is active
$this->main();
// Add "Settings" link when the plugin is active
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_settings_link' ) ) ;
} else {
// Throw a notice if WooCommerce is NOT active
add_action( 'admin_notices', array( $this, 'notice_if_not_woocommerce' ) );
@@ -133,6 +147,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();
@@ -192,6 +210,16 @@ class WooViet {
);
}
// Check if "Support VND for the PayPal Express Checkout gateway" is enabled
if ( 'yes' == $settings['vnd_paypal_express_checkout']['enabled']
AND class_exists( 'WC_Gateway_PPEC_Plugin' )
) { include( WOO_VIET_DIR . 'inc/class-wooviet-vnd-paypal-express-checkout.php' );
$this->VND_PayPal_Express_Checkout = new WooViet_VND_PayPal_Express_Checkout(
$settings['vnd_paypal_express_checkout']['rate'],
$settings['vnd_paypal_express_checkout']['currency']
);
}
}
/**
@@ -220,4 +248,17 @@ class WooViet {
}
}
/**
* Add "Settings" link in the Plugins list page when the plugin is active
*
* @since 1.4
* @author Longkt
*/
public function add_settings_link( $links ) {
$settings = array( '<a href="' . admin_url( 'admin.php?page=woo-viet' ) . '">' . __( 'Settings', 'woo-viet' ) . '</a>' );
$links = array_reverse( array_merge( $links, $settings ) );
return $links;
}
}