Plugin Directory

Changeset 3361458


Ignore:
Timestamp:
09/15/2025 03:13:55 AM (7 months ago)
Author:
omise
Message:

Update to version 6.3.0 from GitHub

Location:
omise
Files:
6 added
36 edited
1 copied

Legend:

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

    r3331857 r3361458  
    11# CHANGELOG
     2
     3## [v6.3.0 _(Sep 3, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.3.0)
     4
     5- Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534))
     6- Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533))
    27
    38## [v6.2.2 _(Jul 22, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.2.2)
  • omise/tags/6.3.0/assets/javascripts/omise-payment-atome.js

    r2912289 r3361458  
    3939
    4040            const phoneNumber = $('#omise_atome_phone_number').val();
    41            
     41
    4242            if (!phoneNumber) {
    4343                return omiseHandleError('Phone number is required in Atome');
     
    5656
    5757    $(function () {
    58         $('form.checkout').on('checkout_place_order', function (e) {
     58        $('form.checkout, form#order_review').on('checkout_place_order', function () {
    5959            return omiseFormHandler();
    6060        });
  • omise/tags/6.3.0/assets/javascripts/omise-payment-form-handler.js

    r3192967 r3361458  
    11(function ($) {
    22    const $form = $('form.checkout, form#order_review');
     3    const $formCheckout = $('form.checkout'); // Form in Normal Checkout Page
     4    const $formOrderReview = $('form#order_review'); // Form in Pay for Order Page
    35
    46    function hideError() {
     
    276278        });
    277279
    278         $('form.checkout').unbind('checkout_place_order_omise');
    279         $('form.checkout').on('checkout_place_order_omise', function () {
     280        $($formCheckout).unbind('checkout_place_order_omise');
     281        $($formCheckout).on('checkout_place_order_omise', function () {
    280282            return omiseFormHandler();
    281283        });
    282         $('form.checkout').unbind('checkout_place_order_omise_installment');
    283         $('form.checkout').on('checkout_place_order_omise_installment', function () {
     284        $($formCheckout).unbind('checkout_place_order_omise_installment');
     285        $($formCheckout).on('checkout_place_order_omise_installment', function () {
    284286            return omiseInstallmentFormHandler();
    285287        });
    286288
    287         /* Pay Page Form */
    288         $('form#order_review').on('submit', function () {
    289             return omiseFormHandler();
     289        /* Pay for Order Page Form */
     290        $($formOrderReview).on('submit', function () {
     291            var selectedPaymentMethod = $('input[name="payment_method"]:checked').val();
     292
     293            switch (selectedPaymentMethod) {
     294                case 'omise':
     295                    return omiseFormHandler();
     296                case 'omise_installment':
     297                    return omiseInstallmentFormHandler();
     298            }
    290299        });
    291300
    292301        /* Both Forms */
    293         $('form.checkout, form#order_review').on('change', '#omise_cc_form input', function() {
     302        $($form).on('change', '#omise_cc_form input', function() {
    294303            $('.omise_token').remove();
    295304            $('.omise_source').remove();
    296305        });
    297306
    298         $('form.checkout').on('change', 'input[name="payment_method"]', function() {
     307        $($form).on('change', 'input[name="payment_method"]', function() {
    299308            setupOmiseForm();
    300309        });
  • omise/tags/6.3.0/includes/gateway/abstract-omise-payment-offsite.php

    r3308831 r3361458  
    1010{
    1111    use Charge_Request_Builder;
     12
     13    /**
     14     * @inheritdoc
     15     */
     16    public function payment_fields() {
     17        parent::payment_fields();
     18    }
    1219
    1320    /**
  • omise/tags/6.3.0/includes/gateway/class-omise-payment-atome.php

    r3256918 r3361458  
    103103        ];
    104104
    105         $currency = strtolower(get_woocommerce_currency());
    106105        $cart = WC()->cart;
    107 
    108         if ($cart->subtotal === 0) {
    109             return [
    110                 'status' => false,
    111                 'message' => 'Complimentary products cannot be billed.'
    112             ];
    113         }
    114 
    115         if (!isset($limits[$currency])) {
    116             return [
    117                 'status' => false,
    118                 'message' => 'Currency not supported'
    119             ];
    120         }
    121 
    122         $limit = $limits[$currency];
    123 
    124         if ($cart->total < $limit['min']) {
     106        $cart_subtotal = $cart->subtotal;
     107        $cart_total = $cart->total;
     108        $cart_currency = strtolower( get_woocommerce_currency() );
     109
     110        // For Pay for Order Page
     111        if ( is_checkout_pay_page() ) {
     112            $order_id = get_query_var('order-pay');
     113            $order = wc_get_order( $order_id );
     114            if ( ! $order ) {
     115                throw new Exception( 'Order not found.' );
     116            }
     117
     118            $cart_subtotal = $order->get_subtotal();
     119            $cart_total = $order->get_total();
     120            $cart_currency = strtolower( $order->get_currency() );
     121        }
     122
     123        if ( $cart_subtotal === 0 ) {
     124            return [
     125                'status' => false,
     126                'message' => 'Complimentary products cannot be billed.',
     127            ];
     128        }
     129
     130        if ( ! isset( $limits[ $cart_currency ] ) ) {
     131            return [
     132                'status' => false,
     133                'message' => 'Currency not supported',
     134            ];
     135        }
     136
     137        $limit = $limits[ $cart_currency ];
     138
     139        if ( $cart_total < $limit['min'] ) {
    125140            return [
    126141                'status' => false,
    127142                'message' => sprintf(
    128                     "Amount must be greater than %u %s",
    129                     number_format($limit['min'], 2),
    130                     strtoupper($currency)
    131                 )
    132             ];
    133         }
    134 
    135         if ($cart->total > $limit['max']) {
    136             return [
    137                 'status' => false,
    138                 'message' => __(
    139                     'Amount must be less than %1 %2',
    140                     number_format($limit['max'], 2),
    141                     strtoupper($currency)
    142                 )
    143             ];
    144         }
    145 
    146         return ['status' => true];
     143                    'Amount must be greater than %s %s',
     144                    number_format( $limit['min'], 2 ),
     145                    strtoupper($cart_currency),
     146                ),
     147            ];
     148        }
     149
     150        if ( $cart_total > $limit['max'] ) {
     151            return [
     152                'status' => false,
     153                'message' => sprintf(
     154                    'Amount must be less than %s %s',
     155                    number_format( $limit['max'], 2 ),
     156                    strtoupper( $cart_currency ),
     157                ),
     158            ];
     159        }
     160
     161        return [ 'status' => true ];
    147162    }
    148163
     
    164179            $this->id . "_callback"
    165180        );
    166        
     181
    167182        $default_phone_selected = isset($_POST['omise_atome_phone_default']) ?
    168183            $_POST['omise_atome_phone_default']
  • omise/tags/6.3.0/includes/gateway/class-omise-payment-installment.php

    r3308831 r3361458  
    130130            $this->id . "_callback"
    131131        );
    132         $requestData['description'] = 'staging';
    133132        $requestData['source'] = isset($_POST['omise_source']) ? wc_clean($_POST['omise_source']) : '';
    134133        $requestData['card'] = isset($_POST['omise_token']) ? wc_clean($_POST['omise_token']) : '';
     134
     135        $custom_wlb_desc = getenv('OMISE_CUSTOM_WLB_ORDER_DESC');
     136        if (!empty($custom_wlb_desc) && !empty($requestData['card'])) {
     137            $custom_wlb_desc = sanitize_text_field($custom_wlb_desc);
     138            $requestData['description'] = str_replace('{description}', $requestData['description'], $custom_wlb_desc);
     139        }
     140
    135141        return OmiseCharge::create($requestData);
    136142    }
  • omise/tags/6.3.0/includes/gateway/class-omise-payment.php

    r3308831 r3361458  
    114114        add_filter( 'woocommerce_email_recipient_new_order', 'OmisePluginHelperMailer::disable_merchant_order_on_hold', 10, 2 );
    115115        add_filter('is_protected_meta', [ $this, 'protectMetadata'], 10, 2);
     116    }
     117
     118    /**
     119     * Displayed payment fields.
     120     */
     121    public function payment_fields() {
     122        parent::payment_fields();
    116123    }
    117124
  • omise/tags/6.3.0/omise-woocommerce.php

    r3331857 r3361458  
    55 * Plugin URI:  https://www.omise.co/woocommerce
    66 * Description: Omise Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Omise Payment Gateway's payment methods to WooCommerce.
    7  * Version:     6.2.2
     7 * Version:     6.3.0
    88 * Author:      Omise and contributors
    99 * Author URI:  https://github.com/omise/omise-woocommerce/graphs/contributors
     
    2424     * @var string
    2525     */
    26     public $version = '6.2.2';
     26    public $version = '6.3.0';
    2727
    2828    /**
  • omise/tags/6.3.0/phpunit.xml

    r3308831 r3361458  
    44    backupGlobals="true"
    55    backupStaticAttributes="false"
     6    bootstrap="tests/unit/bootstrap.php"
    67    colors="true"
    78    stopOnError="false"
  • omise/tags/6.3.0/readme.txt

    r3331857 r3361458  
    44Requires at least: 4.3.1
    55Tested up to: 6.8.1
    6 Stable tag: 6.2.2
     6Stable tag: 6.3.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 6.3.0 =
     38
     39- Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534))
     40- Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533))
    3641
    3742= 6.2.2 =
  • omise/tags/6.3.0/tests/unit/class-omise-unit-test.php

    r3312403 r3361458  
    11<?php
    2 
    3 define( 'ABSPATH', value: '' );
    4 define( 'OMISE_PUBLIC_KEY', 'pkey_test_12345');
    5 define( 'OMISE_SECRET_KEY', 'skey_test_12345');
    62
    73class Omise_Unit_Test {
     
    3127}
    3228
     29/**
     30 * Mock WordPress _e() function.
     31 *
     32 * @see wp-includes/l10n.php
     33 * @see https://developer.wordpress.org/reference/functions/_e
     34 */
     35function _e( $text, $context, $domain = 'default' ) {
     36    echo $text;
     37}
     38
    3339function load_fixture($name) {
    3440    return file_get_contents(__DIR__ . "/../fixtures/{$name}.json");
  • omise/tags/6.3.0/tests/unit/includes/gateway/bootstrap-test-setup.php

    r3331857 r3361458  
    11<?php
    2 
    3 use PHPUnit\Framework\TestCase;
    4 use Brain\Monkey;
    5 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
    6 
    7 /**
    8  * Mock abstract WooCommerce's gateway
    9  */
    10 abstract class WC_Payment_Gateway
     2abstract class Bootstrap_Test_Setup extends Omise_Test_Case
    113{
    12     public static $is_available = true;
    13 
    14     public function is_available()
    15     {
    16         return self::$is_available;
    17     }
    18 }
    19 
    20 /**
    21  * Temporary mock for WP_* class
    22  * In the future, we should move to use WP_UnitTestCase
    23  */
    24 class WP_Error
    25 {
    26     public function __construct(
    27         public $code = '',
    28         public $message = '',
    29         public $data = ''
    30     ) {
    31     }
    32 }
    33 class WP_REST_Server_Stub
    34 {
    35     const EDITABLE = 'POST';
    36     const READABLE = 'GET';
    37 }
    38 
    39 abstract class Bootstrap_Test_Setup extends TestCase
    40 {
    41     // Adds Mockery expectations to the PHPUnit assertions count.
    42     use MockeryPHPUnitIntegration;
    43 
    44     public $sourceType;
    45 
    46     protected function setUp(): void
    47     {
    48         parent::setUp();
    49         Monkey\setUp();
    50     }
    51 
    52     /**
    53      * close mockery after tests are done
    54      */
    55     protected function tearDown(): void
    56     {
    57         Monkey\tearDown();
    58         Mockery::close();
    59         parent::tearDown();
    60     }
    61 
    62     public function getOrderMock($expectedAmount, $expectedCurrency)
     4    public function getOrderMock($expectedAmount, $expectedCurrency, $properties = [])
    635    {
    646        // Create a mock of the $order object
     
    668
    679        // Define expectations for the mock
     10        $orderMock->allows([
     11            'get_id' => $properties['id'] ?? 123,
     12            'get_order_key' => $properties['key'] ?? 'order_kfeERDv',
     13        ]);
    6814        $orderMock->shouldReceive('get_currency')
    69             ->andReturn($expectedCurrency);
     15            ->andReturn(strtoupper($expectedCurrency));
    7016        $orderMock->shouldReceive('get_total')
    7117            ->andReturn($expectedAmount);  // in units
     
    9440    }
    9541
     42    public function getCartMock($cartProperties = []) {
     43        $cart = Mockery::mock('WC_Cart');
     44        $cart->subtotal = $cartProperties['subtotal'] ?? 0;
     45        $cart->total = $cartProperties['total'] ?? 0;
     46
     47        return $cart;
     48    }
     49
     50    public function getWcMock($cart = null) {
     51        $wc = Mockery::mock('WooCommerce');
     52        $wc->cart = $cart ? $cart : $this->getCartMock();
     53
     54        return $wc;
     55    }
     56
    9657    /**
     58     * FIXME: Only used in Omise_Payment_Konbini_Test.
     59     * We can refactor this into offline payment test class or the test itself.
    9760     * @runInSeparateProcess
    9861     */
     
    142105            'public_key' => $pkey,
    143106            'secret_key' => $skey,
     107            'is_dynamic_webhook_enabled' => false,
    144108        ]);
    145109        $omiseSettingMock->shouldReceive('get_settings')->andReturn([])->byDefault();
     
    185149        }
    186150    }
     151
     152    protected function mockRedirectUrl($redirectUrl = 'https://abc.com/order/complete') {
     153        $redirectUrlMock = Mockery::mock('alias:RedirectUrl');
     154        $redirectUrlMock->shouldReceive('create')->andReturn($redirectUrl);
     155        $redirectUrlMock->shouldReceive('getToken')->andReturn('token123');
     156
     157        return $redirectUrlMock;
     158    }
    187159}
    188160
  • omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-offsite-test.php

    r3308831 r3361458  
    55use Brain\Monkey;
    66
     7/**
     8 * @deprecated Please use Omise_Payment_Offsite_Test instead.
     9 */
    710abstract class Omise_Offsite_Test extends Bootstrap_Test_Setup
    811{
  • omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-atome-test.php

    r3312403 r3361458  
    11<?php
    22
    3 require_once __DIR__ . '/class-omise-offsite-test.php';
    4 
    53use Brain\Monkey;
    6 
    7 class Omise_Payment_Atome_Test extends Omise_Offsite_Test
    8 {
    9     protected function setUp(): void
    10     {
    11         $this->sourceType = 'atome';
    12         parent::setUp();
    13         require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-atome.php';
    14 
    15         Monkey\Functions\expect('wp_enqueue_script');
    16         Monkey\Functions\expect('wp_kses');
    17         Monkey\Functions\expect('plugins_url');
    18         Monkey\Functions\expect('add_action');
    19 
    20         // dummy version
    21         if (!defined('WC_VERSION')) {
    22             define('WC_VERSION', '1.0.0');
    23         }
    24     }
    25 
    26     public function testGetChargeRequest()
    27     {
    28         $expectedAmount = 999999;
    29         $expectedCurrency = 'thb';
    30         $orderId = 'order_123';
    31         $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency);
    32 
    33         $wcProduct = Mockery::mock('overload:WC_Product');
    34         $wcProduct->shouldReceive('get_sku')
    35             ->once()
    36             ->andReturn('sku_1234');
    37 
    38         $_POST['omise_atome_phone_default'] = true;
    39 
    40         $obj = new Omise_Payment_Atome();
    41         $result = $obj->get_charge_request($orderId, $orderMock);
    42 
    43         $this->assertEquals($this->sourceType, $result['source']['type']);
    44     }
    45 
    46     public function testCharge()
    47     {
    48         $_POST['omise_atome_phone_default'] = true;
    49         $obj = new Omise_Payment_Atome();
    50         $this->getChargeTest($obj);
    51     }
     4use voku\helper\HtmlDomParser;
     5
     6/**
     7 * @runTestsInSeparateProcesses
     8 */
     9class Omise_Payment_Atome_Test extends Omise_Payment_Offsite_Test {
     10
     11    private $omise_atome;
     12
     13    protected function setUp(): void {
     14        parent::setUp();
     15
     16        $this->omise_atome = $this->mock_payment_class( Omise_Payment_Atome::class );
     17    }
     18
     19    public function test_atome_get_charge_request() {
     20        $order_amount = 4566;
     21        $order_currency = 'THB';
     22        $order_id = 'order_123';
     23        $order_mock = $this->getOrderMock( $order_amount, $order_currency );
     24
     25        $wc_product = Mockery::mock( 'overload:WC_Product' );
     26        $wc_product->shouldReceive( 'get_sku' )
     27            ->once()
     28            ->andReturn( 'sku_1234' );
     29
     30        $_POST['omise_atome_phone_default'] = true;
     31
     32        $result = $this->omise_atome->get_charge_request( $order_id, $order_mock );
     33
     34        $this->assertEquals( 456600, $result['amount'] );
     35        $this->assertEquals( $order_currency, $result['currency'] );
     36        $this->assertEquals( $order_id, $result['metadata']['order_id'] );
     37        $this->assertEquals( $this->return_uri, $result['return_uri'] );
     38
     39        $expected_source = [
     40            'type' => 'atome',
     41            'phone_number' => $order_mock->get_billing_phone(),
     42            'items' => [
     43                [
     44                    'name' => 'T Shirt',
     45                    'amount' => 60000,
     46                    'quantity' => 1,
     47                    'sku' => 'sku_1234',
     48                ],
     49            ],
     50            'shipping' => [
     51                'country' => 'Thailand',
     52                'city' => 'Bangkok',
     53                'postal_code' => '10110',
     54                'state' => 'Bangkok',
     55                'street1' => 'Sukumvit Road',
     56            ],
     57        ];
     58        $this->assertEquals( $expected_source, $result['source'] );
     59    }
     60
     61    public function test_atome_get_charge_request_with_custom_phone_number() {
     62        $order_amount = 4566;
     63        $order_currency = 'THB';
     64        $order_id = 'order_123';
     65        $order_mock = $this->getOrderMock( $order_amount, $order_currency );
     66
     67        $wc_product = Mockery::mock( 'overload:WC_Product' );
     68        $wc_product->shouldReceive( 'get_sku' )
     69            ->once()
     70            ->andReturn( 'sku_1234' );
     71
     72        $_POST['omise_atome_phone_default'] = false;
     73        $_POST['omise_atome_phone_number'] = '+66123456789';
     74
     75        $result = $this->omise_atome->get_charge_request( $order_id, $order_mock );
     76
     77        $this->assertEquals( 456600, $result['amount'] );
     78        $this->assertEquals( $order_currency, $result['currency'] );
     79        $this->assertEquals( 'atome', $result['source']['type'] );
     80        $this->assertEquals( '+66123456789', $result['source']['phone_number'] );
     81    }
     82
     83    public function test_atome_charge() {
     84        $order = $this->getOrderMock( 999999, 'THB' );
     85        $_POST['omise_atome_phone_default'] = true;
     86
     87        $this->perform_charge_test( $this->omise_atome, $order );
     88    }
     89
     90    public function test_atome_payment_fields_renders_atome_form_on_checkout_page() {
     91        $cart = $this->getCartMock(
     92            [
     93                'subtotal' => 300,
     94                'total' => 380,
     95            ]
     96        );
     97        $wc = $this->getWcMock( $cart );
     98
     99        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     100        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     101        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     102
     103        ob_start();
     104        $this->omise_atome->payment_fields();
     105        $output = ob_get_clean();
     106
     107        $page = HtmlDomParser::str_get_html( $output );
     108        $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext );
     109    }
     110
     111    public function test_atome_payment_fields_renders_atome_form_on_pay_for_order_page() {
     112        $wc = $this->getWcMock();
     113        $order_mock = $this->getOrderMock( 380, 'THB' );
     114        $order_mock->shouldReceive( 'get_subtotal' )->andReturn( 300 );
     115
     116        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     117        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     118        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true );
     119        Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 );
     120        Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( $order_mock );
     121
     122        ob_start();
     123        $this->omise_atome->payment_fields();
     124        $output = ob_get_clean();
     125
     126        $page = HtmlDomParser::str_get_html( $output );
     127        $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext );
     128    }
     129
     130    public function test_atome_payment_fields_returns_error_if_subtotal_is_zero() {
     131        $cart = $this->getCartMock(
     132            [
     133                'subtotal' => 0,
     134                'total' => 100,
     135            ]
     136        );
     137        $wc = $this->getWcMock( $cart );
     138
     139        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     140        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     141        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     142
     143        ob_start();
     144        $this->omise_atome->payment_fields();
     145        $output = ob_get_clean();
     146
     147        $this->assertEquals( 'Complimentary products cannot be billed.', trim( $output ) );
     148    }
     149
     150    public function test_atome_payment_fields_returns_error_if_currency_not_support() {
     151        $cart = $this->getCartMock(
     152            [
     153                'subtotal' => 100,
     154                'total' => 100,
     155            ]
     156        );
     157        $wc = $this->getWcMock( $cart );
     158
     159        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     160        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'USD' );
     161        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     162
     163        ob_start();
     164        $this->omise_atome->payment_fields();
     165        $output = ob_get_clean();
     166
     167        $this->assertEquals( 'Currency not supported', trim( $output ) );
     168    }
     169
     170    public function test_atome_payment_fields_returns_error_if_amount_less_than_min_limit() {
     171        $cart = $this->getCartMock(
     172            [
     173                'subtotal' => 1.4,
     174                'total' => 1.4,
     175            ]
     176        );
     177        $wc = $this->getWcMock( $cart );
     178
     179        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     180        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' );
     181        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     182
     183        ob_start();
     184        $this->omise_atome->payment_fields();
     185        $output = ob_get_clean();
     186
     187        $this->assertEquals( 'Amount must be greater than 1.50 SGD', trim( $output ) );
     188    }
     189
     190    public function test_atome_payment_fields_returns_error_if_amount_greater_than_max_limit() {
     191        $cart = $this->getCartMock(
     192            [
     193                'subtotal' => 20001,
     194                'total' => 20001,
     195            ]
     196        );
     197        $wc = $this->getWcMock( $cart );
     198
     199        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     200        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' );
     201        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     202
     203        ob_start();
     204        $this->omise_atome->payment_fields();
     205        $output = ob_get_clean();
     206
     207        $this->assertEquals( 'Amount must be less than 20,000.00 SGD', trim( $output ) );
     208    }
     209
     210    public function test_atome_payment_fields_throws_exception_if_pay_for_order_not_found() {
     211        $wc = $this->getWcMock();
     212
     213        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     214        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     215        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true );
     216        Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 );
     217        Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( false );
     218
     219        $this->expectException( Exception::class );
     220        $this->expectExceptionMessage( 'Order not found.' );
     221
     222        $this->omise_atome->payment_fields();
     223    }
    52224}
  • omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php

    r3308831 r3361458  
    3333        $omiseCardImage->shouldReceive('get_discover_image')->once();
    3434        $omiseCardImage->shouldReceive('get_discover_default_display')->once();
    35 
    36         // dummy version
    37         if (!defined('WC_VERSION')) {
    38             define('WC_VERSION', '1.0.0');
    39         }
    4035
    4136        Monkey\Functions\expect('add_action')->andReturn(null);
  • omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php

    r3209723 r3361458  
    1717        Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb');
    1818
    19         // dummy version
    20         if (!defined('WC_VERSION')) {
    21             define('WC_VERSION', '1.0.0');
    22         }
    23        
    2419        $omisePaymentMock = Mockery::mock('overload:Omise_Payment');
    2520        $omisePaymentMock->shouldReceive('init_settings');
  • omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-installment-test.php

    r3312403 r3361458  
    66
    77/**
    8  * @runInSeparateProcess
     8 * @runTestsInSeparateProcesses
    99 * @preserveGlobalState disabled
    1010 */
    11 
    12 class Omise_Payment_Installment_Test extends Omise_Offsite_Test
     11class Omise_Payment_Installment_Test extends Omise_Payment_Offsite_Test
    1312{
    1413    protected $backend_installment_mock;
     14    private $installment;
    1515
    1616    protected function setUp(): void
    1717    {
    18         $this->sourceType = 'installment_ktc';
    1918        parent::setUp();
    2019
    21         Monkey\Functions\expect('wp_kses');
    22         Omise_Unit_Test::include_class('backends/class-omise-backend.php');
    23         Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php');
    24 
     20        $this->installment = $this->mock_payment_class( Omise_Payment_Installment::class );
    2521        $this->backend_installment_mock = Mockery::mock('Omise_Backend_Installment');
    26         require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php';
    2722    }
    2823
    29     protected function tearDown(): void
     24    public function test_installment_get_total_amount_from_admin_order_page()
    3025    {
    31         parent::tearDown();
    32     }
    33 
    34     /**
    35      * @test
    36      */
    37     public function get_total_amount_from_admin_order_page()
    38     {
    39         Monkey\Functions\expect('add_action');
    40 
    4126        $order = Mockery::mock('WC_Order');
    4227        Monkey\Functions\expect('wc_get_order')->andReturn($order);
     
    5035        $GLOBALS['wp'] = $wp;
    5136
    52         $installment = new Omise_Payment_Installment();
    53         $total = $installment->get_total_amount();
     37        $total = $this->installment->get_total_amount();
    5438
    5539        $this->assertEquals($total, 999999);
    5640    }
    5741
    58     /**
    59      * @test
    60      */
    61     public function get_total_amount_from_cart()
     42    public function test_installment_get_total_amount_from_cart()
    6243    {
    63         Monkey\Functions\expect('add_action');
    64 
    6544        $clazz = new stdClass();
    6645        $clazz->cart = new stdClass();
     
    6948        Monkey\Functions\expect('WC')->andReturn($clazz);
    7049
    71         $installment = new Omise_Payment_Installment();
    72         $total = $installment->get_total_amount();
     50        $total = $this->installment->get_total_amount();
    7351
    7452        $this->assertEquals($total, 999999);
    7553    }
    7654
    77     public function test_charge()
     55    public function test_installment_charge()
    7856    {
    79         $this->backend_installment_mock->shouldReceive('get_provider');
     57        putenv('OMISE_CUSTOM_WLB_ORDER_DESC=test');
    8058
    81         Monkey\Functions\expect('add_action');
     59        $order = $this->getOrderMock(4353, 'THB', [ 'id' => 1293 ]);
     60        $_POST['omise_source'] = 'source_test_12345';
    8261
    83         $_POST['source'] = ['type' => $this->sourceType];
    84         $_POST[$this->sourceType . '_installment_terms'] = 3;
     62        $test_charge_fn = function ($actual) {
     63            return $actual == [
     64                'amount' => 435300,
     65                'currency' => 'THB',
     66                'description' => 'WooCommerce Order id 1293',
     67                'return_uri' => $this->return_uri,
     68                'source' => 'source_test_12345',
     69                'card' => '',
     70                'metadata' => [
     71                    'order_id' => 1293,
     72                ],
     73            ];
     74        };
    8575
    86         $obj = new Omise_Payment_Installment();
    87         $this->getChargeTest($obj);
     76        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
    8877    }
    8978
    90     public function test_get_view_data()
     79    public function test_installment_wlb_charge()
     80    {
     81        putenv('OMISE_CUSTOM_WLB_ORDER_DESC');
     82
     83        $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]);
     84        $_POST['omise_source'] = 'source_test_12345';
     85        $_POST['omise_token'] = 'tokn_test_67890';
     86
     87        $test_charge_fn = function ($actual) {
     88            return $actual == [
     89                'amount' => 25050,
     90                'currency' => 'THB',
     91                'description' => 'WooCommerce Order id 400',
     92                'return_uri' => $this->return_uri,
     93                'source' => 'source_test_12345',
     94                'card' => 'tokn_test_67890',
     95                'metadata' => [
     96                    'order_id' => 400,
     97                ],
     98            ];
     99        };
     100
     101        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
     102    }
     103
     104    public function test_installment_wlb_charge_with_custom_description()
     105    {
     106        putenv('OMISE_CUSTOM_WLB_ORDER_DESC={description} - test');
     107
     108        $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]);
     109        $_POST['omise_source'] = 'source_test_12345';
     110        $_POST['omise_token'] = 'tokn_test_67890';
     111
     112        $test_charge_fn = function ($actual) {
     113            return $actual['description'] == 'WooCommerce Order id 400 - test';
     114        };
     115
     116        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
     117    }
     118
     119    public function test_installment_wlb_charge_with_custom_description_fully_overridden()
     120    {
     121        putenv('OMISE_CUSTOM_WLB_ORDER_DESC=My order description');
     122
     123        $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]);
     124        $_POST['omise_source'] = 'source_test_12345';
     125        $_POST['omise_token'] = 'tokn_test_67890';
     126
     127        $test_charge_fn = function ($actual) {
     128            return $actual['description'] == 'My order description';
     129        };
     130
     131        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
     132    }
     133
     134    public function test_installment_get_view_data()
    91135    {
    92136        $capability = Mockery::mock('alias:Omise_Capability');
     
    109153        Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb');
    110154
    111         $clazz = new stdClass();
    112         $clazz->cart = new stdClass();
    113         $clazz->cart->total = 999999;
     155        $cart = $this->getCartMock(['total' => 999999]);
     156        $wc = $this->getWcMock($cart);
     157        Monkey\Functions\expect('WC')->andReturn($wc);
    114158
    115         Monkey\Functions\expect('WC')->andReturn($clazz);
    116         Monkey\Functions\expect('add_action');
    117 
    118         $obj = new Omise_Payment_Installment();
    119         $result = $obj->get_view_data();
     159        $result = $this->installment->get_view_data();
    120160
    121161        $this->assertArrayHasKey('installments_enabled', $result);
     
    124164    }
    125165
    126     public function testGetParamsForJS()
     166    public function test_installment_get_params_for_js()
    127167    {
    128         $clazz = new stdClass();
    129         $clazz->cart = new stdClass();
    130         $clazz->cart->total = 999999;
     168        $cart = $this->getCartMock(['total' => 999999]);
     169        $wc = $this->getWcMock($cart);
     170        Monkey\Functions\expect('WC')->andReturn($wc);
    131171
    132         Monkey\Functions\expect('WC')->andReturn($clazz);
    133         Monkey\Functions\expect('add_action');
    134         $mock = Mockery::mock('overload:Omise_Payment_Offsite');
    135         $instance = new Omise_Payment_Installment($mock);
    136         $result = $instance->getParamsForJS();
     172        $result = $this->installment->getParamsForJS();
    137173
    138         $this->assertIsArray($result);
    139         $this->assertArrayHasKey('key', $result);
    140         $this->assertArrayHasKey('amount', $result);
    141         $this->assertEquals('pkey_test_123', $result['key']);
    142         $this->assertEquals(99999900, $result['amount']);
     174        $this->assertEquals([
     175            'key' => 'pkey_test_123',
     176            'amount' => 99999900,
     177        ], $result);
    143178    }
    144179
    145     public function testConvertToCents()
     180    public function test_installment_convert_to_cents()
    146181    {
    147         Monkey\Functions\expect('add_action');
    148         $instance = new Omise_Payment_Installment();
     182        $instance = $this->installment;
     183
    149184        $this->assertEquals(100, $instance->convert_to_cents(1.00));
    150185        $this->assertEquals(150, $instance->convert_to_cents(1.50));
  • omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php

    r3182037 r3361458  
    88    public $mockWcDateTime;
    99    public $mockLocalizeScript;
    10     public $mockOmisePluginHelper;
    1110    public $mockOmisePaymentOffline;
    1211    public $mockOmiseCharge;
     
    2322        $this->mockLocalizeScript = Mockery::mock();
    2423        $this->mockWcDateTime = Mockery::mock('overload:WC_DateTime');
    25         $this->mockOmisePluginHelper = Mockery::mock('overload:OmisePluginHelperWcOrder')->shouldIgnoreMissing();
    2624        $this->mockOmisePaymentOffline = Mockery::mock('overload:Omise_Payment_Offline');
    2725        $this->mockOmiseCharge = Mockery::mock('overload:OmiseCharge');
     
    7977        }
    8078
     79        Monkey\Functions\when('wc_get_order')->justReturn($this->mockOrder);
     80        $this->mockOrder->shouldReceive('get_order_key')
     81            ->once()
     82            ->andReturn('wc_order_12345');
     83
    8184        $obj = new Omise_Payment_Promptpay();
    8285        $result = $obj->display_qrcode($this->mockOrder, 'view');
  • omise/trunk/CHANGELOG.md

    r3331857 r3361458  
    11# CHANGELOG
     2
     3## [v6.3.0 _(Sep 3, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.3.0)
     4
     5- Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534))
     6- Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533))
    27
    38## [v6.2.2 _(Jul 22, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.2.2)
  • omise/trunk/assets/javascripts/omise-payment-atome.js

    r2912289 r3361458  
    3939
    4040            const phoneNumber = $('#omise_atome_phone_number').val();
    41            
     41
    4242            if (!phoneNumber) {
    4343                return omiseHandleError('Phone number is required in Atome');
     
    5656
    5757    $(function () {
    58         $('form.checkout').on('checkout_place_order', function (e) {
     58        $('form.checkout, form#order_review').on('checkout_place_order', function () {
    5959            return omiseFormHandler();
    6060        });
  • omise/trunk/assets/javascripts/omise-payment-form-handler.js

    r3192967 r3361458  
    11(function ($) {
    22    const $form = $('form.checkout, form#order_review');
     3    const $formCheckout = $('form.checkout'); // Form in Normal Checkout Page
     4    const $formOrderReview = $('form#order_review'); // Form in Pay for Order Page
    35
    46    function hideError() {
     
    276278        });
    277279
    278         $('form.checkout').unbind('checkout_place_order_omise');
    279         $('form.checkout').on('checkout_place_order_omise', function () {
     280        $($formCheckout).unbind('checkout_place_order_omise');
     281        $($formCheckout).on('checkout_place_order_omise', function () {
    280282            return omiseFormHandler();
    281283        });
    282         $('form.checkout').unbind('checkout_place_order_omise_installment');
    283         $('form.checkout').on('checkout_place_order_omise_installment', function () {
     284        $($formCheckout).unbind('checkout_place_order_omise_installment');
     285        $($formCheckout).on('checkout_place_order_omise_installment', function () {
    284286            return omiseInstallmentFormHandler();
    285287        });
    286288
    287         /* Pay Page Form */
    288         $('form#order_review').on('submit', function () {
    289             return omiseFormHandler();
     289        /* Pay for Order Page Form */
     290        $($formOrderReview).on('submit', function () {
     291            var selectedPaymentMethod = $('input[name="payment_method"]:checked').val();
     292
     293            switch (selectedPaymentMethod) {
     294                case 'omise':
     295                    return omiseFormHandler();
     296                case 'omise_installment':
     297                    return omiseInstallmentFormHandler();
     298            }
    290299        });
    291300
    292301        /* Both Forms */
    293         $('form.checkout, form#order_review').on('change', '#omise_cc_form input', function() {
     302        $($form).on('change', '#omise_cc_form input', function() {
    294303            $('.omise_token').remove();
    295304            $('.omise_source').remove();
    296305        });
    297306
    298         $('form.checkout').on('change', 'input[name="payment_method"]', function() {
     307        $($form).on('change', 'input[name="payment_method"]', function() {
    299308            setupOmiseForm();
    300309        });
  • omise/trunk/includes/gateway/abstract-omise-payment-offsite.php

    r3308831 r3361458  
    1010{
    1111    use Charge_Request_Builder;
     12
     13    /**
     14     * @inheritdoc
     15     */
     16    public function payment_fields() {
     17        parent::payment_fields();
     18    }
    1219
    1320    /**
  • omise/trunk/includes/gateway/class-omise-payment-atome.php

    r3256918 r3361458  
    103103        ];
    104104
    105         $currency = strtolower(get_woocommerce_currency());
    106105        $cart = WC()->cart;
    107 
    108         if ($cart->subtotal === 0) {
    109             return [
    110                 'status' => false,
    111                 'message' => 'Complimentary products cannot be billed.'
    112             ];
    113         }
    114 
    115         if (!isset($limits[$currency])) {
    116             return [
    117                 'status' => false,
    118                 'message' => 'Currency not supported'
    119             ];
    120         }
    121 
    122         $limit = $limits[$currency];
    123 
    124         if ($cart->total < $limit['min']) {
     106        $cart_subtotal = $cart->subtotal;
     107        $cart_total = $cart->total;
     108        $cart_currency = strtolower( get_woocommerce_currency() );
     109
     110        // For Pay for Order Page
     111        if ( is_checkout_pay_page() ) {
     112            $order_id = get_query_var('order-pay');
     113            $order = wc_get_order( $order_id );
     114            if ( ! $order ) {
     115                throw new Exception( 'Order not found.' );
     116            }
     117
     118            $cart_subtotal = $order->get_subtotal();
     119            $cart_total = $order->get_total();
     120            $cart_currency = strtolower( $order->get_currency() );
     121        }
     122
     123        if ( $cart_subtotal === 0 ) {
     124            return [
     125                'status' => false,
     126                'message' => 'Complimentary products cannot be billed.',
     127            ];
     128        }
     129
     130        if ( ! isset( $limits[ $cart_currency ] ) ) {
     131            return [
     132                'status' => false,
     133                'message' => 'Currency not supported',
     134            ];
     135        }
     136
     137        $limit = $limits[ $cart_currency ];
     138
     139        if ( $cart_total < $limit['min'] ) {
    125140            return [
    126141                'status' => false,
    127142                'message' => sprintf(
    128                     "Amount must be greater than %u %s",
    129                     number_format($limit['min'], 2),
    130                     strtoupper($currency)
    131                 )
    132             ];
    133         }
    134 
    135         if ($cart->total > $limit['max']) {
    136             return [
    137                 'status' => false,
    138                 'message' => __(
    139                     'Amount must be less than %1 %2',
    140                     number_format($limit['max'], 2),
    141                     strtoupper($currency)
    142                 )
    143             ];
    144         }
    145 
    146         return ['status' => true];
     143                    'Amount must be greater than %s %s',
     144                    number_format( $limit['min'], 2 ),
     145                    strtoupper($cart_currency),
     146                ),
     147            ];
     148        }
     149
     150        if ( $cart_total > $limit['max'] ) {
     151            return [
     152                'status' => false,
     153                'message' => sprintf(
     154                    'Amount must be less than %s %s',
     155                    number_format( $limit['max'], 2 ),
     156                    strtoupper( $cart_currency ),
     157                ),
     158            ];
     159        }
     160
     161        return [ 'status' => true ];
    147162    }
    148163
     
    164179            $this->id . "_callback"
    165180        );
    166        
     181
    167182        $default_phone_selected = isset($_POST['omise_atome_phone_default']) ?
    168183            $_POST['omise_atome_phone_default']
  • omise/trunk/includes/gateway/class-omise-payment-installment.php

    r3308831 r3361458  
    130130            $this->id . "_callback"
    131131        );
    132         $requestData['description'] = 'staging';
    133132        $requestData['source'] = isset($_POST['omise_source']) ? wc_clean($_POST['omise_source']) : '';
    134133        $requestData['card'] = isset($_POST['omise_token']) ? wc_clean($_POST['omise_token']) : '';
     134
     135        $custom_wlb_desc = getenv('OMISE_CUSTOM_WLB_ORDER_DESC');
     136        if (!empty($custom_wlb_desc) && !empty($requestData['card'])) {
     137            $custom_wlb_desc = sanitize_text_field($custom_wlb_desc);
     138            $requestData['description'] = str_replace('{description}', $requestData['description'], $custom_wlb_desc);
     139        }
     140
    135141        return OmiseCharge::create($requestData);
    136142    }
  • omise/trunk/includes/gateway/class-omise-payment.php

    r3308831 r3361458  
    114114        add_filter( 'woocommerce_email_recipient_new_order', 'OmisePluginHelperMailer::disable_merchant_order_on_hold', 10, 2 );
    115115        add_filter('is_protected_meta', [ $this, 'protectMetadata'], 10, 2);
     116    }
     117
     118    /**
     119     * Displayed payment fields.
     120     */
     121    public function payment_fields() {
     122        parent::payment_fields();
    116123    }
    117124
  • omise/trunk/omise-woocommerce.php

    r3331857 r3361458  
    55 * Plugin URI:  https://www.omise.co/woocommerce
    66 * Description: Omise Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Omise Payment Gateway's payment methods to WooCommerce.
    7  * Version:     6.2.2
     7 * Version:     6.3.0
    88 * Author:      Omise and contributors
    99 * Author URI:  https://github.com/omise/omise-woocommerce/graphs/contributors
     
    2424     * @var string
    2525     */
    26     public $version = '6.2.2';
     26    public $version = '6.3.0';
    2727
    2828    /**
  • omise/trunk/phpunit.xml

    r3308831 r3361458  
    44    backupGlobals="true"
    55    backupStaticAttributes="false"
     6    bootstrap="tests/unit/bootstrap.php"
    67    colors="true"
    78    stopOnError="false"
  • omise/trunk/readme.txt

    r3331857 r3361458  
    44Requires at least: 4.3.1
    55Tested up to: 6.8.1
    6 Stable tag: 6.2.2
     6Stable tag: 6.3.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 6.3.0 =
     38
     39- Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534))
     40- Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533))
    3641
    3742= 6.2.2 =
  • omise/trunk/tests/unit/class-omise-unit-test.php

    r3312403 r3361458  
    11<?php
    2 
    3 define( 'ABSPATH', value: '' );
    4 define( 'OMISE_PUBLIC_KEY', 'pkey_test_12345');
    5 define( 'OMISE_SECRET_KEY', 'skey_test_12345');
    62
    73class Omise_Unit_Test {
     
    3127}
    3228
     29/**
     30 * Mock WordPress _e() function.
     31 *
     32 * @see wp-includes/l10n.php
     33 * @see https://developer.wordpress.org/reference/functions/_e
     34 */
     35function _e( $text, $context, $domain = 'default' ) {
     36    echo $text;
     37}
     38
    3339function load_fixture($name) {
    3440    return file_get_contents(__DIR__ . "/../fixtures/{$name}.json");
  • omise/trunk/tests/unit/includes/gateway/bootstrap-test-setup.php

    r3331857 r3361458  
    11<?php
    2 
    3 use PHPUnit\Framework\TestCase;
    4 use Brain\Monkey;
    5 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
    6 
    7 /**
    8  * Mock abstract WooCommerce's gateway
    9  */
    10 abstract class WC_Payment_Gateway
     2abstract class Bootstrap_Test_Setup extends Omise_Test_Case
    113{
    12     public static $is_available = true;
    13 
    14     public function is_available()
    15     {
    16         return self::$is_available;
    17     }
    18 }
    19 
    20 /**
    21  * Temporary mock for WP_* class
    22  * In the future, we should move to use WP_UnitTestCase
    23  */
    24 class WP_Error
    25 {
    26     public function __construct(
    27         public $code = '',
    28         public $message = '',
    29         public $data = ''
    30     ) {
    31     }
    32 }
    33 class WP_REST_Server_Stub
    34 {
    35     const EDITABLE = 'POST';
    36     const READABLE = 'GET';
    37 }
    38 
    39 abstract class Bootstrap_Test_Setup extends TestCase
    40 {
    41     // Adds Mockery expectations to the PHPUnit assertions count.
    42     use MockeryPHPUnitIntegration;
    43 
    44     public $sourceType;
    45 
    46     protected function setUp(): void
    47     {
    48         parent::setUp();
    49         Monkey\setUp();
    50     }
    51 
    52     /**
    53      * close mockery after tests are done
    54      */
    55     protected function tearDown(): void
    56     {
    57         Monkey\tearDown();
    58         Mockery::close();
    59         parent::tearDown();
    60     }
    61 
    62     public function getOrderMock($expectedAmount, $expectedCurrency)
     4    public function getOrderMock($expectedAmount, $expectedCurrency, $properties = [])
    635    {
    646        // Create a mock of the $order object
     
    668
    679        // Define expectations for the mock
     10        $orderMock->allows([
     11            'get_id' => $properties['id'] ?? 123,
     12            'get_order_key' => $properties['key'] ?? 'order_kfeERDv',
     13        ]);
    6814        $orderMock->shouldReceive('get_currency')
    69             ->andReturn($expectedCurrency);
     15            ->andReturn(strtoupper($expectedCurrency));
    7016        $orderMock->shouldReceive('get_total')
    7117            ->andReturn($expectedAmount);  // in units
     
    9440    }
    9541
     42    public function getCartMock($cartProperties = []) {
     43        $cart = Mockery::mock('WC_Cart');
     44        $cart->subtotal = $cartProperties['subtotal'] ?? 0;
     45        $cart->total = $cartProperties['total'] ?? 0;
     46
     47        return $cart;
     48    }
     49
     50    public function getWcMock($cart = null) {
     51        $wc = Mockery::mock('WooCommerce');
     52        $wc->cart = $cart ? $cart : $this->getCartMock();
     53
     54        return $wc;
     55    }
     56
    9657    /**
     58     * FIXME: Only used in Omise_Payment_Konbini_Test.
     59     * We can refactor this into offline payment test class or the test itself.
    9760     * @runInSeparateProcess
    9861     */
     
    142105            'public_key' => $pkey,
    143106            'secret_key' => $skey,
     107            'is_dynamic_webhook_enabled' => false,
    144108        ]);
    145109        $omiseSettingMock->shouldReceive('get_settings')->andReturn([])->byDefault();
     
    185149        }
    186150    }
     151
     152    protected function mockRedirectUrl($redirectUrl = 'https://abc.com/order/complete') {
     153        $redirectUrlMock = Mockery::mock('alias:RedirectUrl');
     154        $redirectUrlMock->shouldReceive('create')->andReturn($redirectUrl);
     155        $redirectUrlMock->shouldReceive('getToken')->andReturn('token123');
     156
     157        return $redirectUrlMock;
     158    }
    187159}
    188160
  • omise/trunk/tests/unit/includes/gateway/class-omise-offsite-test.php

    r3308831 r3361458  
    55use Brain\Monkey;
    66
     7/**
     8 * @deprecated Please use Omise_Payment_Offsite_Test instead.
     9 */
    710abstract class Omise_Offsite_Test extends Bootstrap_Test_Setup
    811{
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-atome-test.php

    r3312403 r3361458  
    11<?php
    22
    3 require_once __DIR__ . '/class-omise-offsite-test.php';
    4 
    53use Brain\Monkey;
    6 
    7 class Omise_Payment_Atome_Test extends Omise_Offsite_Test
    8 {
    9     protected function setUp(): void
    10     {
    11         $this->sourceType = 'atome';
    12         parent::setUp();
    13         require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-atome.php';
    14 
    15         Monkey\Functions\expect('wp_enqueue_script');
    16         Monkey\Functions\expect('wp_kses');
    17         Monkey\Functions\expect('plugins_url');
    18         Monkey\Functions\expect('add_action');
    19 
    20         // dummy version
    21         if (!defined('WC_VERSION')) {
    22             define('WC_VERSION', '1.0.0');
    23         }
    24     }
    25 
    26     public function testGetChargeRequest()
    27     {
    28         $expectedAmount = 999999;
    29         $expectedCurrency = 'thb';
    30         $orderId = 'order_123';
    31         $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency);
    32 
    33         $wcProduct = Mockery::mock('overload:WC_Product');
    34         $wcProduct->shouldReceive('get_sku')
    35             ->once()
    36             ->andReturn('sku_1234');
    37 
    38         $_POST['omise_atome_phone_default'] = true;
    39 
    40         $obj = new Omise_Payment_Atome();
    41         $result = $obj->get_charge_request($orderId, $orderMock);
    42 
    43         $this->assertEquals($this->sourceType, $result['source']['type']);
    44     }
    45 
    46     public function testCharge()
    47     {
    48         $_POST['omise_atome_phone_default'] = true;
    49         $obj = new Omise_Payment_Atome();
    50         $this->getChargeTest($obj);
    51     }
     4use voku\helper\HtmlDomParser;
     5
     6/**
     7 * @runTestsInSeparateProcesses
     8 */
     9class Omise_Payment_Atome_Test extends Omise_Payment_Offsite_Test {
     10
     11    private $omise_atome;
     12
     13    protected function setUp(): void {
     14        parent::setUp();
     15
     16        $this->omise_atome = $this->mock_payment_class( Omise_Payment_Atome::class );
     17    }
     18
     19    public function test_atome_get_charge_request() {
     20        $order_amount = 4566;
     21        $order_currency = 'THB';
     22        $order_id = 'order_123';
     23        $order_mock = $this->getOrderMock( $order_amount, $order_currency );
     24
     25        $wc_product = Mockery::mock( 'overload:WC_Product' );
     26        $wc_product->shouldReceive( 'get_sku' )
     27            ->once()
     28            ->andReturn( 'sku_1234' );
     29
     30        $_POST['omise_atome_phone_default'] = true;
     31
     32        $result = $this->omise_atome->get_charge_request( $order_id, $order_mock );
     33
     34        $this->assertEquals( 456600, $result['amount'] );
     35        $this->assertEquals( $order_currency, $result['currency'] );
     36        $this->assertEquals( $order_id, $result['metadata']['order_id'] );
     37        $this->assertEquals( $this->return_uri, $result['return_uri'] );
     38
     39        $expected_source = [
     40            'type' => 'atome',
     41            'phone_number' => $order_mock->get_billing_phone(),
     42            'items' => [
     43                [
     44                    'name' => 'T Shirt',
     45                    'amount' => 60000,
     46                    'quantity' => 1,
     47                    'sku' => 'sku_1234',
     48                ],
     49            ],
     50            'shipping' => [
     51                'country' => 'Thailand',
     52                'city' => 'Bangkok',
     53                'postal_code' => '10110',
     54                'state' => 'Bangkok',
     55                'street1' => 'Sukumvit Road',
     56            ],
     57        ];
     58        $this->assertEquals( $expected_source, $result['source'] );
     59    }
     60
     61    public function test_atome_get_charge_request_with_custom_phone_number() {
     62        $order_amount = 4566;
     63        $order_currency = 'THB';
     64        $order_id = 'order_123';
     65        $order_mock = $this->getOrderMock( $order_amount, $order_currency );
     66
     67        $wc_product = Mockery::mock( 'overload:WC_Product' );
     68        $wc_product->shouldReceive( 'get_sku' )
     69            ->once()
     70            ->andReturn( 'sku_1234' );
     71
     72        $_POST['omise_atome_phone_default'] = false;
     73        $_POST['omise_atome_phone_number'] = '+66123456789';
     74
     75        $result = $this->omise_atome->get_charge_request( $order_id, $order_mock );
     76
     77        $this->assertEquals( 456600, $result['amount'] );
     78        $this->assertEquals( $order_currency, $result['currency'] );
     79        $this->assertEquals( 'atome', $result['source']['type'] );
     80        $this->assertEquals( '+66123456789', $result['source']['phone_number'] );
     81    }
     82
     83    public function test_atome_charge() {
     84        $order = $this->getOrderMock( 999999, 'THB' );
     85        $_POST['omise_atome_phone_default'] = true;
     86
     87        $this->perform_charge_test( $this->omise_atome, $order );
     88    }
     89
     90    public function test_atome_payment_fields_renders_atome_form_on_checkout_page() {
     91        $cart = $this->getCartMock(
     92            [
     93                'subtotal' => 300,
     94                'total' => 380,
     95            ]
     96        );
     97        $wc = $this->getWcMock( $cart );
     98
     99        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     100        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     101        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     102
     103        ob_start();
     104        $this->omise_atome->payment_fields();
     105        $output = ob_get_clean();
     106
     107        $page = HtmlDomParser::str_get_html( $output );
     108        $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext );
     109    }
     110
     111    public function test_atome_payment_fields_renders_atome_form_on_pay_for_order_page() {
     112        $wc = $this->getWcMock();
     113        $order_mock = $this->getOrderMock( 380, 'THB' );
     114        $order_mock->shouldReceive( 'get_subtotal' )->andReturn( 300 );
     115
     116        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     117        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     118        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true );
     119        Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 );
     120        Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( $order_mock );
     121
     122        ob_start();
     123        $this->omise_atome->payment_fields();
     124        $output = ob_get_clean();
     125
     126        $page = HtmlDomParser::str_get_html( $output );
     127        $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext );
     128    }
     129
     130    public function test_atome_payment_fields_returns_error_if_subtotal_is_zero() {
     131        $cart = $this->getCartMock(
     132            [
     133                'subtotal' => 0,
     134                'total' => 100,
     135            ]
     136        );
     137        $wc = $this->getWcMock( $cart );
     138
     139        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     140        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     141        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     142
     143        ob_start();
     144        $this->omise_atome->payment_fields();
     145        $output = ob_get_clean();
     146
     147        $this->assertEquals( 'Complimentary products cannot be billed.', trim( $output ) );
     148    }
     149
     150    public function test_atome_payment_fields_returns_error_if_currency_not_support() {
     151        $cart = $this->getCartMock(
     152            [
     153                'subtotal' => 100,
     154                'total' => 100,
     155            ]
     156        );
     157        $wc = $this->getWcMock( $cart );
     158
     159        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     160        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'USD' );
     161        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     162
     163        ob_start();
     164        $this->omise_atome->payment_fields();
     165        $output = ob_get_clean();
     166
     167        $this->assertEquals( 'Currency not supported', trim( $output ) );
     168    }
     169
     170    public function test_atome_payment_fields_returns_error_if_amount_less_than_min_limit() {
     171        $cart = $this->getCartMock(
     172            [
     173                'subtotal' => 1.4,
     174                'total' => 1.4,
     175            ]
     176        );
     177        $wc = $this->getWcMock( $cart );
     178
     179        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     180        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' );
     181        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     182
     183        ob_start();
     184        $this->omise_atome->payment_fields();
     185        $output = ob_get_clean();
     186
     187        $this->assertEquals( 'Amount must be greater than 1.50 SGD', trim( $output ) );
     188    }
     189
     190    public function test_atome_payment_fields_returns_error_if_amount_greater_than_max_limit() {
     191        $cart = $this->getCartMock(
     192            [
     193                'subtotal' => 20001,
     194                'total' => 20001,
     195            ]
     196        );
     197        $wc = $this->getWcMock( $cart );
     198
     199        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     200        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' );
     201        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false );
     202
     203        ob_start();
     204        $this->omise_atome->payment_fields();
     205        $output = ob_get_clean();
     206
     207        $this->assertEquals( 'Amount must be less than 20,000.00 SGD', trim( $output ) );
     208    }
     209
     210    public function test_atome_payment_fields_throws_exception_if_pay_for_order_not_found() {
     211        $wc = $this->getWcMock();
     212
     213        Monkey\Functions\expect( 'WC' )->andReturn( $wc );
     214        Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' );
     215        Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true );
     216        Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 );
     217        Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( false );
     218
     219        $this->expectException( Exception::class );
     220        $this->expectExceptionMessage( 'Order not found.' );
     221
     222        $this->omise_atome->payment_fields();
     223    }
    52224}
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php

    r3308831 r3361458  
    3333        $omiseCardImage->shouldReceive('get_discover_image')->once();
    3434        $omiseCardImage->shouldReceive('get_discover_default_display')->once();
    35 
    36         // dummy version
    37         if (!defined('WC_VERSION')) {
    38             define('WC_VERSION', '1.0.0');
    39         }
    4035
    4136        Monkey\Functions\expect('add_action')->andReturn(null);
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php

    r3209723 r3361458  
    1717        Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb');
    1818
    19         // dummy version
    20         if (!defined('WC_VERSION')) {
    21             define('WC_VERSION', '1.0.0');
    22         }
    23        
    2419        $omisePaymentMock = Mockery::mock('overload:Omise_Payment');
    2520        $omisePaymentMock->shouldReceive('init_settings');
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-installment-test.php

    r3312403 r3361458  
    66
    77/**
    8  * @runInSeparateProcess
     8 * @runTestsInSeparateProcesses
    99 * @preserveGlobalState disabled
    1010 */
    11 
    12 class Omise_Payment_Installment_Test extends Omise_Offsite_Test
     11class Omise_Payment_Installment_Test extends Omise_Payment_Offsite_Test
    1312{
    1413    protected $backend_installment_mock;
     14    private $installment;
    1515
    1616    protected function setUp(): void
    1717    {
    18         $this->sourceType = 'installment_ktc';
    1918        parent::setUp();
    2019
    21         Monkey\Functions\expect('wp_kses');
    22         Omise_Unit_Test::include_class('backends/class-omise-backend.php');
    23         Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php');
    24 
     20        $this->installment = $this->mock_payment_class( Omise_Payment_Installment::class );
    2521        $this->backend_installment_mock = Mockery::mock('Omise_Backend_Installment');
    26         require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php';
    2722    }
    2823
    29     protected function tearDown(): void
     24    public function test_installment_get_total_amount_from_admin_order_page()
    3025    {
    31         parent::tearDown();
    32     }
    33 
    34     /**
    35      * @test
    36      */
    37     public function get_total_amount_from_admin_order_page()
    38     {
    39         Monkey\Functions\expect('add_action');
    40 
    4126        $order = Mockery::mock('WC_Order');
    4227        Monkey\Functions\expect('wc_get_order')->andReturn($order);
     
    5035        $GLOBALS['wp'] = $wp;
    5136
    52         $installment = new Omise_Payment_Installment();
    53         $total = $installment->get_total_amount();
     37        $total = $this->installment->get_total_amount();
    5438
    5539        $this->assertEquals($total, 999999);
    5640    }
    5741
    58     /**
    59      * @test
    60      */
    61     public function get_total_amount_from_cart()
     42    public function test_installment_get_total_amount_from_cart()
    6243    {
    63         Monkey\Functions\expect('add_action');
    64 
    6544        $clazz = new stdClass();
    6645        $clazz->cart = new stdClass();
     
    6948        Monkey\Functions\expect('WC')->andReturn($clazz);
    7049
    71         $installment = new Omise_Payment_Installment();
    72         $total = $installment->get_total_amount();
     50        $total = $this->installment->get_total_amount();
    7351
    7452        $this->assertEquals($total, 999999);
    7553    }
    7654
    77     public function test_charge()
     55    public function test_installment_charge()
    7856    {
    79         $this->backend_installment_mock->shouldReceive('get_provider');
     57        putenv('OMISE_CUSTOM_WLB_ORDER_DESC=test');
    8058
    81         Monkey\Functions\expect('add_action');
     59        $order = $this->getOrderMock(4353, 'THB', [ 'id' => 1293 ]);
     60        $_POST['omise_source'] = 'source_test_12345';
    8261
    83         $_POST['source'] = ['type' => $this->sourceType];
    84         $_POST[$this->sourceType . '_installment_terms'] = 3;
     62        $test_charge_fn = function ($actual) {
     63            return $actual == [
     64                'amount' => 435300,
     65                'currency' => 'THB',
     66                'description' => 'WooCommerce Order id 1293',
     67                'return_uri' => $this->return_uri,
     68                'source' => 'source_test_12345',
     69                'card' => '',
     70                'metadata' => [
     71                    'order_id' => 1293,
     72                ],
     73            ];
     74        };
    8575
    86         $obj = new Omise_Payment_Installment();
    87         $this->getChargeTest($obj);
     76        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
    8877    }
    8978
    90     public function test_get_view_data()
     79    public function test_installment_wlb_charge()
     80    {
     81        putenv('OMISE_CUSTOM_WLB_ORDER_DESC');
     82
     83        $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]);
     84        $_POST['omise_source'] = 'source_test_12345';
     85        $_POST['omise_token'] = 'tokn_test_67890';
     86
     87        $test_charge_fn = function ($actual) {
     88            return $actual == [
     89                'amount' => 25050,
     90                'currency' => 'THB',
     91                'description' => 'WooCommerce Order id 400',
     92                'return_uri' => $this->return_uri,
     93                'source' => 'source_test_12345',
     94                'card' => 'tokn_test_67890',
     95                'metadata' => [
     96                    'order_id' => 400,
     97                ],
     98            ];
     99        };
     100
     101        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
     102    }
     103
     104    public function test_installment_wlb_charge_with_custom_description()
     105    {
     106        putenv('OMISE_CUSTOM_WLB_ORDER_DESC={description} - test');
     107
     108        $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]);
     109        $_POST['omise_source'] = 'source_test_12345';
     110        $_POST['omise_token'] = 'tokn_test_67890';
     111
     112        $test_charge_fn = function ($actual) {
     113            return $actual['description'] == 'WooCommerce Order id 400 - test';
     114        };
     115
     116        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
     117    }
     118
     119    public function test_installment_wlb_charge_with_custom_description_fully_overridden()
     120    {
     121        putenv('OMISE_CUSTOM_WLB_ORDER_DESC=My order description');
     122
     123        $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]);
     124        $_POST['omise_source'] = 'source_test_12345';
     125        $_POST['omise_token'] = 'tokn_test_67890';
     126
     127        $test_charge_fn = function ($actual) {
     128            return $actual['description'] == 'My order description';
     129        };
     130
     131        $this->perform_charge_test( $this->installment, $order, $test_charge_fn );
     132    }
     133
     134    public function test_installment_get_view_data()
    91135    {
    92136        $capability = Mockery::mock('alias:Omise_Capability');
     
    109153        Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb');
    110154
    111         $clazz = new stdClass();
    112         $clazz->cart = new stdClass();
    113         $clazz->cart->total = 999999;
     155        $cart = $this->getCartMock(['total' => 999999]);
     156        $wc = $this->getWcMock($cart);
     157        Monkey\Functions\expect('WC')->andReturn($wc);
    114158
    115         Monkey\Functions\expect('WC')->andReturn($clazz);
    116         Monkey\Functions\expect('add_action');
    117 
    118         $obj = new Omise_Payment_Installment();
    119         $result = $obj->get_view_data();
     159        $result = $this->installment->get_view_data();
    120160
    121161        $this->assertArrayHasKey('installments_enabled', $result);
     
    124164    }
    125165
    126     public function testGetParamsForJS()
     166    public function test_installment_get_params_for_js()
    127167    {
    128         $clazz = new stdClass();
    129         $clazz->cart = new stdClass();
    130         $clazz->cart->total = 999999;
     168        $cart = $this->getCartMock(['total' => 999999]);
     169        $wc = $this->getWcMock($cart);
     170        Monkey\Functions\expect('WC')->andReturn($wc);
    131171
    132         Monkey\Functions\expect('WC')->andReturn($clazz);
    133         Monkey\Functions\expect('add_action');
    134         $mock = Mockery::mock('overload:Omise_Payment_Offsite');
    135         $instance = new Omise_Payment_Installment($mock);
    136         $result = $instance->getParamsForJS();
     172        $result = $this->installment->getParamsForJS();
    137173
    138         $this->assertIsArray($result);
    139         $this->assertArrayHasKey('key', $result);
    140         $this->assertArrayHasKey('amount', $result);
    141         $this->assertEquals('pkey_test_123', $result['key']);
    142         $this->assertEquals(99999900, $result['amount']);
     174        $this->assertEquals([
     175            'key' => 'pkey_test_123',
     176            'amount' => 99999900,
     177        ], $result);
    143178    }
    144179
    145     public function testConvertToCents()
     180    public function test_installment_convert_to_cents()
    146181    {
    147         Monkey\Functions\expect('add_action');
    148         $instance = new Omise_Payment_Installment();
     182        $instance = $this->installment;
     183
    149184        $this->assertEquals(100, $instance->convert_to_cents(1.00));
    150185        $this->assertEquals(150, $instance->convert_to_cents(1.50));
  • omise/trunk/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php

    r3182037 r3361458  
    88    public $mockWcDateTime;
    99    public $mockLocalizeScript;
    10     public $mockOmisePluginHelper;
    1110    public $mockOmisePaymentOffline;
    1211    public $mockOmiseCharge;
     
    2322        $this->mockLocalizeScript = Mockery::mock();
    2423        $this->mockWcDateTime = Mockery::mock('overload:WC_DateTime');
    25         $this->mockOmisePluginHelper = Mockery::mock('overload:OmisePluginHelperWcOrder')->shouldIgnoreMissing();
    2624        $this->mockOmisePaymentOffline = Mockery::mock('overload:Omise_Payment_Offline');
    2725        $this->mockOmiseCharge = Mockery::mock('overload:OmiseCharge');
     
    7977        }
    8078
     79        Monkey\Functions\when('wc_get_order')->justReturn($this->mockOrder);
     80        $this->mockOrder->shouldReceive('get_order_key')
     81            ->once()
     82            ->andReturn('wc_order_12345');
     83
    8184        $obj = new Omise_Payment_Promptpay();
    8285        $result = $obj->display_qrcode($this->mockOrder, 'view');
Note: See TracChangeset for help on using the changeset viewer.