48 Commits

Author SHA1 Message Date
Dat Hoang 96bb0fa9ab Fix PHP 8.2+ deprecation warnings for dynamic property creation (#95)
Declare protected properties in WooViet_OnePay_Abstract class to resolve
deprecation warnings when creating dynamic properties in PHP 8.2+.

Properties declared:
- $testmode
- $merchant_id
- $access_code
- $secure_secret
- $user
- $password
- $debug

This fix is backward compatible with older PHP versions and resolves
the warnings reported in issue #94.

Fixes #94

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-06 11:31:36 +07:00
Dat Hoang 54142b611c Update readme.txt for releasing 1.5.3 2024-01-13 23:23:04 +07:00
Dat Hoang 9565a8f574 Sanitize admin settings 2024-01-13 23:19:51 +07:00
Dat Hoang e0b5010e7e Update version info for 1.5.2 release 2021-10-03 01:25:59 +07:00
Dat Hoang 051a65724c Update readme.md 2021-10-03 01:19:09 +07:00
Đào Hoàng Sơn 860354c64f Update VN cities as of July 1st, 2021 (#81) 2021-10-03 01:17:22 +07:00
Dat Hoang c89c14094f Add GitHub Actions for WPorg deploy and asset update (#87)
* Add GitHub Actions for WordPress.org Plugin Readme/Assets Update

* Moved off WPorg asset files to wordpress.org folder

* Add GitHub Actions to release to WP.org
2021-10-03 01:07:13 +07:00
Dat Hoang 37c7d71755 Update version - compatibility for ver 1.5.2 #86 2021-10-03 00:15:37 +07:00
Dat Hoang 8658b6d753 Update version - compatibility for ver 1.5.2 2021-10-03 00:14:17 +07:00
Dat Hoang 69a51f43ea Hot fix - 1.5.1 - Fix the loading of WooViet_VND_PayPal_Standard
Reported in https://wordpress.org/support/topic/plugin-bi-loi-phan-chuyen-doi-tien-te-paypal/

Bug introduced in this line and commit https://github.com/htdat/woo-viet/commit/752f6c26f35c33ffede1f3da9d208ca0e74ae7d8#diff-69930de797b06bf012c5e6601f0f0caeR260
2020-09-13 08:43:38 +07:00
Dat Hoang 90543c378d Finalize 1.5.0 #79
Related #79
2020-09-08 23:06:15 +07:00
Dat Hoang 0e0ef82954 Add rating and support links in the end of the settings page #30
Close #30
2020-09-06 16:53:02 +07:00
Dat Hoang e6759edbf1 Fix: make exchange rate fields better visible 2020-09-06 15:57:58 +07:00
Dat Hoang 0767e86331 Merge pull request #77 from htdat/fix/73
Fix two issues with Support VND for PayPal Checkout when testing with Woo 4.4.1
2020-09-06 14:19:44 +07:00
Dat Hoang 05ae206a4e Ensure that PayPal Checkout SDK will load with the correct currency
Details in this comment https://github.com/htdat/woo-viet/issues/73#issuecomment-685841637
2020-09-03 21:13:06 +07:00
Dat Hoang 7c40f3b69a Let action ppec_match_currency_order run after the other action in the main plugin
More details in https://github.com/htdat/woo-viet/issues/73#issuecomment-685768769
2020-09-03 21:09:05 +07:00
Dat Hoang 752f6c26f3 Tighten condtions to load support for PP Standard and PP Checkout 2020-09-03 20:54:40 +07:00
Dat Hoang 5487c55a2b Improvement: remove redundancy 2020-09-03 20:45:57 +07:00
Dat Hoang 3c818d3d6d OnePay gateways: move Order Button text to payment settings 2020-09-03 20:23:47 +07:00
Dat Hoang 3a82b9d23c Handle OnePay options in the settings page better
If a payment gateway option is NOT checked, it should not echo any link to configuration pages.
2020-09-03 20:01:24 +07:00
Dat Hoang 7a2ac200d8 Small changes to make the code cleaner 2020-09-03 19:38:18 +07:00
Dat Hoang ec28b890fa Fixed depreciated cancel_order method 2020-09-03 19:38:18 +07:00
Dat Hoang 9bc9726151 Handle handle_onepay_querydr 2020-09-03 19:38:18 +07:00
Dat Hoang d039192043 Handle error codes and messages 2020-09-03 19:38:18 +07:00
Dat Hoang 3dde550c88 Handle different logo images 2020-09-03 19:38:18 +07:00
Dat Hoang 14aadd581b Handle order notes 2020-09-03 19:38:18 +07:00
Dat Hoang be85184ca2 Handle different payment and queryDR links 2020-09-03 19:38:18 +07:00
Dat Hoang bf2f84a380 Add settings to handle OnePay Intl gateway 2020-09-03 19:38:18 +07:00
Dat Hoang 61308bb4c2 Update international-settings.php 2020-09-03 19:38:18 +07:00
Dat Hoang 659c7e63d3 Seperate Intl and Domestic classes for OnePay 2020-09-03 19:38:18 +07:00
Dat Hoang 55b7b14c5d TEMP - add important changes for intl gateway 2020-09-03 19:38:18 +07:00
Dat Hoang 83a9922426 Start developing ver 1.5.0 2020-09-03 19:38:18 +07:00
Dat Hoang e15f18a0bd Release 1.4.5 2019-10-21 23:05:21 +07:00
Dat A8C19 f3fae72f67 Update meta info for 1.4.5 2019-10-21 23:02:41 +07:00
Dat A8C19 6250762e7b Reformat code - no major change 2019-10-21 23:02:41 +07:00
Đào Hoàng Sơn 9edd924c1b Update VN cities. (#68)
Data source: https://github.com/daohoangson/dvhcvn
2019-10-21 23:02:41 +07:00
Dat Hoang 195f246f22 Fix issue #65 (#67)
* An idea to fix issue 65

Needs to refine the code before publishing it

* Polish the fix for issue #65

* Needs to remove the filter valid-paypal-standard-ipn-request also
2019-10-21 23:02:41 +07:00
Dat A8C19 ed92de526a Start working on 1.4.5 2019-10-21 23:02:41 +07:00
Long 6707c735b5 Support shipping order fields for the VietNam standard 2019-03-27 21:55:03 +07:00
Dat Hoang 68b9b75adf Release 1.4.4 for a small fix
Co-Authored-By: longnguyen <longkt@users.noreply.github.com>

#60
2019-02-24 20:41:30 +07:00
longnguyen b2414f500b Fix the order of Provine - District field not working when update WC to version 3.5.1 (#60) 2019-02-24 20:22:58 +07:00
Dat Hoang a41866d8ea Merge pull request #57 from htdat/1.4.3-dev
Merge 1.4.3
2018-07-31 13:08:43 +07:00
Dat Hoang 975a41f807 Prepare for the release of 1.4.3 #53 2018-07-31 13:05:41 +07:00
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
28 changed files with 1338 additions and 787 deletions
+9
View File
@@ -0,0 +1,9 @@
# Directories
/.wordpress-org
/.git
/.github
/node_modules
# Files
.distignore
.gitignore
+7
View File
@@ -0,0 +1,7 @@
# Directories
/.wordpress-org export-ignore
/.github export-ignore
# Files
/.gitattributes export-ignore
/.gitignore export-ignore
+22
View File
@@ -0,0 +1,22 @@
# This workflow automatically updates the plugin on WordPress.org
# when a tag is pushed to this repo.
name: Deploy to WordPress.org
on:
push:
tags:
- "*"
jobs:
tag:
name: New tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
# - name: Build # Remove or modify this step as needed
# run: |
# npm install
# npm run build
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
@@ -0,0 +1,16 @@
name: Plugin asset/readme update
on:
push:
branches:
- master
jobs:
trunk:
name: Push to trunk
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: WordPress.org plugin asset/readme update
uses: 10up/action-wordpress-plugin-asset-update@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

+24 -12
View File
@@ -1,48 +1,60 @@
.woocommerce-billing-fields__field-wrapper.active {
.woocommerce-billing-fields__field-wrapper,
.woocommerce-shipping-fields__field-wrapper {
display: flex;
flex-wrap: wrap;
}
#billing_first_name_field {
#billing_first_name_field,
#shipping_first_name_field {
order: 1;
}
#billing_last_name_field {
#billing_last_name_field,
#shipping_last_name_field {
order: 2;
}
#billing_company_field {
#billing_company_field,
#shipping_company_field {
order: 3;
}
#billing_country_field {
#billing_country_field,
#shipping_country_field {
order: 4;
}
#billing_state_field {
#billing_state_field,
#shipping_state_field {
order: 5;
}
#billing_city_field {
#billing_city_field,
#shipping_city_field {
order: 6;
}
#billing_address_1_field {
#billing_address_1_field,
#shipping_address_1_field {
order: 7;
}
#billing_address_2_field {
#billing_address_2_field,
#shipping_address_2_field {
order: 8;
}
#billing_postcode_field {
#billing_postcode_field,
#shipping_postcode_field {
order: 9;
}
#billing_phone_field {
#billing_phone_field,
#shipping_phone_field {
order: 10;
}
#billing_email_field {
#billing_email_field,
#shipping_email_field {
order: 11;
}

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+67 -6
View File
@@ -36,7 +36,7 @@ class WooViet_Admin_Page {
*/
public function save_settings() {
if ( wp_verify_nonce( $_REQUEST['wooviet_nonce'], 'wooviet_save_settings' ) ) {
update_option( 'woo-viet', $_REQUEST['settings'] );
update_option( 'woo-viet', $this->sanitize_settings( $_REQUEST['settings'] ) );
$this->message =
'<div class="updated notice"><p><strong>' .
@@ -106,7 +106,9 @@ 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&section=wooviet_onepay_domestic' ) );
if ( 'yes' == $settings['add_onepay_domestic']['enabled'] ) {
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' );
}
@@ -115,7 +117,35 @@ class WooViet_Admin_Page {
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Add the OnePay International Gateway', 'woo-viet' ) ?></th>
<td>
<input name="settings[add_onepay_international][enabled]" type="hidden" value="no">
<input name="settings[add_onepay_international][enabled]" type="checkbox"
id="add_onepay_international" value="yes"
<?php if ( 'yes' == $settings['add_onepay_international']['enabled'] )
echo 'checked="checked"' ?>>
<label for="add_onepay_international"><?php _e( 'Enabled', 'woo-viet' ) ?></label>
<br/>
<br/>
<label for="">
<?php
echo sprintf( __( 'Your store currency is <code>%s</code>. ', 'woo-viet' ), get_woocommerce_currency() );
// Handle whether or not the store current is VND
if ( 'VND' == get_woocommerce_currency() ) {
_e( 'OnePay can work on your site.', 'woo-viet' );
echo '<br/>';
if ( 'yes' == $settings['add_onepay_international']['enabled'] ) {
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_international' ) );
}
} else {
_e( '<span style="color: red" ">This gateway is not active on your site. Because OnePay supports VND only.</span>', 'woo-viet' );
}
?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Add provinces for Vietnam', 'woo-viet' ) ?></th>
<td>
@@ -232,7 +262,7 @@ class WooViet_Admin_Page {
<br/>
<input name="settings[vnd_paypal_standard][rate]" type="number" step="1" min="100"
id="vnd_paypal_standard_rate" style="width: 70px;"
id="vnd_paypal_standard_rate" style="width: 70px; padding-right: 0;"
value="<?php echo $settings['vnd_paypal_standard']['rate'] ?>"
<label for="vnd_paypal_standard_rate"><?php _e( 'Insert the exchange rate of this currency to VND', 'woo-viet' ) ?></label>
</fieldset>
@@ -268,8 +298,9 @@ class WooViet_Admin_Page {
<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;"
<input name="settings[vnd_paypal_express_checkout][rate]" type="number" step="1"
min="100"
id="vnd_paypal_express_checkout_rate" style="width: 70px; padding-right: 0;"
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>
@@ -283,8 +314,38 @@ class WooViet_Admin_Page {
</p>
</form>
<div id="wooviet-admin-footer"
style="border: 1px dotted; padding: 5px;">
<?php
printf( __( 'Wanna get support or give feedback? Please <a href="%1$s">rate Woo Viet</a> or post questions <a href="%2$s">in the forum</a>!', 'woo-viet' ),
'https://wordpress.org/support/plugin/woo-viet/reviews/?filter=5#new-post',
'https://wordpress.org/support/plugin/woo-viet/'
)
?>
</div>
</div><!-- #wrap ->
<?php
}
}
/**
* Sanitize admin settings.
*
* @author htdat
* @since 1.5.3
*
* @param array $settings User input settings.
*
* @return array
*/
private function sanitize_settings( array $settings ): array {
$sanitized_settings = array();
foreach ( $settings as $feature => $feature_options ) {
foreach ( $feature_options as $option => $value ) {
$sanitized_settings[ $feature ][ $option ] = esc_html( sanitize_text_field( $value ) );
}
}
return $sanitized_settings;
}
}
File diff suppressed because it is too large Load Diff
+26 -395
View File
@@ -8,346 +8,26 @@ if ( ! defined( 'ABSPATH' ) ) {
*
*
* @author htdat
* @since 1.3
* @since 1.5.0
*
*/
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;
require_once('onepay/abstract-payment.php');
class WooViet_OnePay_Domestic extends WooViet_OnePay_Abstract {
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = strtolower( __CLASS__ );
$this->has_fields = false;
$this->order_button_text = __( 'Proceed to OnePay', 'woo-viet' );
public function configure_payment() {
$this->method_title = __( 'OnePay Domestic Gateway (by Woo Viet)', 'woo-viet' );
$this->method_description = __( 'OnePay supports all major bank ATMs in Vietnam.', 'woo-viet' );
$this->supports = array(
'products',
);
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables.
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' ) . sprintf( '<br/><div align="center"><img src="%s"></div>', WOO_VIET_URL . 'assets/onepay_domestic.png' );
$this->testmode = 'yes' === $this->get_option( 'testmode', 'no' );
$this->merchant_id = $this->get_option( 'merchant_id' );
$this->access_code = $this->get_option( 'access_code' );
$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(
$this,
'process_admin_options'
) );
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'handle_onepay_return_url' ) );
add_action( 'woocommerce_api_' . strtolower( __CLASS__ ), array( $this, 'handle_onepay_ipn' ) );
}
/**
* Initialise Gateway Settings Form Fields.
*/
public function init_form_fields() {
$this->form_fields = include( 'onepay/domestic-settings.php' );
public function get_onepay_payment_link( $testmode ) {
return $testmode ? 'https://mtf.onepay.vn/onecomm-pay/vpc.op' : 'https://onepay.vn/onecomm-pay/vpc.op';
}
/**
* 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__ );
public function get_onepay_querydr_link( $testmode ) {
return $testmode ? 'https://mtf.onepay.vn/onecomm-pay/Vpcdps.op' : 'https://onepay.vn/onecomm-pay/Vpcdps.op';
}
/**
* 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 )
);
}
/**
* 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 ) {
$args = array(
'Title' => __( 'OnePay Payment Title', 'woo-viet' ),
'vpc_Merchant' => $this->merchant_id,
'vpc_AccessCode' => $this->access_code,
'vpc_MerchTxnRef' => sprintf( '%1$s_%2$s', $order->get_id(), date( 'YmdHis' ) ),
'vpc_OrderInfo' => substr(
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
'vpc_ReturnURL' => $this->get_return_url( $order ),
'vpc_Version' => '2',
'vpc_Command' => 'pay',
'vpc_Locale' => ( 'vi' == get_locale() ) ? 'vn' : 'en',
'vpc_Currency' => 'VND',
'vpc_TicketNo' => $_SERVER['REMOTE_ADDR'],
);
// Set the queryDR cron for this transaction
$this->set_onepay_querydr_cron( $args['vpc_MerchTxnRef'] );
// Get the secure hash
$vpc_SecureHash = $this->create_vpc_SecureHash( $args );
// Add the secure hash to the args
$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 {
return 'https://onepay.vn/onecomm-pay/vpc.op?' . $http_args;
}
}
/**
* 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 )
);
}
/**
* Create the vpc_SecureHash value.
* @see https://mtf.onepay.vn/developer/?page=modul_noidia_php
*
* @param array $args
*
* @return string
*/
public function create_vpc_SecureHash( $args ) {
$stringHashData = "";
// arrange array data a-z before make a hash
ksort( $args );
foreach ( $args as $key => $value ) {
if ( strlen( $value ) > 0 ) {
if ( ( strlen( $value ) > 0 ) && ( ( substr( $key, 0, 4 ) == "vpc_" ) || ( substr( $key, 0, 5 ) == "user_" ) ) ) {
$stringHashData .= $key . "=" . $value . "&";
}
}
}
//Remove the last character "&"
$stringHashData = rtrim( $stringHashData, "&" );
return strtoupper( hash_hmac( 'SHA256', $stringHashData, pack( 'H*', $this->secure_secret ) ) );
}
/**
* Handle the return URL - GET request from OnePay
*/
public function handle_onepay_return_url() {
if ( isset( $_GET['vpc_SecureHash'] ) ) {
$this->process_onepay_response_data( $_GET, 'return' );
}
}
/**
* Handle the repsonse data from OnePay
*
* @param string $args the response data from OnePay
* @param string $type
*/
public function process_onepay_response_data( $args, $type ) {
$types_accepted = array(
'return',
'ipn',
'querydr',
);
// Do nothing if the type is wrong
if ( ! in_array( $type, $types_accepted ) ) {
return;
}
$is_secure = false;
$is_querydr_exists = false;
if ( 'return' == $type OR 'ipn' == $type ) {
$vpc_SecureHash = $args['vpc_SecureHash'];
// Remove the parameter "vpc_SecureHash" for validating SecureHash
unset( $args['vpc_SecureHash'] );
$is_secure = $this->check_vpc_SecureHash( $args, $vpc_SecureHash );
} elseif ( 'querydr' == $type ) {
$is_querydr_exists = ( 'Y' == $args['vpc_DRExists'] );
}
// Process the data
if ( $is_secure OR $is_querydr_exists ) {
/**
* $vpc_MerchTxnRef looks like this "139_20170418101843" or {order_id}_{date_time}
* @see $this->get_pay_url();
*/
$vpc_MerchTxnRef = $args['vpc_MerchTxnRef'];
$vpc_TxnResponseCode = $args['vpc_TxnResponseCode'];
// Get the order_id part only
$order_id = substr( $vpc_MerchTxnRef, 0, strrpos( $vpc_MerchTxnRef, '_' ) );
$order = wc_get_order( $order_id );
// Add the order note for the reference
$order_note = sprintf(
__( 'OnePay Domestic Gateway Info | Code: %1$s | Message: %2$s | MerchantTxnRef: %3$s | Type: %4$s', 'woo-viet' ),
$vpc_TxnResponseCode,
$this->OnePay_getResponseDescription( $vpc_TxnResponseCode ),
$vpc_MerchTxnRef,
$type
);
$order->add_order_note( $order_note );
// 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': // 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': // Output the data to the page content
exit( 'responsecode=1&desc=confirm-success' );
break;
case 'querydr':
// Do nothing
break;
}
} else {
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
*
* @param string $responseCode
*
* @return string
*/
public function OnePay_getResponseDescription( $responseCode ) {
switch ( $responseCode ) {
@@ -388,86 +68,37 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
$result = "Ngày phát hành/Hết hạn không đúng - Invalid card date";
break;
case "13" :
$result = "Vượt quá hạn mức thanh toán - Exist Amount";
$result = "Vượt quá hạn mức thanh toán - Exceeds the maximum limit";
break;
case "21" :
$result = "Số tiền không đủ để thanh toán - Insufficient fund";
break;
case "22" :
$result = "Thông tin tài khoản không đúng - Invalid account ìnfo";
break;
case "23" :
$result = "Tài khoản bị khóa - Account locked";
break;
case "24" :
$result = "Thông tin thẻ không đúng - Incorrect card number";
break;
case "25" :
$result = "OTP không đúng - Incorrect OTP";
break;
case "99" :
$result = "Người sủ dụng hủy giao dịch - User cancel";
break;
default :
$result = "Giao dịch thất bại - Failured";
$result = "Giao dịch thất bại - Failure";
}
return $result;
}
/**
* Handle the IPN POST request from OnePay
* Initialise Gateway Settings Form Fields.
*/
public function handle_onepay_ipn() {
if ( isset( $_REQUEST['vpc_SecureHash'] ) ) {
$this->process_onepay_response_data( $_REQUEST, 'ipn' );
}
public function init_form_fields() {
$this->form_fields = include( 'onepay/domestic-settings.php' );
}
/**
* 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;
}
// 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 );
// Process the data
$this->process_onepay_response_data( $args_response, 'querydr' );
}
/**
* 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__ ) );
}
}
}
}
@@ -0,0 +1,88 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* The class to handle the domestic OnePay gateway https://mtf.onepay.vn/developer/?page=modul_quocte
*
*
* @author htdat
* @since 1.5.0
*
*/
require_once('onepay/abstract-payment.php');
class WooViet_OnePay_International extends WooViet_OnePay_Abstract {
public function configure_payment() {
$this->method_title = __( 'OnePay International Gateway (by Woo Viet)', 'woo-viet' );
$this->method_description = __( 'OnePay supports all major international cards Visa, Master, JCB, Amex, etc.', 'woo-viet' );
}
public function get_onepay_payment_link( $testmode ) {
return $testmode ? 'https://mtf.onepay.vn/vpcpay/vpcpay.op' : 'https://onepay.vn/vpcpay/vpcpay.op';
}
public function get_onepay_querydr_link( $testmode ) {
return $testmode ? 'https://mtf.onepay.vn/vpcpay/Vpcdps.op' : 'https://onepay.vn/vpcpay/Vpcdps.op';
}
public function OnePay_getResponseDescription( $responseCode ) {
switch ( $responseCode ) {
case "0" :
$result = "Giao dịch thành công - Approved";
break;
case "1" :
case "2" :
$result = "Ngân hàng từ chối giao dịch - Bank Declined";
break;
case "3" :
$result = "OnePay không nhận được kết quả giao dịch từ ngân hàng - OnePAY did not received payment result
from Issuer bank";
break;
case "4" :
$result = "Thẻ hết hạn hoặc sai thông tin hết hạn thẻ - Card expired or incorrect expired date";
break;
case "5" :
$result = "Số tiền không đủ để thanh toán - Insufficient fund";
break;
case "6" :
case "7" :
$result = "Quá trình xử lý giao dịch phát sinh lỗi - An error was encountered while processing your transaction";
break;
case "8" :
$result = "Thẻ không hỗ trợ giao
dịch thanh toán trên Internet - Ecommerce transaction is not supported for this card";
break;
case "9" :
$result = "Ngân hàng từ chối giao dịch - Bank Declined";
break;
case "99" :
$result = "Người sủ dụng hủy giao dịch - User cancel";
break;
case "B" :
case "F" :
$result = "Không xác thực được 3D-Secure - 3D Secure Authentication Failed";
break;
case "E" :
$result = "Nhập sai CSC (Card Security Card) hoặc ngân hàng từ chối cấp phép cho giao dịch - You have entered wrong CSC or Issuer Bank declided transaction";
break;
case "Z" :
$result = "Transaction restricted due to OFDs policies - vi phạm quy định của hệ thống";
break;
default :
$result = "Giao dịch thất bại - Failure";
}
return $result;
}
/**
* Initialise Gateway Settings Form Fields.
*/
public function init_form_fields() {
$this->form_fields = include( 'onepay/international-settings.php' );
}
}
+6 -6
View File
@@ -139,12 +139,12 @@ class WooViet_Provinces {
}
/**
* 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
*/
* 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' );
@@ -41,16 +41,28 @@ class WooViet_VND_PayPal_Express_Checkout {
$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>"
);
"<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_action( 'woocommerce_paypal_express_checkout_valid_ipn_request', array(
$this,
'ppec_match_currency_order'
), 20 );
// Add exchange rate before send request to PayPal
add_filter( 'woocommerce_paypal_express_checkout_request_body', array( $this, 'ppec_convert_prices' ) );
/**
* Ensure that PayPal Checkout SDK will load with the correct currency
* @see https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/blob/f1f16de178cbf1d529deeaf574a52aca82a6e093/includes/class-wc-gateway-ppec-cart-handler.php#L553-L556
*/
add_filter ('woocommerce_paypal_express_checkout_sdk_script_args', function( $script_args ) {
$script_args[ 'currency' ] = $this->ppec_currency;
return $script_args;
});
// Load the method to add the exchange rate info for this gateway
$this->ppec_exchange_rate_info();
@@ -58,12 +70,12 @@ class WooViet_VND_PayPal_Express_Checkout {
/**
* Match response currency from PayPal with the order
*
*
* @param $posted_data
*/
public function ppec_match_currency_order( $posted_data ) {
if( $posted_data['mc_currency'] ) {
if ( $posted_data['mc_currency'] ) {
$posted_data['mc_currency'] = $order->get_currency();
}
@@ -71,42 +83,43 @@ class WooViet_VND_PayPal_Express_Checkout {
/**
* @param $params
*
* @return mixed
*/
public function ppec_convert_prices( $params ) {
if( isset( $params['PAYMENTREQUEST_0_CURRENCYCODE'] ) ) {
if ( isset( $params['PAYMENTREQUEST_0_CURRENCYCODE'] ) ) {
$params['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->ppec_currency;
$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++;
}
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;
}
@@ -117,22 +130,31 @@ class WooViet_VND_PayPal_Express_Checkout {
public function ppec_exchange_rate_info() {
// Check if "Checkout on cart page" is enabled.
if( 'yes' === wc_gateway_ppec()->settings->cart_checkout_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 );
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 );
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 );
add_filter( 'option_woocommerce_ppec_paypal_settings', array(
$this,
'add_ppec_checkout_exchange_rate_info'
), 11 );
}
@@ -147,8 +169,9 @@ class WooViet_VND_PayPal_Express_Checkout {
/**
* Display the exchange rate info of PP Credit in Checkout page
*
*
* @param $value
*
* @return mixed
*/
public function add_paypal_credit_exchange_rate_info( $value ) {
@@ -163,8 +186,9 @@ class WooViet_VND_PayPal_Express_Checkout {
/**
* Display the exchange rate info of PPEC in Checkout page
*
*
* @param $value
*
* @return mixed
*/
public function add_ppec_checkout_exchange_rate_info( $value ) {
@@ -173,8 +197,9 @@ class WooViet_VND_PayPal_Express_Checkout {
$value['description'] .= '<br />';
$value['description'] .= $this->ppec_description;
}
return $value;
}
}
+30 -14
View File
@@ -44,8 +44,11 @@ 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 of Paypal with local order
add_action( 'valid-paypal-standard-ipn-request', array( $this, 'match_currency_order' ), 10 );
// Remove checks on currency and gross (total) values
add_action( 'woocommerce_api_wc_gateway_paypal', array( $this, 'remove_currency_and_total_checks' ), 5 );
}
/**
@@ -110,18 +113,31 @@ class WooViet_VND_PayPal_Standard {
return $value;
}
/*
* Match response currency from Paypal IPN with the order
*
* Topic https://wordpress.org/support/topic/loi-order-bi-on-hold/
*
* @author Longkt
* @since 1.4
*/
public function match_currency_order($posted) {
if($posted['mc_currency']) {
$posted['mc_currency'] = $order->get_currency();
}
/**
* Remove currency and total (gross) amount check in class WC_Gateway_Paypal_IPN_Handler
*
* @since 1.4.5
* @author htdat
*/
public function remove_currency_and_total_checks() {
// Remove these filters https://github.com/woocommerce/woocommerce/blob/3.7.1/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php#L34-L35
remove_all_filters( 'woocommerce_api_wc_gateway_paypal', 10 );
remove_all_filters( 'valid-paypal-standard-ipn-request', 10 );
// Get values for PayPal Standard settings
// Ref: https://github.com/woocommerce/woocommerce/blob/3.7.1/includes/gateways/paypal/class-wc-gateway-paypal.php#L58-L61
$paypal_options = get_option( 'woocommerce_paypal_settings' );
$testmode = 'yes' === $paypal_options['testmode'];
$receiver_email = is_null( $paypal_options['receiver_email'] ) ? $paypal_options['email'] : $paypal_options['receiver_email'];
// Replace it by a child class of WC_Gateway_Paypal_IPN_Handler,
// which overrides/removes validate_currency() and validate_amount()
require_once dirname( __FILE__ ) . '/paypal-standard/class-woo-viet-wc-gateway-paypal-ipn-handler.php.php';
$handler = new Woo_Viet_WC_Gateway_Paypal_IPN_Handler( $testmode, $receiver_email ); //@todo needs to handle the correct variables
$handler->check_response();
}
}
+450
View File
@@ -0,0 +1,450 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Abstract class to handle the domestic and international OnePay gateways
*
*
* @author htdat
* @since 1.5.0
*
*/
abstract class WooViet_OnePay_Abstract 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;
/** @var bool Test mode flag */
protected $testmode;
/** @var string OnePay merchant ID */
protected $merchant_id;
/** @var string OnePay access code */
protected $access_code;
/** @var string OnePay secure secret */
protected $secure_secret;
/** @var string OnePay user */
protected $user;
/** @var string OnePay password */
protected $password;
/** @var bool Debug mode flag */
protected $debug;
/**
* Configure $method_title and $method_description
*/
abstract public function configure_payment();
/**
* @param bool $testmode
*/
abstract public function get_onepay_payment_link( $testmode );
/**
* @param bool $testmode
*/
abstract public function get_onepay_querydr_link( $testmode );
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = strtolower( get_called_class() );
$this->has_fields = false;
$this->configure_payment();
$this->supports = array(
'products',
);
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables.
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' )
. sprintf( '<br/><div align="center" class="onepay-logo" id="%1$s"><img src="%2$s"></div>',
$this->id . '_logo',
apply_filters( $this->id . '_logo', WOO_VIET_URL . "assets/$this->id.png" ) );
$this->order_button_text = $this->get_option( 'order_button_text' );
$this->testmode = 'yes' === $this->get_option( 'testmode', 'no' );
$this->merchant_id = $this->get_option( 'merchant_id' );
$this->access_code = $this->get_option( 'access_code' );
$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(
$this,
'process_admin_options'
) );
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'handle_onepay_return_url' ) );
add_action( 'woocommerce_api_' . strtolower( get_called_class() ), array( $this, 'handle_onepay_ipn' ) );
}
/**
* 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( get_called_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 )
);
}
/**
* 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 ) {
$home_url_without_scheme = str_replace( 'https://', '', get_home_url() );
$home_url_without_scheme = str_replace( 'http://', '', $home_url_without_scheme );
$args = array(
'Title' => __( 'OnePay Payment Title', 'woo-viet' ),
'vpc_Merchant' => $this->merchant_id,
'vpc_AccessCode' => $this->access_code,
'vpc_MerchTxnRef' => sprintf( '%1$s_%2$s', $order->get_id(), date( 'YmdHis' ) ),
'vpc_OrderInfo' => substr(
sprintf( 'Order #%1$s - %2$s', $order->get_id(), $home_url_without_scheme ),
0,
32 ), // Limit 32 characters
'vpc_Amount' => $order->get_total() * 100, // Multiplying 100 is a requirement from OnePay
'vpc_ReturnURL' => $this->get_return_url( $order ),
'vpc_Version' => '2',
'vpc_Command' => 'pay',
'vpc_Locale' => ( 'vi' == get_locale() ) ? 'vn' : 'en',
'vpc_Currency' => 'VND',
'vpc_TicketNo' => $_SERVER['REMOTE_ADDR'],
'AgainLink' => mb_strimwidth( wc_get_checkout_url(), 0, 64 ),
);
// Set the queryDR cron for this transaction
$this->set_onepay_querydr_cron( $args['vpc_MerchTxnRef'] );
// Get the secure hash
$vpc_SecureHash = $this->create_vpc_SecureHash( $args );
// Add the secure hash to the args
$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 );
return $this->get_onepay_payment_link( $this->testmode ) . '?' . $http_args;
}
/**
* 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,
$this->id . '_handle_querydr', // wooviet_onepay_international_handle_querydr | wooviet_onepay_domestic_handle_querydr
array( $vpc_MerchTxnRef )
);
}
/**
* Create the vpc_SecureHash value.
* @see https://mtf.onepay.vn/developer/?page=modul_noidia_php
*
* @param array $args
*
* @return string
*/
public function create_vpc_SecureHash( $args ) {
$stringHashData = "";
// arrange array data a-z before make a hash
ksort( $args );
foreach ( $args as $key => $value ) {
if ( strlen( $value ) > 0 ) {
if ( ( strlen( $value ) > 0 ) && ( ( substr( $key, 0, 4 ) == "vpc_" ) || ( substr( $key, 0, 5 ) == "user_" ) ) ) {
$stringHashData .= $key . "=" . $value . "&";
}
}
}
//Remove the last character "&"
$stringHashData = rtrim( $stringHashData, "&" );
return strtoupper( hash_hmac( 'SHA256', $stringHashData, pack( 'H*', $this->secure_secret ) ) );
}
/**
* Handle the return URL - GET request from OnePay
*/
public function handle_onepay_return_url() {
if ( isset( $_GET['vpc_SecureHash'] ) ) {
$this->process_onepay_response_data( $_GET, 'return' );
}
}
/**
* Handle the repsonse data from OnePay
*
* @param string $args the response data from OnePay
* @param string $type
*/
public function process_onepay_response_data( $args, $type ) {
$types_accepted = array(
'return',
'ipn',
'querydr',
);
// Do nothing if the type is wrong
if ( ! in_array( $type, $types_accepted ) ) {
return;
}
$is_secure = false;
$is_querydr_exists = false;
// Verify hash for 'return' and 'ipn'
// And check vpc_DRExists value for 'querydr'
switch ( $type ) {
case 'return':
case 'ipn':
$vpc_SecureHash = $args['vpc_SecureHash'];
// Remove the parameter "vpc_SecureHash" for validating SecureHash
unset( $args['vpc_SecureHash'] );
$is_secure = $this->check_vpc_SecureHash( $args, $vpc_SecureHash );
break;
case 'querydr':
$is_querydr_exists = ( 'Y' == $args['vpc_DRExists'] );
}
// Process the data
if ( $is_secure OR $is_querydr_exists ) {
/**
* $vpc_MerchTxnRef looks like this "139_20170418101843" or {order_id}_{date_time}
* @see $this->get_pay_url();
*/
$vpc_MerchTxnRef = $args['vpc_MerchTxnRef'];
$vpc_TxnResponseCode = $args['vpc_TxnResponseCode'];
// Get the order_id part only
$order_id = explode('_', $vpc_MerchTxnRef)[0];
$order = wc_get_order( $order_id );
// Add the order note for the reference
$order_note = get_called_class() . sprintf(
__( ' Gateway Info | Code: %1$s | Message: %2$s | MerchantTxnRef: %3$s | Type: %4$s', 'woo-viet' ),
$vpc_TxnResponseCode,
$this->OnePay_getResponseDescription( $vpc_TxnResponseCode ),
$vpc_MerchTxnRef,
$type
);
$order->add_order_note( $order_note );
// 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 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->update_status( 'cancelled' );
break;
default:
// For other cases, do nothing. By default, the order status is still "Pending Payment"
break;
}
// Do the last actions based on $type
switch ( $type ) {
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': // Output the data to the page content
exit( 'responsecode=1&desc=confirm-success' );
break;
case 'querydr':
// Do nothing
break;
}
} else {
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
*
* @param string $responseCode
*
* @return string
*/
abstract public function OnePay_getResponseDescription( $responseCode );
/**
* 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, '', '&' );
$http_link = $this->get_onepay_querydr_link( $this->testmode ) . '?' . $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 );
// Process the data
$this->process_onepay_response_data( $args_response, 'querydr' );
}
/**
* 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' => get_called_class() ) );
}
}
}
+10 -4
View File
@@ -5,8 +5,8 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
* Settings for 1Pay Gateway.
* @since 1.3
* Settings for OnePay Domestic Gateway.
* @since 1.3
*/
return array(
'enabled' => array(
@@ -21,7 +21,6 @@ return array(
'label' => __( 'Enable OnePay sandbox (testing)', 'woocommerce' ),
'default' => 'no',
'description' => sprintf( __( 'OnePay sandbox can be used to test payments. See <a href="%s">the testing info</a>.', 'woocommerce' ), 'https://mtf.onepay.vn/developer/?page=modul_noidia' ),
//@todo: add the logo https://mtf.onepay.vn/developer/?page=logo
),
'title' => array(
'title' => __( 'Title', 'woo-viet' ),
@@ -37,6 +36,13 @@ return array(
'description' => __( 'This controls the description which the user sees during checkout.', 'woo-viet' ),
'default' => __( 'With OnePay, you can make payment by using any local Vietnam ATM card.', 'woo-viet' )
),
'order_button_text' => array(
'title' => __( 'Button text', 'woo-viet' ),
'type' => 'text',
'desc_tip' => true,
'description' => __( 'Button label in the checkout page.', 'woo-viet' ),
'default' => __( 'Pay with ATM cards', 'woo-viet' )
),
'api_details' => array(
'title' => __( 'API Credentials', 'woo-viet' ),
'type' => 'title',
@@ -92,7 +98,7 @@ return array(
/**
* @since 1.3.1
*/
'debug' => array(
'debug' => array(
'title' => __( 'Debug log', 'woo-viet' ),
'type' => 'checkbox',
'label' => __( 'Enable logging', 'woo-viet' ),
+109
View File
@@ -0,0 +1,109 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Settings for OnePay International Gateway.
* @since 1.5.0
*/
return array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woo-viet' ),
'type' => 'checkbox',
'label' => __( 'OnePay International Gateway (by Woo Viet)', 'woo-viet' ),
'default' => 'no'
),
'testmode' => array(
'title' => __( 'OnePay Sandbox', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable OnePay sandbox (testing)', 'woocommerce' ),
'default' => 'no',
'description' => sprintf( __( 'OnePay sandbox can be used to test payments. See <a href="%s">the testing info</a>.', 'woocommerce' ), 'https://mtf.onepay.vn/developer/?page=modul_quocte' ),
),
'title' => array(
'title' => __( 'Title', 'woo-viet' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'woo-viet' ),
'default' => __( 'OnePay International Gateway', 'woo-viet' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description', 'woo-viet' ),
'type' => 'textarea',
'desc_tip' => true,
'description' => __( 'This controls the description which the user sees during checkout.', 'woo-viet' ),
'default' => __( 'With OnePay, you can make payment by using any local international card such as Visa, Master, JCB, and Amex.', 'woo-viet' )
),
'order_button_text' => array(
'title' => __( 'Button text', 'woo-viet' ),
'type' => 'text',
'desc_tip' => true,
'description' => __( 'Button label in the checkout page.', 'woo-viet' ),
'default' => __( "Pay with international cards", 'woo-viet' )
),
'api_details' => array(
'title' => __( 'API Credentials', 'woo-viet' ),
'type' => 'title',
'description' => sprintf( __( 'Enter your OnePay API credentials. Contact OnePay to have your credentials %shere%s.', 'woo-viet' ), '<a href="http://onepay.com.vn/home/en/contact-us.html">', '</a>' ),
),
'merchant_id' => array(
'title' => __( 'Merchant ID', 'woo-viet' ),
'type' => 'text',
'description' => __( 'Get your Merchant ID from OnePay.', 'woo-viet' ),
'default' => '',
'desc_tip' => true,
'placeholder' => __( 'Required. Provided by OnePay.', 'woo-viet' )
),
'access_code' => array(
'title' => __( 'Access Code', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Get your Access Code from OnePay.', 'woo-viet' ),
'default' => '',
'desc_tip' => true,
'placeholder' => __( 'Required. Provided by OnePay.', 'woo-viet' )
),
'secure_secret' => array(
'title' => __( 'Secure Secret', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Get your Secure Secret from OnePay.', 'woo-viet' ),
'default' => '',
'desc_tip' => true,
'placeholder' => __( 'Required. Provided by OnePay.', 'woo-viet' )
),
'user' => array(
'title' => __( 'User for queryDR. Test value: op01', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Get your user info from OnePay.', 'woo-viet' ),
'default' => '',
'desc_tip' => true,
'placeholder' => __( 'Required. Provided by OnePay', 'woo-viet' )
),
'password' => array(
'title' => __( 'Password for queryDR. Test value: op123456', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Get your password info from OnePay.', 'woo-viet' ),
'default' => '',
'desc_tip' => true,
'placeholder' => __( 'Required. Provided by OnePay.', 'woo-viet' )
),
'more_info' => array(
'title' => __( 'Instant Payment Notification (IPN)', 'woo-viet' ),
'type' => 'title',
'description' =>
sprintf( 'URL: <code>%s</code>', WooViet_OnePay_International::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_International' ) . '</code>' ),
),
);
@@ -0,0 +1,22 @@
<?php
/**
* Override/remove two validate functions in the parent class
*
* @author htdat
* @since 1.4.5
*
*/
if ( class_exists( 'WC_Gateway_Paypal_IPN_Handler' ) ) {
class Woo_Viet_WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_IPN_Handler {
protected function validate_currency( $order, $currency ) {
}
protected function validate_amount( $order, $amount ) {
}
}
}
+43
View File
@@ -8,6 +8,49 @@ Xem phiên bản tiếng Việt tại đây https://vi.wordpress.org/plugins/woo
## Changelog
### 1.5.3 - 2024.01.13
* Update - Sanitize admin settings to avoid XSS. Thanks Dhabaleshwar Das.
### 1.5.2 - 2021.10.03
* Update - tested with WP 5.8.1 and WC 5.7.1. #86
* Dev - Add GitHub Actions for WPorg deploy and asset update #87
* Update provinces and cities as of July 1st, 2021 #81. Thanks @daohoangson!
### 1.5.1 - 2020.09.13
* Fix the loading of WooViet_VND_PayPal_Standard
### 1.5.0 - 2020.09.10
* Add the OnePay international gateway #74
* Add Order Button texts in OnePay gateway setting pages. (Commit 3c818d3)
* Add rating and support links in the end of the settings page #30
* Fix two issues related to supporting VND for PayPal Checkout #77
### 1.4.5 - 2019.10.22
* Fix VND for PP Standard: wrong currency and gross (total) price in email confirmation #65
* Update provinces and cities #68. Thanks @daohoangson!
### 1.4.4 - 2019.02.24
* Fix the order of Provine - District field not working after updating WooCommerce 3.5.x #60
### 1.4.3 - 2018.07.31
* Fix fatal error when handling PayPal IPN #56
* Other small improvements #53
### 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.
+12 -17
View File
@@ -2,9 +2,9 @@
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.9.5
Requires PHP: 5.6
Stable tag: 1.4
Tested up to: 6.4.2
Requires PHP: 7.0
Stable tag: 1.5.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -16,9 +16,6 @@ Add features to WooCommerce stores having anything related to Vietnam: currency,
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/).
= FEATURES =
* Change the VND currency symbol `đ` to anything, e.g: `VND`, `VNĐ`, `đồng`, etc.
@@ -26,16 +23,18 @@ 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.
* Support `VND` for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/)
* 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.
* Add [the OnePay international (Visa, Master, JCB, Amex cards) gateway](http://onepay.com.vn/). Implement all methods in [the official documents](https://mtf.onepay.vn/developer/?page=modul_quocte_php): QueryDR, IPN, and Return URL.
= ROAD MAP =
In the future, this plugin will add more and more features for the Vietnam market:
* 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.
* Integrate the Vietnam payment gateways like Momo, VNPay, BaoKim, Ngan Luong, etc.
* Integrate the Vietnam shipping solutions like Giaohangnhanh, Giao Hang Tiet Kiem, VNPost, ViettelPost, etc.
= WHERE CAN I CONTRIBUTE MY CODE OR IDEA? =
@@ -76,18 +75,14 @@ Follow these steps to install and use the plugin:
== Changelog ==
= 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.5.0 =
Version 1.5.0 comes with a new gateway OnePay International and other small improvements.
= 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.
+81 -35
View File
@@ -7,10 +7,10 @@
* Author URI: https://profiles.wordpress.org/htdat
* Text Domain: woo-viet
* Domain Path: /languages
* Version: 1.4
* Version: 1.5.3
*
* WC requires at least: 2.6
* WC tested up to: 2.3
* WC requires at least: 3.0
* WC tested up to: 8.4.0
*
* License: GPLv2+
*/
@@ -40,37 +40,41 @@ class WooViet {
* @var array The default settings for the whole plugin
*/
static $default_settings = array(
'add_province' =>
'add_province' =>
array(
'enabled' => 'yes',
),
'add_city' =>
'add_city' =>
array(
'enabled' => 'yes',
),
'change_currency_symbol' =>
'change_currency_symbol' =>
array(
'enabled' => 'yes',
'text' => 'VND',
),
'convert_price' =>
'convert_price' =>
array(
'enabled' => 'yes',
'text' => 'K',
),
'vnd_paypal_standard' =>
'vnd_paypal_standard' =>
array(
'enabled' => 'yes',
'currency' => 'USD',
'rate' => '22770',
),
'add_onepay_domestic' =>
'add_onepay_domestic' =>
array(
'enabled' => 'yes',
),
'add_onepay_international' =>
array(
'enabled' => 'yes',
),
'vnd_paypal_express_checkout' =>
array(
'enabled' => 'yes',
array(
'enabled' => 'yes',
'currency' => 'USD',
'rate' => '22770',
),
@@ -122,7 +126,7 @@ class WooViet {
$this->main();
// Add "Settings" link when the plugin is active
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_settings_link' ) ) ;
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' ) );
@@ -161,20 +165,70 @@ class WooViet {
) {
include( 'inc/class-wooviet-onepay-domestic.php' );
add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway_class' ) );
add_filter( 'woocommerce_payment_gateways', function ( $methods ) {
$methods[] = 'WooViet_OnePay_Domestic';
return $methods;
} );
// Add the action to check the cron job for handling queryDR
// It's not possible to add in the class "WooViet_OnePay_Domestic_Hook" because it's NOT always loadded
/**
* Add the action to check the cron job for handling queryDR
* It's not possible to add in the "WooViet_OnePay_Domestic" class
* because it's NOT always loaded in the 'woocommerce_payment_gateways' hook above
*/
if ( defined( 'DOING_CRON' ) and DOING_CRON ) {
$this->WooViet_OnePay_Domestic_Hook = new WooViet_OnePay_Domestic();
$wooviet_onepay_domestic = new WooViet_OnePay_Domestic();
/**
* @since 1.5.0
*/
add_action( 'wooviet_onepay_domestic_handle_querydr', array(
$wooviet_onepay_domestic,
'handle_onepay_querydr'
), 10, 1 );
/**
* Backward compatibility
* Actually, this does help for the short time (exactly 20 minutes) @see WooViet_OnePay_Abstract::set_onepay_querydr_cron()
* when upgrading to version 1.5.0
* as the previous cron jobs set by the previous versions has not run yet.
*
* TODO: May consider removing this completely after 2 major versions. Target: 1.7
*/
add_action( 'wooviet_handle_onepay_querydr', array(
$this->WooViet_OnePay_Domestic_Hook,
$wooviet_onepay_domestic,
'handle_onepay_querydr'
), 10, 1 );
}
}
/**
* Check if "Add the OnePay International Gateway" is enabled
* @since 1.5.0
*/
if ( 'yes' == $settings['add_onepay_international']['enabled']
AND 'VND' == get_woocommerce_currency()
) {
include( 'inc/class-wooviet-onepay-international.php' );
add_filter( 'woocommerce_payment_gateways', function ( $methods ) {
$methods[] = 'WooViet_OnePay_International';
return $methods;
} );
/**
* Add the action to check the cron job for handling queryDR
* It's not possible to add in the "WooViet_OnePay_International" class
* because it's NOT always loaded in the 'woocommerce_payment_gateways' hook above
*/
if ( defined( 'DOING_CRON' ) and DOING_CRON ) {
add_action( 'wooviet_onepay_international_handle_querydr', array(
new WooViet_OnePay_International(),
'handle_onepay_querydr'
), 10, 1 );
}
}
// Check if "Add provinces for Vietnam " is enabled.
if ( 'yes' == $settings['add_province']['enabled'] ) {
include( WOO_VIET_DIR . 'inc/class-wooviet-provinces.php' );
@@ -202,7 +256,10 @@ class WooViet {
// Check if "Support VND for the PayPal Standard gateway" is enabled
if ( 'yes' == $settings['vnd_paypal_standard']['enabled'] ) {
if ( 'yes' == $settings['vnd_paypal_standard']['enabled']
AND class_exists( 'WC_Gateway_Paypal' )
AND 'VND' == get_woocommerce_currency()
) {
include( WOO_VIET_DIR . 'inc/class-wooviet-vnd-paypal-standard.php' );
$this->VND_PayPal_Standard = new WooViet_VND_PayPal_Standard(
$settings['vnd_paypal_standard']['rate'],
@@ -211,7 +268,10 @@ class WooViet {
}
// Check if "Support VND for the PayPal Express Checkout gateway" is enabled
if ( 'yes' == $settings['vnd_paypal_express_checkout']['enabled'] ) {
if ( 'yes' == $settings['vnd_paypal_express_checkout']['enabled']
AND class_exists( 'WC_Gateway_PPEC_Plugin' )
AND 'VND' == get_woocommerce_currency()
) {
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'],
@@ -232,30 +292,16 @@ class WooViet {
return $settings;
}
/**
* Add the gateways to WooCommerce
*
* @param array $methods
*
* @since 1.3
* @return array
*/
public function add_gateway_class( $methods ) {
$methods[] = 'WooViet_OnePay_Domestic';
return $methods;
}
/**
* 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 ) );
$links = array_reverse( array_merge( $links, $settings ) );
return $links;
}