diff --git a/CHANGELOG.md b/CHANGELOG.md index 296749e3..935dd617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +### [v5.4.0 _(Sep 21, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.4.0) +- Added OCBC Digital for Singapore PSP. (PR [#401](https://github.com/omise/omise-woocommerce/pull/401)) + ### [v5.3.1 _(Sep 05, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.3.1) - Fixed capabilities api calling on every pages. (PR [#398](https://github.com/omise/omise-woocommerce/pull/398)) diff --git a/assets/images/ocbc-digital.png b/assets/images/ocbc-digital.png new file mode 100644 index 00000000..699b34bb Binary files /dev/null and b/assets/images/ocbc-digital.png differ diff --git a/includes/class-omise-payment-factory.php b/includes/class-omise-payment-factory.php index 8a01804e..9607a4d9 100644 --- a/includes/class-omise-payment-factory.php +++ b/includes/class-omise-payment-factory.php @@ -32,6 +32,7 @@ class Omise_Payment_Factory { 'Omise_Payment_TouchNGo', 'Omise_Payment_RabbitLinePay', 'Omise_Payment_OCBC_PAO', + 'Omise_Payment_OCBC_Digital', 'Omise_Payment_GrabPay', 'Omise_Payment_GooglePay', 'Omise_Payment_Boost', diff --git a/includes/gateway/class-omise-payment-ocbc-digital.php b/includes/gateway/class-omise-payment-ocbc-digital.php new file mode 100644 index 00000000..baed7371 --- /dev/null +++ b/includes/gateway/class-omise-payment-ocbc-digital.php @@ -0,0 +1,98 @@ +id = 'omise_ocbc'; + $this->has_fields = false; + $this->method_title = __( 'Opn Payments OCBC Digital', 'omise' ); + $this->method_description = __( 'Accept payment through OCBC Digital via Opn Payments payment gateway.', 'omise' ); + $this->supports = [ 'products', 'refunds' ]; + + $this->init_form_fields(); + $this->init_settings(); + + $this->title = $this->get_option( 'title' ); + $this->description = $this->get_option( 'description' ); + $this->restricted_countries = [ 'SG' ]; + $this->source_type = 'mobile_banking_ocbc'; + + add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' ); + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] ); + add_action( 'woocommerce_order_action_' . $this->id . '_sync_payment', [ $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 = [ + 'enabled' => [ + 'title' => __( 'Enable/Disable', 'omise' ), + 'type' => 'checkbox', + 'label' => __( 'Enable Opn Payments OCBC Digital', 'omise' ), + 'default' => 'no' + ], + + 'title' => [ + 'title' => __( 'Title', 'omise' ), + 'type' => 'text', + 'description' => __( 'This controls the title the user sees during checkout.', 'omise' ), + 'default' => __( 'OCBC Digital', 'omise' ), + ], + + 'description' => [ + 'title' => __( 'Description', 'omise' ), + 'type' => 'textarea', + 'description' => __( 'This controls the description the user sees during checkout.', 'omise' ) + ], + ]; + } + + /** + * @inheritdoc + */ + public function charge($order_id, $order) + { + return OmiseCharge::create($this->get_charge_request($order_id, $order)); + } + + /** + * @order_id integer + * @order object + */ + public function get_charge_request($order_id, $order) + { + $currency = $order->get_currency(); + + return [ + 'amount' => Omise_Money::to_subunit($order->get_total(), $currency), + 'currency' => $currency, + 'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order), + 'source' => [ + 'type' => $this->source_type, + 'platform_type' => Omise_Util::get_platform_type( wc_get_user_agent() ) + ], + 'return_uri' => $this->getRedirectUrl("{$this->id}_callback", $order_id, $order), + 'metadata' => $this->getMetadata($order_id, $order) + ]; + } + + /** + * Get icons + * + * @see WC_Payment_Gateway::get_icon() + */ + public function get_icon() + { + $icon = Omise_Image::get_image([ + 'file' => 'ocbc-digital.png', + 'alternate_text' => 'OCBC Digital', + 'width' => 60, + ]); + return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); + } +} diff --git a/omise-woocommerce.php b/omise-woocommerce.php index 919c77b9..fd1b3df6 100644 --- a/omise-woocommerce.php +++ b/omise-woocommerce.php @@ -4,7 +4,7 @@ * Plugin Name: Opn Payments * Plugin URI: https://www.omise.co/woocommerce * Description: Opn Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Opn Payments Payment Gateway's payment methods to WooCommerce. - * Version: 5.3.1 + * Version: 5.4.0 * Author: Opn Payments and contributors * Author URI: https://github.com/omise/omise-woocommerce/graphs/contributors * Text Domain: omise @@ -22,7 +22,7 @@ class Omise * * @var string */ - public $version = '5.3.1'; + public $version = '5.4.0'; /** * The Omise Instance. @@ -213,6 +213,7 @@ private function include_classes() require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/class-omise-payment-googlepay.php'; require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/class-omise-payment-grabpay.php'; require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/class-omise-payment-ocbc-pao.php'; + require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/class-omise-payment-ocbc-digital.php'; require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/class-omise-payment-boost.php'; require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/class-omise-payment-duitnow-obw.php'; require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/class-omise-payment-duitnow-qr.php'; diff --git a/readme.txt b/readme.txt index 625c9574..1f57bf7f 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: Opn Payments Tags: opn payments, payment, payment gateway, woocommerce plugin, omise, opn, installment, internet banking, alipay, paynow, truemoney wallet, woocommerce payment Requires at least: 4.3.1 Tested up to: 6.0.2 -Stable tag: 5.3.1 +Stable tag: 5.4.0 License: MIT License URI: https://opensource.org/licenses/MIT @@ -34,6 +34,10 @@ From there: == Changelog == += 5.4.0 = + +- Added OCBC Digital for Singapore PSP. (PR [#401](https://github.com/omise/omise-woocommerce/pull/401)) + = 5.3.1 = - Fixed capabilities api calling on every pages. (PR [#398](https://github.com/omise/omise-woocommerce/pull/398)) diff --git a/tests/unit/includes/gateway/class-omise-offsite-test.php b/tests/unit/includes/gateway/class-omise-offsite-test.php index 4712b196..56233409 100644 --- a/tests/unit/includes/gateway/class-omise-offsite-test.php +++ b/tests/unit/includes/gateway/class-omise-offsite-test.php @@ -11,6 +11,8 @@ public function setUp(): void $offsite->shouldReceive('init_settings'); $offsite->shouldReceive('get_option'); $offsite->shouldReceive('get_provider'); + $offsite->shouldReceive('getRedirectUrl'); + $offsite->shouldReceive('getMetadata'); // mocking WP built-in functions if (!function_exists('wp_kses')) { @@ -20,8 +22,6 @@ function wp_kses() {} if (!function_exists('add_action')) { function add_action() {} } - - require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-alipayplus.php'; } /** diff --git a/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php b/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php new file mode 100644 index 00000000..b33e74a2 --- /dev/null +++ b/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php @@ -0,0 +1,108 @@ +obj = new Omise_Payment_OCBC_Digital(); + } + + public function tearDown(): void + { + // destroy object and clear memory + unset($this->obj); + } + + /** + * @test + */ + public function restrictedCountriesHasRequiredCountries() + { + $expectedCountries = ['SG']; + $this->assertEqualsCanonicalizing($expectedCountries, $this->obj->restricted_countries); + } + + /** + * @test + */ + public function sourceTypeIsCorrect() + { + $this->assertEquals('mobile_banking_ocbc', $this->obj->source_type); + } + + /** + * @test + */ + public function methodTitleIsCorrect() + { + $this->assertEquals('Opn Payments OCBC Digital', $this->obj->method_title); + } + + /** + * @test + */ + public function supportsIsCorrect() + { + $this->assertEqualsCanonicalizing([ 'products', 'refunds' ], $this->obj->supports); + } + + /** + * @test + */ + public function getIconReturnsCorrectImageLink() + { + // mocking WP built-in functions + if (!function_exists('plugins_url')) { + function plugins_url() { + return "http://localhost"; + } + } + + if (!function_exists('apply_filters')) { + function apply_filters() { + return "http://localhost/image.png"; + } + } + + $result = $this->obj->get_icon(); + + $this->assertEquals("http://localhost/image.png", $result); + } + + /** + * @test + */ + public function getChargeRequestReturnsCorrectData() + { + // Create a mock of the $order object + $orderMock = Mockery::mock('WC_Order'); + $expectedCurrency = 'SGD'; + $expectedAmount = 1000000; // in subunits + + // Define expectations for the mock + $orderMock->shouldReceive('get_currency') + ->andReturn($expectedCurrency); + $orderMock->shouldReceive('get_total') + ->andReturn($expectedAmount/100); // in units + + if (!function_exists('wc_get_user_agent')) { + function wc_get_user_agent() { + return "Chrome Web"; + } + } + + $expectedSourceType = 'mobile_banking_ocbc'; + $order_id = "123"; + $result = $this->obj->get_charge_request($order_id, $orderMock); + $this->assertEquals($expectedAmount, $result['amount']); + $this->assertEquals($expectedCurrency, $result['currency']); + $this->assertEquals($expectedSourceType, $result['source']['type']); + } +}