Plugin Directory

Changeset 3021743


Ignore:
Timestamp:
01/15/2024 07:46:52 AM (2 years ago)
Author:
omise
Message:

Update to version 5.7.0 from GitHub

Location:
omise
Files:
30 edited
1 copied

Legend:

Unmodified
Added
Removed
  • omise/tags/5.7.0/CHANGELOG.md

    r3006639 r3021743  
    11# CHANGELOG
     2
     3## [v5.7.0 _(Jan 11, 2024)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.7.0)
     4- Added TrueMoney jumpapp. (PR [#431](https://github.com/omise/omise-woocommerce/pull/431))
     5- Updated README.md. (PR [#429](https://github.com/omise/omise-woocommerce/pull/429))
    26
    37## [v5.6.2 _(Dec 7, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.6.2)
  • omise/tags/5.7.0/README.md

    r2501457 r3021743  
    11<!--- KEEP START --->
    2 [![Omise](https://cdn.omise.co/assets/omise.png)](https://www.omise.co/developers)
     2[![Opn Payments](https://www.opn.ooo/assets/svg/logo-opn-full.svg)](https://www.opn.ooo)
    33
    4 [Omise](https://www.omise.co/) is a payment service provider operating in Thailand, Japan, and Singapore.
    5 Omise provides a set of APIs that help merchants of any size accept payments online. 
     4[Opn Payments](https://www.opn.ooo) is a payment service provider operating in Thailand, Japan, and Singapore.
     5Opn Payments provides a set of APIs that help merchants of any size accept payments online. 
    66<!--- KEEP END --->
    77
    8 **Omise WooCommerce** is our official plugin providing support for processing payments on WooCommerce through Omise.
    9 
    10 ![PHP Composer](https://github.com/omise/omise-woocommerce/workflows/PHP%20Composer/badge.svg)
     8**Omise WooCommerce** is our official plugin providing support for processing payments on WooCommerce through Opn Payments.
    119
    1210## Usage
    1311
    14 See our [official docs](https://www.omise.co/woocommerce-plugin) for details on installation and configuration.
     12See our [official docs](https://docs.opn.ooo/woocommerce-plugin) for details on installation and configuration.
    1513
    1614## Contributing
  • omise/tags/5.7.0/includes/class-omise-capabilities.php

    r2962817 r3021743  
    252252        return $this->capabilities['limits']['installment_amount']['min'];
    253253    }
     254
     255    /**
     256     * Retrieves details of TrueMoney from capabilities.
     257     *
     258     * @param string $source_type
     259     */
     260    public function get_truemoney_backend($source_type)
     261    {
     262        $truemoney_source_types = [Omise_Payment_Truemoney::WALLET, Omise_Payment_Truemoney::JUMPAPP];
     263
     264        if (!in_array($source_type, $truemoney_source_types)) {
     265            return null;
     266        }
     267
     268        return $this->getBackendByType($source_type);
     269    }
    254270}
  • omise/tags/5.7.0/includes/gateway/class-omise-payment-truemoney.php

    r2979883 r3021743  
    77class Omise_Payment_Truemoney extends Omise_Payment_Offsite
    88{
     9    /**
     10     * Backends identifier
     11     * @var string
     12     */
     13    const WALLET = 'truemoney';
     14    const JUMPAPP = 'truemoney_jumpapp';
     15
    916    public function __construct()
    1017    {
     
    1320        $this->id                 = 'omise_truemoney';
    1421        $this->has_fields         = true;
    15         $this->method_title       = __( 'Opn Payments TrueMoney Wallet', 'omise' );
     22        $this->method_title       = __( 'Opn Payments TrueMoney', 'omise' );
    1623        $this->method_description = wp_kses(
    17             __( 'Accept payments through <strong>TrueMoney Wallet</strong> via Opn Payments payment gateway (only available in Thailand).', 'omise' ),
     24            __( 'Accept payments through <strong>TrueMoney</strong> via Opn Payments payment gateway (only available in Thailand).', 'omise' ),
    1825            array( 'strong' => array() )
    1926        );
     
    2734        $this->description          = $this->get_option( 'description' );
    2835        $this->restricted_countries = array( 'TH' );
    29         $this->source_type          = 'truemoney';
     36        $this->source_type        = $this->get_source();
    3037
    3138        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     
    4451                'title'   => __( 'Enable/Disable', 'omise' ),
    4552                'type'    => 'checkbox',
    46                 'label'   => __( 'Enable Opn Payments TrueMoney Wallet Payment', 'omise' ),
     53                'label'   => __( 'Enable Opn Payments TrueMoney Payment', 'omise' ),
    4754                'default' => 'no'
    4855            ),
     
    5259                'type'        => 'text',
    5360                'description' => __( 'This controls the title the user sees during checkout.', 'omise' ),
    54                 'default'     => __( 'TrueMoney Wallet', 'omise' ),
     61                'default'     => __( 'TrueMoney', 'omise' ),
    5562            ),
    5663
     
    6976    {
    7077        parent::payment_fields();
    71         Omise_Util::render_view( 'templates/payment/form-truemoney.php', array() );
     78        if (self::WALLET === $this->source_type) {
     79            Omise_Util::render_view( 'templates/payment/form-truemoney.php', [] );
     80        }
    7281    }
    7382
     
    8392    public function get_charge_request($order_id, $order)
    8493    {
    85         $phoneOption = $_POST['omise_phone_number_default'];
    86         $isPhoneOptionChecked = isset($phoneOption) && 1 == $phoneOption;
    87         $phone_number = $isPhoneOptionChecked ?
    88             $order->get_billing_phone() :
    89             sanitize_text_field( $_POST['omise_phone_number'] );
    90 
    91         $requestData = $this->build_charge_request(
     94        $request_data = $this->build_charge_request(
    9295            $order_id,
    9396            $order,
     
    9598            $this->id . '_callback'
    9699        );
    97         $requestData['source'] = array_merge($requestData['source'], [
    98             'phone_number' => $phone_number
    99         ]);
    100100
    101         return $requestData;
     101        if (self::WALLET === $this->source_type) {
     102            $phone_option = $_POST['omise_phone_number_default'];
     103            $is_phone_option_checked = isset($phone_option) && 1 == $phone_option;
     104            $phone_number = $is_phone_option_checked ?
     105                $order->get_billing_phone() :
     106                sanitize_text_field( $_POST['omise_phone_number'] );
     107
     108            $request_data['source'] = array_merge($request_data['source'], [
     109                'phone_number' => $phone_number
     110            ]);
     111        }
     112
     113        return $request_data;
     114    }
     115
     116    /**
     117     * Return the right ShopeePay backend depending on the platform and availability of
     118     * the backend in the capability
     119     */
     120    public function get_source()
     121    {
     122        $capabilities = Omise_Capabilities::retrieve();
     123
     124        if (!$capabilities) {
     125            return self::JUMPAPP;
     126        }
     127
     128        $is_jumpapp_enabled = $capabilities->get_truemoney_backend(self::JUMPAPP);
     129        $is_wallet_enabled = $capabilities->get_truemoney_backend(self::WALLET);
     130
     131        if (!empty($is_wallet_enabled) && empty($is_jumpapp_enabled)) {
     132            return self::WALLET;
     133        }
     134
     135        // Return JUMP APP for the following cases:
     136        // Case 1: Both jumpapp and wallet are enabled
     137        // Case 2: jumpapp is enabled and wallet is disabled
     138        // Case 3: Both are disabled.
     139        return self::JUMPAPP;
    102140    }
    103141}
  • omise/tags/5.7.0/omise-woocommerce.php

    r3006639 r3021743  
    55 * Plugin URI:  https://www.omise.co/woocommerce
    66 * 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.
    7  * Version:     5.6.2
     7 * Version:     5.7.0
    88 * Author:      Opn Payments and contributors
    99 * Author URI:  https://github.com/omise/omise-woocommerce/graphs/contributors
     
    2323     * @var string
    2424     */
    25     public $version = '5.6.2';
     25    public $version = '5.7.0';
    2626
    2727    /**
  • omise/tags/5.7.0/readme.txt

    r3006639 r3021743  
    11=== Opn Payments ===
    22Contributors: Opn Payments
    3 Tags: opn payments, payment, payment gateway, woocommerce plugin, omise, opn, installment, internet banking, alipay, paynow, truemoney wallet, woocommerce payment
     3Tags: opn payments, payment, payment gateway, woocommerce plugin, omise, opn, installment, internet banking, alipay, paynow, truemoney, woocommerce payment
    44Requires at least: 4.3.1
    55Tested up to: 6.4.2
    6 Stable tag: 5.6.2
     6Stable tag: 5.7.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 5.7.0 =
     38
     39- Added TrueMoney jumpapp. (PR [#431](https://github.com/omise/omise-woocommerce/pull/431))
     40- Updated README.md. (PR [#429](https://github.com/omise/omise-woocommerce/pull/429))
    3641
    3742= 5.6.2 =
  • omise/tags/5.7.0/tests/unit/includes/class-omise-capabilities-test.php

    r2962817 r3021743  
    11<?php
    22
    3 use PHPUnit\Framework\TestCase;
     3require_once __DIR__ . '/gateway/bootstrap-test-setup.php';
    44
    5 class Omise_Capabilities_Test extends TestCase
     5/**
     6 * @runTestsInSeparateProcesses
     7 */
     8class Omise_Capabilities_Test extends Bootstrap_Test_Setup
    69{
    710    private $omiseSettingMock;
     
    1417    public function setUp(): void
    1518    {
     19        parent::setUp();
     20
     21        Mockery::mock('Omise_Payment_Offsite');
    1622        require_once __DIR__ . '/../../../includes/class-omise-capabilities.php';
     23        require_once __DIR__ . '/../../../includes/gateway/class-omise-payment-truemoney.php';
    1724        $this->omiseSettingMock = Mockery::mock('alias:Omise_Setting');
    1825        $this->omiseCapabilitiesMock = Mockery::mock('alias:OmiseCapabilities');
     
    2027
    2128    /**
    22      * close mockery after test cases are done
    23      */
    24     public function tearDown(): void
    25     {
    26         Mockery::close();
    27     }
    28 
    29     /**
    3029     * @dataProvider retrieve_data_provider
    31      * @runInSeparateProcess
    3230     * @covers Omise_Capabilities
    3331     */
    3432    public function test_retrieve_should_return_value_when_it_should_call_api($isCheckout, $isThankYouPage, $isAdmin, $adminPageName, $expected)
    35     {   
     33    {
    3634        // assigning to global variable, so that we can use in child functions
    3735        $GLOBALS['isCheckout'] = $isCheckout;
     
    4240        $_GET['page'] = $adminPageName;
    4341
    44         function is_checkout() { return $GLOBALS['isCheckout']; }
    45         function is_wc_endpoint_url($page) { return $GLOBALS['isThankYouPage']; }
    46         function is_admin() { return $GLOBALS['isAdmin']; }
     42        Brain\Monkey\Functions\expect('is_admin')
     43            ->with('123')
     44            ->andReturn($GLOBALS['isAdmin']);
     45        Brain\Monkey\Functions\expect('is_checkout')
     46            ->with('123')
     47            ->andReturn($GLOBALS['isCheckout']);
     48        Brain\Monkey\Functions\expect('is_wc_endpoint_url')
     49            ->with('123')
     50            ->andReturn($GLOBALS['isThankYouPage']);
    4751
    4852        if ($expected) {
     
    6771            // checkout page and not thank you page
    6872            [true, false, false, '', true],
    69             // // checkout page and also thank you page
     73            // checkout page and also thank you page
    7074            [true, true, false, '', false],
    71             // // omise setting page
     75            // omise setting page
    7276            [true, true, true, 'omise', true],
    73             // // other admin page
     77            // other admin page
    7478            [true, true, true, 'other-page', false],
    75             // // non checkout page and also no-admin page
     79            // non checkout page and also no-admin page
    7680            [false, false, false, 'other-page', false],
    77             // // non checkout page, non admin page
     81            // non checkout page, non admin page
    7882            [false, false, false, '', false],
    7983        ];
    8084    }
     85
     86    /**
     87     * @test
     88     */
     89    public function test_get_truemoney_backend_returns_null_when_invalid_payment_is_passed()
     90    {
     91        Brain\Monkey\Functions\expect('is_admin')
     92            ->with('123')
     93            ->andReturn(true);
     94
     95        Brain\Monkey\Functions\expect('is_checkout')
     96            ->with('123')
     97            ->andReturn(true);
     98
     99        Brain\Monkey\Functions\expect('is_wc_endpoint_url')
     100            ->with('123')
     101            ->andReturn(false);
     102
     103        $capabilities = new Omise_Capabilities;
     104        $is_enabled = $capabilities->get_truemoney_backend('abc');
     105        $this->assertNull($is_enabled);
     106    }
     107
     108    public function truemoney_source_provider()
     109    {
     110        return [ ['abc', false], ['truemoney', true], ['truemoney_jumpapp', true] ];
     111    }
    81112}
     113
     114class Omise_Payment_Truemoney_Stub
     115{
     116    /**
     117     * Backends identifier
     118     * @var string
     119     */
     120    const WALLET = 'truemoney';
     121    const JUMPAPP = 'truemoney_jumpapp';
     122}
  • omise/tags/5.7.0/tests/unit/includes/gateway/bootstrap-test-setup.php

    r2996251 r3021743  
    22
    33use PHPUnit\Framework\TestCase;
    4 use Brain;
     4
    55
    66abstract class Bootstrap_Test_Setup extends TestCase
  • omise/tags/5.7.0/tests/unit/includes/gateway/class-omise-payment-alipayplus-hk-test.php

    r2979883 r3021743  
    33require_once __DIR__ . '/class-omise-offsite-test.php';
    44
     5/**
     6 * @runTestsInSeparateProcesses
     7 */
    58class Omise_Payment_Alipay_Hk_Test extends Omise_Offsite_Test
    69{
  • omise/tags/5.7.0/tests/unit/includes/gateway/class-omise-payment-alipayplus-kakaopay-test.php

    r2979883 r3021743  
    33require_once __DIR__ . '/class-omise-offsite-test.php';
    44
     5/**
     6 * @runTestsInSeparateProcesses
     7 */
    58class Omise_Payment_Kakaopay_Test extends Omise_Offsite_Test
    69{
  • omise/tags/5.7.0/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php

    r2996251 r3021743  
    22
    33use PHPUnit\Framework\TestCase;
    4 use Brain;
    54
    65class Omise_Payment_CreditCard_Test extends TestCase
  • omise/tags/5.7.0/tests/unit/includes/gateway/class-omise-payment-mobilebanking-test.php

    r2979883 r3021743  
    1414    public function testCharge()
    1515    {
     16        Brain\Monkey\Functions\expect('wc_get_user_agent')
     17            ->with('123')
     18            ->andReturn('Chrome Web');
    1619        $_POST['omise-offsite'] = 'mobile_banking_bbl';
    1720        $obj = new Omise_Payment_Mobilebanking();
  • omise/tags/5.7.0/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php

    r3006639 r3021743  
    1919            function plugins_url() {
    2020                return "http://localhost";
    21             }
    22         }
    23 
    24         if (!function_exists('wc_get_user_agent')) {
    25             function wc_get_user_agent() {
    26                 return "Chrome Web";
    2721            }
    2822        }
     
    8680    public function testCharge()
    8781    {
     82        Brain\Monkey\Functions\expect('wc_get_user_agent')
     83            ->with('123')
     84            ->andReturn('Chrome Web');
    8885        $this->getChargeTest($this->obj);
    8986    }
  • omise/tags/5.7.0/tests/unit/includes/gateway/class-omise-payment-ocbc-pao-test.php

    r2979883 r3021743  
    2727    public function testCharge()
    2828    {
     29        Brain\Monkey\Functions\expect('wc_get_user_agent')
     30            ->with('123')
     31            ->andReturn('Chrome Web');
    2932        $this->getChargeTest($this->obj);
    3033    }
  • omise/tags/5.7.0/tests/unit/includes/gateway/class-omise-payment-truemoney-test.php

    r2979883 r3021743  
    55class Omise_Payment_Truemoney_Test extends Omise_Offsite_Test
    66{
     7    private $omise_capability_mock;
     8
    79    public function setUp(): void
    810    {
    911        $this->sourceType = 'truemoney';
    1012        parent::setUp();
     13        Brain\Monkey\Functions\expect('is_admin')
     14            ->with('123')
     15            ->andReturn(true);
     16        Brain\Monkey\Functions\expect('is_checkout')
     17            ->with('123')
     18            ->andReturn(true);
     19        Brain\Monkey\Functions\expect('is_wc_endpoint_url')
     20            ->with('123')
     21            ->andReturn(true);
    1122        require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-truemoney.php';
     23        $this->omise_capability_mock = Mockery::mock('alias:Omise_Capabilities');
    1224    }
    1325
    14     public function testGetChargeRequest()
     26    public function test_get_charge_request()
    1527    {
     28        $this->omise_capability_mock->shouldReceive('retrieve')->once();
     29        // set source type to truemoney wallet
    1630        $obj = new Omise_Payment_Truemoney();
    17 
    18         $orderId = 'order_123';
    19         $expectedAmount = 999999;
    20         $expectedCurrency = 'thb';
    21         $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency);
     31        $obj->source_type = 'truemoney';
     32        $order_id = 'order_123';
     33        $expected_amount = 999999;
     34        $expected_currency = 'thb';
     35        $order_mock = $this->getOrderMock($expected_amount, $expected_currency);
    2236
    2337        $_POST['omise_phone_number_default'] = true;
    24         $result = $obj->get_charge_request($orderId, $orderMock);
     38        $result = $obj->get_charge_request($order_id, $order_mock);
    2539
    26         $this->assertEquals($orderMock->get_billing_phone(), $result['source']['phone_number']);
    27 
    28         unset($_POST['omise_phone_number_default']);
    29         unset($obj);
     40        $this->assertEquals($order_mock->get_billing_phone(), $result['source']['phone_number']);
    3041    }
    3142
    32     public function testGetChargeRequestWhenCustomerOverridesDefaultPhone()
     43    public function test_get_charge_request_when_customer_overrides_default_phone()
    3344    {
     45        $this->omise_capability_mock->shouldReceive('retrieve')->once();
     46        $order_id = 'order_123';
     47        $expected_amount = 999999;
     48        $expected_currency = 'thb';
     49        $order_mock = $this->getOrderMock($expected_amount, $expected_currency);
     50
     51        $_POST['omise_phone_number'] = '1234567890';
     52
    3453        $obj = new Omise_Payment_Truemoney();
    35 
    36         $orderId = 'order_123';
    37         $expectedAmount = 999999;
    38         $expectedCurrency = 'thb';
    39         $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency);
    40 
    41         $_POST['omise_phone_number_default'] = false;
    42         $_POST['omise_phone_number'] = '1234567890';
    43        
    44         $result = $obj->get_charge_request($orderId, $orderMock);
     54        $result = $obj->get_charge_request($order_id, $order_mock);
    4555
    4656        $this->assertEquals($this->sourceType, $result['source']['type']);
    4757    }
    4858
    49     public function testCharge()
     59    public function test_charge()
    5060    {
     61        $this->omise_capability_mock->shouldReceive('retrieve')->once();
    5162        $_POST['omise_phone_number_default'] = true;
    5263        $obj = new Omise_Payment_Truemoney();
    5364        $this->getChargeTest($obj);
    5465    }
     66
     67    public function test_get_source_returns_jumpapp()
     68    {
     69        $this->omise_capability_mock->shouldReceive('retrieve');
     70        $obj = new Omise_Payment_Truemoney();
     71        $source_type = $obj->get_source();
     72        $this->assertEquals('truemoney_jumpapp', $source_type);
     73    }
     74
     75    public function test_get_source_returns_wallet()
     76    {
     77        $this->omise_capability_mock->shouldReceive('retrieve')
     78            ->andReturn(new class() {
     79                public function get_truemoney_backend($source_type) {
     80                    if ('truemoney' === $source_type) {
     81                        return (object)[
     82                            'truemoney' => [
     83                                'type' => 'truemoney',
     84                                'currencies' => [
     85                                    'thb'
     86                                ],
     87                                'amount' => [
     88                                    'min' => 2000,
     89                                    'max' => 500000000000
     90                                ]
     91                            ]
     92                        ];
     93                    }
     94
     95                    return null;
     96                }
     97            });
     98
     99        $obj = new Omise_Payment_Truemoney();
     100        $source_type = $obj->get_source();
     101        $this->assertEquals('truemoney', $source_type);
     102    }
     103
     104    public function test_get_source_returns_jumpapp_when_both_are_enabled()
     105    {
     106        $this->omise_capability_mock->shouldReceive('retrieve')
     107            ->andReturn(new class() {
     108                public function get_truemoney_backend($source_type) {
     109                    if ('truemoney' === $source_type) {
     110                        return (object)[
     111                            'truemoney' => [
     112                                'type' => 'truemoney',
     113                                'currencies' => [
     114                                    'thb'
     115                                ],
     116                                'amount' => [
     117                                    'min' => 2000,
     118                                    'max' => 500000000000
     119                                ]
     120                            ]
     121                        ];
     122                    }
     123
     124                    return (object)[
     125                        'truemoney_jumpapp' => [
     126                            'type' => 'truemoney_jumpapp',
     127                            'currencies' => [
     128                                'thb'
     129                            ],
     130                            'amount' => [
     131                                'min' => 2000,
     132                                'max' => 500000000000
     133                            ]
     134                        ]
     135                    ];
     136                }
     137            });
     138
     139        $obj = new Omise_Payment_Truemoney();
     140        $source_type = $obj->get_source();
     141        $this->assertEquals('truemoney_jumpapp', $source_type);
     142    }
    55143}
  • omise/trunk/CHANGELOG.md

    r3006639 r3021743  
    11# CHANGELOG
     2
     3## [v5.7.0 _(Jan 11, 2024)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.7.0)
     4- Added TrueMoney jumpapp. (PR [#431](https://github.com/omise/omise-woocommerce/pull/431))
     5- Updated README.md. (PR [#429](https://github.com/omise/omise-woocommerce/pull/429))
    26
    37## [v5.6.2 _(Dec 7, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.6.2)
  • omise/trunk/README.md

    r2501457 r3021743  
    11<!--- KEEP START --->
    2 [![Omise](https://cdn.omise.co/assets/omise.png)](https://www.omise.co/developers)
     2[![Opn Payments](https://www.opn.ooo/assets/svg/logo-opn-full.svg)](https://www.opn.ooo)
    33
    4 [Omise](https://www.omise.co/) is a payment service provider operating in Thailand, Japan, and Singapore.
    5 Omise provides a set of APIs that help merchants of any size accept payments online. 
     4[Opn Payments](https://www.opn.ooo) is a payment service provider operating in Thailand, Japan, and Singapore.
     5Opn Payments provides a set of APIs that help merchants of any size accept payments online. 
    66<!--- KEEP END --->
    77
    8 **Omise WooCommerce** is our official plugin providing support for processing payments on WooCommerce through Omise.
    9 
    10 ![PHP Composer](https://github.com/omise/omise-woocommerce/workflows/PHP%20Composer/badge.svg)
     8**Omise WooCommerce** is our official plugin providing support for processing payments on WooCommerce through Opn Payments.
    119
    1210## Usage
    1311
    14 See our [official docs](https://www.omise.co/woocommerce-plugin) for details on installation and configuration.
     12See our [official docs](https://docs.opn.ooo/woocommerce-plugin) for details on installation and configuration.
    1513
    1614## Contributing
  • omise/trunk/includes/class-omise-capabilities.php

    r2962817 r3021743  
    252252        return $this->capabilities['limits']['installment_amount']['min'];
    253253    }
     254
     255    /**
     256     * Retrieves details of TrueMoney from capabilities.
     257     *
     258     * @param string $source_type
     259     */
     260    public function get_truemoney_backend($source_type)
     261    {
     262        $truemoney_source_types = [Omise_Payment_Truemoney::WALLET, Omise_Payment_Truemoney::JUMPAPP];
     263
     264        if (!in_array($source_type, $truemoney_source_types)) {
     265            return null;
     266        }
     267
     268        return $this->getBackendByType($source_type);
     269    }
    254270}
  • omise/trunk/includes/gateway/class-omise-payment-truemoney.php

    r2979883 r3021743  
    77class Omise_Payment_Truemoney extends Omise_Payment_Offsite
    88{
     9    /**
     10     * Backends identifier
     11     * @var string
     12     */
     13    const WALLET = 'truemoney';
     14    const JUMPAPP = 'truemoney_jumpapp';
     15
    916    public function __construct()
    1017    {
     
    1320        $this->id                 = 'omise_truemoney';
    1421        $this->has_fields         = true;
    15         $this->method_title       = __( 'Opn Payments TrueMoney Wallet', 'omise' );
     22        $this->method_title       = __( 'Opn Payments TrueMoney', 'omise' );
    1623        $this->method_description = wp_kses(
    17             __( 'Accept payments through <strong>TrueMoney Wallet</strong> via Opn Payments payment gateway (only available in Thailand).', 'omise' ),
     24            __( 'Accept payments through <strong>TrueMoney</strong> via Opn Payments payment gateway (only available in Thailand).', 'omise' ),
    1825            array( 'strong' => array() )
    1926        );
     
    2734        $this->description          = $this->get_option( 'description' );
    2835        $this->restricted_countries = array( 'TH' );
    29         $this->source_type          = 'truemoney';
     36        $this->source_type        = $this->get_source();
    3037
    3138        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     
    4451                'title'   => __( 'Enable/Disable', 'omise' ),
    4552                'type'    => 'checkbox',
    46                 'label'   => __( 'Enable Opn Payments TrueMoney Wallet Payment', 'omise' ),
     53                'label'   => __( 'Enable Opn Payments TrueMoney Payment', 'omise' ),
    4754                'default' => 'no'
    4855            ),
     
    5259                'type'        => 'text',
    5360                'description' => __( 'This controls the title the user sees during checkout.', 'omise' ),
    54                 'default'     => __( 'TrueMoney Wallet', 'omise' ),
     61                'default'     => __( 'TrueMoney', 'omise' ),
    5562            ),
    5663
     
    6976    {
    7077        parent::payment_fields();
    71         Omise_Util::render_view( 'templates/payment/form-truemoney.php', array() );
     78        if (self::WALLET === $this->source_type) {
     79            Omise_Util::render_view( 'templates/payment/form-truemoney.php', [] );
     80        }
    7281    }
    7382
     
    8392    public function get_charge_request($order_id, $order)
    8493    {
    85         $phoneOption = $_POST['omise_phone_number_default'];
    86         $isPhoneOptionChecked = isset($phoneOption) && 1 == $phoneOption;
    87         $phone_number = $isPhoneOptionChecked ?
    88             $order->get_billing_phone() :
    89             sanitize_text_field( $_POST['omise_phone_number'] );
    90 
    91         $requestData = $this->build_charge_request(
     94        $request_data = $this->build_charge_request(
    9295            $order_id,
    9396            $order,
     
    9598            $this->id . '_callback'
    9699        );
    97         $requestData['source'] = array_merge($requestData['source'], [
    98             'phone_number' => $phone_number
    99         ]);
    100100
    101         return $requestData;
     101        if (self::WALLET === $this->source_type) {
     102            $phone_option = $_POST['omise_phone_number_default'];
     103            $is_phone_option_checked = isset($phone_option) && 1 == $phone_option;
     104            $phone_number = $is_phone_option_checked ?
     105                $order->get_billing_phone() :
     106                sanitize_text_field( $_POST['omise_phone_number'] );
     107
     108            $request_data['source'] = array_merge($request_data['source'], [
     109                'phone_number' => $phone_number
     110            ]);
     111        }
     112
     113        return $request_data;
     114    }
     115
     116    /**
     117     * Return the right ShopeePay backend depending on the platform and availability of
     118     * the backend in the capability
     119     */
     120    public function get_source()
     121    {
     122        $capabilities = Omise_Capabilities::retrieve();
     123
     124        if (!$capabilities) {
     125            return self::JUMPAPP;
     126        }
     127
     128        $is_jumpapp_enabled = $capabilities->get_truemoney_backend(self::JUMPAPP);
     129        $is_wallet_enabled = $capabilities->get_truemoney_backend(self::WALLET);
     130
     131        if (!empty($is_wallet_enabled) && empty($is_jumpapp_enabled)) {
     132            return self::WALLET;
     133        }
     134
     135        // Return JUMP APP for the following cases:
     136        // Case 1: Both jumpapp and wallet are enabled
     137        // Case 2: jumpapp is enabled and wallet is disabled
     138        // Case 3: Both are disabled.
     139        return self::JUMPAPP;
    102140    }
    103141}
  • omise/trunk/omise-woocommerce.php

    r3006639 r3021743  
    55 * Plugin URI:  https://www.omise.co/woocommerce
    66 * 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.
    7  * Version:     5.6.2
     7 * Version:     5.7.0
    88 * Author:      Opn Payments and contributors
    99 * Author URI:  https://github.com/omise/omise-woocommerce/graphs/contributors
     
    2323     * @var string
    2424     */
    25     public $version = '5.6.2';
     25    public $version = '5.7.0';
    2626
    2727    /**
  • omise/trunk/readme.txt

    r3006639 r3021743  
    11=== Opn Payments ===
    22Contributors: Opn Payments
    3 Tags: opn payments, payment, payment gateway, woocommerce plugin, omise, opn, installment, internet banking, alipay, paynow, truemoney wallet, woocommerce payment
     3Tags: opn payments, payment, payment gateway, woocommerce plugin, omise, opn, installment, internet banking, alipay, paynow, truemoney, woocommerce payment
    44Requires at least: 4.3.1
    55Tested up to: 6.4.2
    6 Stable tag: 5.6.2
     6Stable tag: 5.7.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 5.7.0 =
     38
     39- Added TrueMoney jumpapp. (PR [#431](https://github.com/omise/omise-woocommerce/pull/431))
     40- Updated README.md. (PR [#429](https://github.com/omise/omise-woocommerce/pull/429))
    3641
    3742= 5.6.2 =
  • omise/trunk/tests/unit/includes/class-omise-capabilities-test.php

    r2962817 r3021743  
    11<?php
    22
    3 use PHPUnit\Framework\TestCase;
     3require_once __DIR__ . '/gateway/bootstrap-test-setup.php';
    44
    5 class Omise_Capabilities_Test extends TestCase
     5/**
     6 * @runTestsInSeparateProcesses
     7 */
     8class Omise_Capabilities_Test extends Bootstrap_Test_Setup
    69{
    710    private $omiseSettingMock;
     
    1417    public function setUp(): void
    1518    {
     19        parent::setUp();
     20
     21        Mockery::mock('Omise_Payment_Offsite');
    1622        require_once __DIR__ . '/../../../includes/class-omise-capabilities.php';
     23        require_once __DIR__ . '/../../../includes/gateway/class-omise-payment-truemoney.php';
    1724        $this->omiseSettingMock = Mockery::mock('alias:Omise_Setting');
    1825        $this->omiseCapabilitiesMock = Mockery::mock('alias:OmiseCapabilities');
     
    2027
    2128    /**
    22      * close mockery after test cases are done
    23      */
    24     public function tearDown(): void
    25     {
    26         Mockery::close();
    27     }
    28 
    29     /**
    3029     * @dataProvider retrieve_data_provider
    31      * @runInSeparateProcess
    3230     * @covers Omise_Capabilities
    3331     */
    3432    public function test_retrieve_should_return_value_when_it_should_call_api($isCheckout, $isThankYouPage, $isAdmin, $adminPageName, $expected)
    35     {   
     33    {
    3634        // assigning to global variable, so that we can use in child functions
    3735        $GLOBALS['isCheckout'] = $isCheckout;
     
    4240        $_GET['page'] = $adminPageName;
    4341
    44         function is_checkout() { return $GLOBALS['isCheckout']; }
    45         function is_wc_endpoint_url($page) { return $GLOBALS['isThankYouPage']; }
    46         function is_admin() { return $GLOBALS['isAdmin']; }
     42        Brain\Monkey\Functions\expect('is_admin')
     43            ->with('123')
     44            ->andReturn($GLOBALS['isAdmin']);
     45        Brain\Monkey\Functions\expect('is_checkout')
     46            ->with('123')
     47            ->andReturn($GLOBALS['isCheckout']);
     48        Brain\Monkey\Functions\expect('is_wc_endpoint_url')
     49            ->with('123')
     50            ->andReturn($GLOBALS['isThankYouPage']);
    4751
    4852        if ($expected) {
     
    6771            // checkout page and not thank you page
    6872            [true, false, false, '', true],
    69             // // checkout page and also thank you page
     73            // checkout page and also thank you page
    7074            [true, true, false, '', false],
    71             // // omise setting page
     75            // omise setting page
    7276            [true, true, true, 'omise', true],
    73             // // other admin page
     77            // other admin page
    7478            [true, true, true, 'other-page', false],
    75             // // non checkout page and also no-admin page
     79            // non checkout page and also no-admin page
    7680            [false, false, false, 'other-page', false],
    77             // // non checkout page, non admin page
     81            // non checkout page, non admin page
    7882            [false, false, false, '', false],
    7983        ];
    8084    }
     85
     86    /**
     87     * @test
     88     */
     89    public function test_get_truemoney_backend_returns_null_when_invalid_payment_is_passed()
     90    {
     91        Brain\Monkey\Functions\expect('is_admin')
     92            ->with('123')
     93            ->andReturn(true);
     94
     95        Brain\Monkey\Functions\expect('is_checkout')
     96            ->with('123')
     97            ->andReturn(true);
     98
     99        Brain\Monkey\Functions\expect('is_wc_endpoint_url')
     100            ->with('123')
     101            ->andReturn(false);
     102
     103        $capabilities = new Omise_Capabilities;
     104        $is_enabled = $capabilities->get_truemoney_backend('abc');
     105        $this->assertNull($is_enabled);
     106    }
     107
     108    public function truemoney_source_provider()
     109    {
     110        return [ ['abc', false], ['truemoney', true], ['truemoney_jumpapp', true] ];
     111    }
    81112}
     113
     114class Omise_Payment_Truemoney_Stub
     115{
     116    /**
     117     * Backends identifier
     118     * @var string
     119     */
     120    const WALLET = 'truemoney';
     121    const JUMPAPP = 'truemoney_jumpapp';
     122}
  • omise/trunk/tests/unit/includes/gateway/bootstrap-test-setup.php

    r2996251 r3021743  
    22
    33use PHPUnit\Framework\TestCase;
    4 use Brain;
     4
    55
    66abstract class Bootstrap_Test_Setup extends TestCase
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-alipayplus-hk-test.php

    r2979883 r3021743  
    33require_once __DIR__ . '/class-omise-offsite-test.php';
    44
     5/**
     6 * @runTestsInSeparateProcesses
     7 */
    58class Omise_Payment_Alipay_Hk_Test extends Omise_Offsite_Test
    69{
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-alipayplus-kakaopay-test.php

    r2979883 r3021743  
    33require_once __DIR__ . '/class-omise-offsite-test.php';
    44
     5/**
     6 * @runTestsInSeparateProcesses
     7 */
    58class Omise_Payment_Kakaopay_Test extends Omise_Offsite_Test
    69{
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php

    r2996251 r3021743  
    22
    33use PHPUnit\Framework\TestCase;
    4 use Brain;
    54
    65class Omise_Payment_CreditCard_Test extends TestCase
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-mobilebanking-test.php

    r2979883 r3021743  
    1414    public function testCharge()
    1515    {
     16        Brain\Monkey\Functions\expect('wc_get_user_agent')
     17            ->with('123')
     18            ->andReturn('Chrome Web');
    1619        $_POST['omise-offsite'] = 'mobile_banking_bbl';
    1720        $obj = new Omise_Payment_Mobilebanking();
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php

    r3006639 r3021743  
    1919            function plugins_url() {
    2020                return "http://localhost";
    21             }
    22         }
    23 
    24         if (!function_exists('wc_get_user_agent')) {
    25             function wc_get_user_agent() {
    26                 return "Chrome Web";
    2721            }
    2822        }
     
    8680    public function testCharge()
    8781    {
     82        Brain\Monkey\Functions\expect('wc_get_user_agent')
     83            ->with('123')
     84            ->andReturn('Chrome Web');
    8885        $this->getChargeTest($this->obj);
    8986    }
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-ocbc-pao-test.php

    r2979883 r3021743  
    2727    public function testCharge()
    2828    {
     29        Brain\Monkey\Functions\expect('wc_get_user_agent')
     30            ->with('123')
     31            ->andReturn('Chrome Web');
    2932        $this->getChargeTest($this->obj);
    3033    }
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-truemoney-test.php

    r2979883 r3021743  
    55class Omise_Payment_Truemoney_Test extends Omise_Offsite_Test
    66{
     7    private $omise_capability_mock;
     8
    79    public function setUp(): void
    810    {
    911        $this->sourceType = 'truemoney';
    1012        parent::setUp();
     13        Brain\Monkey\Functions\expect('is_admin')
     14            ->with('123')
     15            ->andReturn(true);
     16        Brain\Monkey\Functions\expect('is_checkout')
     17            ->with('123')
     18            ->andReturn(true);
     19        Brain\Monkey\Functions\expect('is_wc_endpoint_url')
     20            ->with('123')
     21            ->andReturn(true);
    1122        require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-truemoney.php';
     23        $this->omise_capability_mock = Mockery::mock('alias:Omise_Capabilities');
    1224    }
    1325
    14     public function testGetChargeRequest()
     26    public function test_get_charge_request()
    1527    {
     28        $this->omise_capability_mock->shouldReceive('retrieve')->once();
     29        // set source type to truemoney wallet
    1630        $obj = new Omise_Payment_Truemoney();
    17 
    18         $orderId = 'order_123';
    19         $expectedAmount = 999999;
    20         $expectedCurrency = 'thb';
    21         $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency);
     31        $obj->source_type = 'truemoney';
     32        $order_id = 'order_123';
     33        $expected_amount = 999999;
     34        $expected_currency = 'thb';
     35        $order_mock = $this->getOrderMock($expected_amount, $expected_currency);
    2236
    2337        $_POST['omise_phone_number_default'] = true;
    24         $result = $obj->get_charge_request($orderId, $orderMock);
     38        $result = $obj->get_charge_request($order_id, $order_mock);
    2539
    26         $this->assertEquals($orderMock->get_billing_phone(), $result['source']['phone_number']);
    27 
    28         unset($_POST['omise_phone_number_default']);
    29         unset($obj);
     40        $this->assertEquals($order_mock->get_billing_phone(), $result['source']['phone_number']);
    3041    }
    3142
    32     public function testGetChargeRequestWhenCustomerOverridesDefaultPhone()
     43    public function test_get_charge_request_when_customer_overrides_default_phone()
    3344    {
     45        $this->omise_capability_mock->shouldReceive('retrieve')->once();
     46        $order_id = 'order_123';
     47        $expected_amount = 999999;
     48        $expected_currency = 'thb';
     49        $order_mock = $this->getOrderMock($expected_amount, $expected_currency);
     50
     51        $_POST['omise_phone_number'] = '1234567890';
     52
    3453        $obj = new Omise_Payment_Truemoney();
    35 
    36         $orderId = 'order_123';
    37         $expectedAmount = 999999;
    38         $expectedCurrency = 'thb';
    39         $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency);
    40 
    41         $_POST['omise_phone_number_default'] = false;
    42         $_POST['omise_phone_number'] = '1234567890';
    43        
    44         $result = $obj->get_charge_request($orderId, $orderMock);
     54        $result = $obj->get_charge_request($order_id, $order_mock);
    4555
    4656        $this->assertEquals($this->sourceType, $result['source']['type']);
    4757    }
    4858
    49     public function testCharge()
     59    public function test_charge()
    5060    {
     61        $this->omise_capability_mock->shouldReceive('retrieve')->once();
    5162        $_POST['omise_phone_number_default'] = true;
    5263        $obj = new Omise_Payment_Truemoney();
    5364        $this->getChargeTest($obj);
    5465    }
     66
     67    public function test_get_source_returns_jumpapp()
     68    {
     69        $this->omise_capability_mock->shouldReceive('retrieve');
     70        $obj = new Omise_Payment_Truemoney();
     71        $source_type = $obj->get_source();
     72        $this->assertEquals('truemoney_jumpapp', $source_type);
     73    }
     74
     75    public function test_get_source_returns_wallet()
     76    {
     77        $this->omise_capability_mock->shouldReceive('retrieve')
     78            ->andReturn(new class() {
     79                public function get_truemoney_backend($source_type) {
     80                    if ('truemoney' === $source_type) {
     81                        return (object)[
     82                            'truemoney' => [
     83                                'type' => 'truemoney',
     84                                'currencies' => [
     85                                    'thb'
     86                                ],
     87                                'amount' => [
     88                                    'min' => 2000,
     89                                    'max' => 500000000000
     90                                ]
     91                            ]
     92                        ];
     93                    }
     94
     95                    return null;
     96                }
     97            });
     98
     99        $obj = new Omise_Payment_Truemoney();
     100        $source_type = $obj->get_source();
     101        $this->assertEquals('truemoney', $source_type);
     102    }
     103
     104    public function test_get_source_returns_jumpapp_when_both_are_enabled()
     105    {
     106        $this->omise_capability_mock->shouldReceive('retrieve')
     107            ->andReturn(new class() {
     108                public function get_truemoney_backend($source_type) {
     109                    if ('truemoney' === $source_type) {
     110                        return (object)[
     111                            'truemoney' => [
     112                                'type' => 'truemoney',
     113                                'currencies' => [
     114                                    'thb'
     115                                ],
     116                                'amount' => [
     117                                    'min' => 2000,
     118                                    'max' => 500000000000
     119                                ]
     120                            ]
     121                        ];
     122                    }
     123
     124                    return (object)[
     125                        'truemoney_jumpapp' => [
     126                            'type' => 'truemoney_jumpapp',
     127                            'currencies' => [
     128                                'thb'
     129                            ],
     130                            'amount' => [
     131                                'min' => 2000,
     132                                'max' => 500000000000
     133                            ]
     134                        ]
     135                    ];
     136                }
     137            });
     138
     139        $obj = new Omise_Payment_Truemoney();
     140        $source_type = $obj->get_source();
     141        $this->assertEquals('truemoney_jumpapp', $source_type);
     142    }
    55143}
Note: See TracChangeset for help on using the changeset viewer.