diff --git a/assets/images/wechat_pay.svg b/assets/images/wechat_pay.svg
new file mode 100644
index 00000000..01775569
--- /dev/null
+++ b/assets/images/wechat_pay.svg
@@ -0,0 +1,3 @@
+
diff --git a/includes/class-omise-callback.php b/includes/class-omise-callback.php
index 736a001a..7a636f83 100644
--- a/includes/class-omise-callback.php
+++ b/includes/class-omise-callback.php
@@ -31,7 +31,7 @@ public static function execute()
$order_id = isset( $_GET['order_id'] ) ? sanitize_text_field( $_GET['order_id'] ) : null;
$order = wc_get_order( $order_id );
- if(!RequestHelper::validateRequest($order->get_meta('token'))) {
+ if(!RequestHelper::validate_request($order->get_meta('token'))) {
return wp_redirect( wc_get_checkout_url() );
}
@@ -39,7 +39,6 @@ public static function execute()
$callback->validate();
}
-
/**
* Sometimes cancelling a transaction does not updates the status on the Omise backend
* which causes the status to be pending even thought the transaction was cancelled.
diff --git a/includes/class-omise-payment-factory.php b/includes/class-omise-payment-factory.php
index 9607a4d9..d4ec0930 100644
--- a/includes/class-omise-payment-factory.php
+++ b/includes/class-omise-payment-factory.php
@@ -41,7 +41,8 @@ class Omise_Payment_Factory {
'Omise_Payment_DuitNow_QR',
'Omise_Payment_DuitNow_OBW',
'Omise_Payment_Atome',
- 'Omise_Payment_PayPay'
+ 'Omise_Payment_PayPay',
+ 'Omise_Payment_Wechat_Pay',
);
/**
diff --git a/includes/gateway/class-omise-payment-wechat-pay.php b/includes/gateway/class-omise-payment-wechat-pay.php
new file mode 100644
index 00000000..5b2a56be
--- /dev/null
+++ b/includes/gateway/class-omise-payment-wechat-pay.php
@@ -0,0 +1,83 @@
+id = 'omise_wechat_pay';
+ $this->has_fields = true;
+ $this->method_title = __( 'Opn Payments WeChat Pay', 'omise' );
+ $this->method_description = wp_kses(
+ __( 'Accept payment through WeChat Pay via Opn Payments payment gateway.', 'omise' ),
+ ['strong' => []]
+ );
+
+ $this->init_form_fields();
+ $this->init_settings();
+
+ $this->title = $this->get_option( 'title' );
+ $this->description = $this->get_option( 'description' );
+ $this->restricted_countries = [ 'TH' ];
+ $this->source_type = 'wechat_pay';
+
+ add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' );
+ add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
+ add_action( 'woocommerce_order_action_' . $this->id . '_sync_payment', array( $this, 'sync_payment' ) );
+ }
+
+ /**
+ * @see WC_Settings_API::init_form_fields()
+ * @see woocommerce/includes/abstracts/abstract-wc-settings-api.php
+ */
+ public function init_form_fields()
+ {
+ $this->form_fields = array(
+ 'enabled' => array(
+ 'title' => __('Enable/Disable', 'omise'),
+ 'type' => 'checkbox',
+ 'label' => __('Enable Opn Payments WeChat Pay', 'omise'),
+ 'default' => 'no'
+ ),
+
+ 'title' => array(
+ 'title' => __('Title', 'omise'),
+ 'type' => 'text',
+ 'description' => __('This controls the title the user sees during checkout.', 'omise'),
+ 'default' => __('WeChat Pay', 'omise'),
+ ),
+
+ 'description' => array(
+ 'title' => __('Description', 'omise'),
+ 'type' => 'textarea',
+ 'description' => __('This controls the description the user sees during checkout.', 'omise')
+ ),
+ );
+ }
+
+ /**
+ * Get icons
+ *
+ * @see WC_Payment_Gateway::get_icon()
+ */
+ public function get_icon()
+ {
+ $icon = Omise_Image::get_image([
+ 'file' => 'wechat_pay.svg',
+ 'alternate_text' => 'WeChat Pay',
+ ]);
+
+ return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
+ }
+
+ public function charge($order_id, $order)
+ {
+ $requestData = $this->build_charge_request(
+ $order_id, $order, $this->source_type, $this->id . "_callback"
+ );
+ $requestData['source']['ip'] = RequestHelper::get_client_ip();
+ return OmiseCharge::create($requestData);
+ }
+}
diff --git a/includes/libraries/omise-plugin/helpers/request.php b/includes/libraries/omise-plugin/helpers/request.php
index 0bbbc31b..976d1851 100644
--- a/includes/libraries/omise-plugin/helpers/request.php
+++ b/includes/libraries/omise-plugin/helpers/request.php
@@ -1,5 +1,5 @@
vendor
+
+
+
+
+
+
+
+
diff --git a/tests/unit/includes/gateway/bootstrap-test-setup.php b/tests/unit/includes/gateway/bootstrap-test-setup.php
index 952ba0a6..6bdec48f 100644
--- a/tests/unit/includes/gateway/bootstrap-test-setup.php
+++ b/tests/unit/includes/gateway/bootstrap-test-setup.php
@@ -2,7 +2,6 @@
use PHPUnit\Framework\TestCase;
-
abstract class Bootstrap_Test_Setup extends TestCase
{
public $sourceType;
diff --git a/tests/unit/includes/gateway/class-omise-payment-wechat-pay-test.php b/tests/unit/includes/gateway/class-omise-payment-wechat-pay-test.php
new file mode 100644
index 00000000..648f96ad
--- /dev/null
+++ b/tests/unit/includes/gateway/class-omise-payment-wechat-pay-test.php
@@ -0,0 +1,48 @@
+sourceType = 'wechat_pay';
+
+ Brain\Monkey\setUp();
+ Brain\Monkey\Functions\stubs([
+ 'apply_filters' => function () {
+ return Omise_Image::get_image([
+ 'file' => 'wechat_pay.svg',
+ 'alternate_text' => 'WeChat Pay',
+ ]);
+ },
+ ]);
+
+ require_once __DIR__ . '/../../../../includes/libraries/omise-plugin/helpers/request.php';
+ require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-wechat-pay.php';
+ }
+
+ public function test_restricted_countries_field_has_required_countries()
+ {
+ $obj = new Omise_Payment_Wechat_Pay();
+ $expectedCountries = ['TH'];
+
+ $this->assertEqualsCanonicalizing($expectedCountries, $obj->restricted_countries);
+ unset($expectedCountries);
+ }
+
+ public function test_charge()
+ {
+ $obj = new Omise_Payment_Wechat_Pay();
+ $this->getChargeTest($obj);
+ }
+
+ public function test_get_icon()
+ {
+ $obj = new Omise_Payment_Wechat_Pay();
+ $res = $obj->get_icon();
+ $expected = "";
+ $this->assertEquals($expected, trim($res));
+ }
+}
diff --git a/tests/unit/includes/libraries/omise-plugin/helpers/request-test.php b/tests/unit/includes/libraries/omise-plugin/helpers/request-test.php
new file mode 100644
index 00000000..b235a8a7
--- /dev/null
+++ b/tests/unit/includes/libraries/omise-plugin/helpers/request-test.php
@@ -0,0 +1,51 @@
+assertEquals($_SERVER[$serverArrKeyToTest], $res);
+ }
+
+ /**
+ * Data provider for toSubunitReturnCorrectFormat
+ */
+ public function get_client_ip_data_provider()
+ {
+ return [
+ ['HTTP_CLIENT_IP'],
+ ['HTTP_X_FORWARDED_FOR'],
+ ['HTTP_X_FORWARDED'],
+ ['HTTP_FORWARDED_FOR'],
+ ['HTTP_FORWARDED'],
+ ['REMOTE_ADDR'],
+ ];
+ }
+}