Plugin Directory

Changeset 2876857


Ignore:
Timestamp:
03/09/2023 02:03:23 AM (3 years ago)
Author:
omise
Message:

Update to version 4.29.0 from GitHub

Location:
omise
Files:
6 added
36 edited
1 copied

Legend:

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

    r2854110 r2876857  
    11# CHANGELOG
     2
     3### [v4.29.0 _(Mar 8, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.29.0)
     4- Added Krungthai NEXT mobile banking (PR [#347](https://github.com/omise/omise-woocommerce/pull/347))
    25
    36### [v4.28.1 _(Jan 25, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.28.1)
  • omise/tags/4.29.0/assets/css/omise-css.css

    r2852769 r2876857  
    437437}
    438438
     439/** KTB **/
     440.mobile-banking-logo.ktb {
     441    background: url('../images/ktb-m.png');
     442    background-size: cover;
     443}
    439444
    440445/**
  • omise/tags/4.29.0/includes/admin/class-omise-admin-page.php

    r2501457 r2876857  
    2626                $this->errors[] = $message;
    2727                break;
    28 
    29             case 'message':
     28            default:
    3029                $this->messages[] = $message;
    3130                break;
  • omise/tags/4.29.0/includes/admin/views/omise-page-settings.php

    r2852769 r2876857  
    196196                                                        </td>';
    197197                                                        break;
     198
     199                                                    default:
     200                                                        break;
    198201                                                }
    199202                                            endforeach;
  • omise/tags/4.29.0/includes/backends/class-omise-backend-mobile-banking.php

    r2783685 r2876857  
    2727                'title'              => __( 'Bualuang mBanking', 'omise' ),
    2828                'logo'               => 'bbl',
     29            ),
     30            'mobile_banking_ktb' => array(
     31                'title'              => __( 'Krungthai NEXT', 'omise' ),
     32                'logo'               => 'ktb',
    2933            )
    3034        );
  • omise/tags/4.29.0/includes/class-omise-callback.php

    r2832733 r2876857  
    2222    public function __construct( $order ) {
    2323        $this->order = $order;
    24         if ( ! $this->order || ! $this->order instanceof WC_Abstract_Order ) $this->invalid_result();
     24        if ( ! $this->order || ! $this->order instanceof WC_Abstract_Order ) {
     25            $this->invalid_result();
     26        }
    2527    }
    2628
  • omise/tags/4.29.0/includes/class-omise-money.php

    r2501457 r2876857  
    5050
    5151    /**
     52     * convert omise amount to human readable amount.
     53     */
     54    public static function convert_currency_unit( $amount, $currency ) {
     55        $amount   = self::purify_amount( $amount );
     56        $currency = strtoupper( $currency );
     57
     58        if ( ! isset( self::$subunit_multiplier[ $currency ] ) ) {
     59            throw new Exception( __( 'We do not support the currency you are using.', 'omise' ) );
     60        }
     61
     62        return $amount / self::$subunit_multiplier[ $currency ];
     63    }
     64
     65    /**
    5266     * @param  int|float $amount
    5367     *
  • omise/tags/4.29.0/includes/class-omise-rest-webhooks-controller.php

    r2720994 r2876857  
    3030
    3131    /**
     32     * @var string
     33     */
     34    const RETURN_TRUE = '__return_true';
     35
     36    /**
    3237     * Register the routes for webhooks.
    3338     */
     
    3944                'methods' => WP_REST_Server::EDITABLE,
    4045                'callback' => array( $this, 'callback' ),
    41                 'permission_callback' => '__return_true'
     46                'permission_callback' => self::RETURN_TRUE
    4247            )
    4348        );
     
    4954                'methods' => WP_REST_Server::READABLE,
    5055                'callback' => array( $this, 'callback_paynow_payment_status' ),
    51                 'permission_callback' => '__return_true'
     56                'permission_callback' => self::RETURN_TRUE
    5257            )
    5358        );
     
    5964                'methods' => WP_REST_Server::READABLE,
    6065                'callback' => array( $this, 'callback_ocbc_pao_callback' ),
    61                 'permission_callback' => '__return_true'
     66                'permission_callback' => self::RETURN_TRUE
    6267            )
    6368        );
  • omise/tags/4.29.0/includes/events/class-omise-event-charge-capture.php

    r2832733 r2876857  
    7979                    $this->order->update_status( 'processing' );
    8080                }
    81             break;
     81                break;
     82
     83            default:
     84                throw new Exception('invalid charge status');
     85                break;
    8286        }
    8387
  • omise/tags/4.29.0/includes/events/class-omise-event-charge-complete.php

    r2832733 r2876857  
    11<?php
    22
    3 defined( 'ABSPATH' ) || exit;
     3defined('ABSPATH') || exit;
    44
    5 class Omise_Event_Charge_Complete extends Omise_Event {
     5class Omise_Event_Charge_Complete extends Omise_Event
     6{
    67    /**
    78     * @var string  of an event name.
     
    1213     * @inheritdoc
    1314     */
    14     public function validate() {
    15         if ( 'charge' !== $this->data['object'] || ! isset( $this->data['metadata']['order_id'] ) ) {
     15    public function validate()
     16    {
     17        if ('charge' !== $this->data['object'] || !isset($this->data['metadata']['order_id'])) {
    1618            return false;
    1719        }
    1820
    19         if ( ! $this->order = wc_get_order( $this->data['metadata']['order_id'] ) ) {
     21        if (!$this->order = wc_get_order($this->data['metadata']['order_id'])) {
    2022            return false;
    2123        }
    2224
    2325        // Making sure that an event's charge id is identical with an order transaction id.
    24         if ( $this->order->get_transaction_id() !== $this->data['id'] ) {
     26        if ($this->order->get_transaction_id() !== $this->data['id']) {
    2527            return false;
    2628        }
     
    2931    }
    3032
    31     public function is_resolvable() {
    32         if ( 'yes' === $this->order->get_meta( 'is_omise_payment_resolved' ) || $this->is_attempt_limit_exceeded() ) {
     33    public function is_resolvable()
     34    {
     35        if ('yes' === $this->order->get_meta('is_omise_payment_resolved') || $this->is_attempt_limit_exceeded()) {
    3336            return true;
    3437        }
     
    3639        $schedule_action = 'omise_async_webhook_event_handler';
    3740        $schedule_group  = 'omise_async_webhook';
    38         $data            = array( 'key' => self::EVENT_NAME, 'data' => serialize( $this->data ) );
    39         $this->schedule_single( $schedule_action, $data, $schedule_group );
     41        $data            = array('key' => self::EVENT_NAME, 'data' => serialize($this->data));
     42        $this->schedule_single($schedule_action, $data, $schedule_group);
    4043        return false;
    4144    }
     
    7376     * @return void
    7477     */
    75     public function resolve() {
    76         if ( ! $this->is_resolvable() ) return;
     78    public function resolve()
     79    {
     80        if (!$this->is_resolvable()) {
     81            return;
     82        }
    7783
    78         $this->order->add_order_note( __( 'Opn Payments: Received charge.complete webhook event.', 'omise' ) );
     84        $this->order->add_order_note(
     85            $this->allow_br('Opn Payments: Received charge.complete webhook event.'));
    7986
    80         switch ( $this->data['status'] ) {
     87        switch ($this->data['status']) {
    8188            case 'failed':
    82                 if ( $this->order->has_status( 'failed' ) ) {
    83                     return;
    84                 }
    85 
    86                 $message         = __( 'Opn Payments: Payment failed.<br/>%s', 'omise' );
    87                 $failure_message = Omise()->translate( $this->data['failure_message'] ) . ' (code: ' . $this->data['failure_code'] . ')';
    88                 $this->order->add_order_note(
    89                     sprintf(
    90                         wp_kses( $message, array( 'br' => array() ) ),
    91                         $failure_message
    92                     )
    93                 );
    94                 $this->order->update_status( 'failed' );
     89                $this->handle_failed_charge();
    9590                break;
    96 
    9791            case 'successful':
    98                 if ( $this->order->has_status( 'processing' ) ) {
    99                     return;
    100                 }
    101 
    102                 $message = __( 'Opn Payments: Payment successful.<br/>An amount %1$s %2$s has been paid', 'omise' );
    103 
    104                 $this->order->add_order_note(
    105                     sprintf(
    106                         wp_kses( $message, array( 'br' => array() ) ),
    107                         $this->order->get_total(),
    108                         $this->order->get_currency()
    109                     )
    110                 );
    111                 $this->order->payment_complete();
     92                $this->handle_successful_charge();
    11293                break;
    113            
    11494            case 'pending':
    115                 if ( $this->order->has_status( 'processing' ) ) {
    116                     return;
    117                 }
    118 
    119                 // Credit Card 3-D Secure with 'authorize only' payment action case.
    120                 if ( $this->data['authorized'] ) {
    121                     $this->order->update_meta_data( 'is_awaiting_capture', 'yes' );
    122                     $this->order->update_status( 'processing' );
    123                     $this->order->save();
    124                 }
     95                $this->handle_pending_charge();
     96                break;
     97            default:
    12598                break;
    12699        }
     
    128101        return;
    129102    }
     103
     104    /**
     105     * handler failed charge
     106     */
     107    private function handle_failed_charge()
     108    {
     109        if ($this->order->has_status('failed')) {
     110            return;
     111        }
     112
     113        $failure_message = sprintf(
     114            '%s  (code: %s)',
     115            Omise()->translate($this->data['failure_message']),
     116            $this->data['failure_code']
     117        );
     118
     119        $this->order->add_order_note(
     120            sprintf(
     121                $this->allow_br('Opn Payments: Payment failed.<br/>%s'),
     122                $failure_message
     123            )
     124        );
     125
     126        $this->order->update_status(Omise_Payment::STATUS_FAILED);
     127    }
     128
     129    /**
     130     * handler successful charge
     131     */
     132    private function handle_successful_charge()
     133    {
     134        if ($this->order->has_status('processing')) {
     135            return;
     136        }
     137        $this->order->add_order_note(
     138            sprintf(
     139                $this->allow_br('Opn Payments: Payment successful.<br/>An amount %1$s %2$s has been paid'),
     140                $this->order->get_total(),
     141                $this->order->get_currency()
     142            )
     143        );
     144        $this->order->payment_complete();
     145    }
     146
     147    /**
     148     * handler pending charge
     149     */
     150    private function handle_pending_charge()
     151    {
     152        if ($this->order->has_status('processing')) {
     153            return;
     154        }
     155        // Credit Card 3-D Secure with 'authorize only' payment action case.
     156        if ($this->data['authorized']) {
     157            $this->order->update_meta_data('is_awaiting_capture', 'yes');
     158            $this->order->update_status('processing');
     159            $this->order->save();
     160        }
     161    }
     162
     163    /**
     164     * allow br from the message.
     165     */
     166    private function  allow_br($message)
     167    {
     168        return wp_kses(__($message, 'omise'), ['br' => []]);
     169    }
    130170}
  • omise/tags/4.29.0/includes/gateway/abstract-omise-payment-base-card.php

    r2832733 r2876857  
    205205
    206206                // Then, check is authorized after if the first condition is false.
    207                 if ( ! $success )
     207                if ( ! $success ) {
    208208                    $success = Omise_Charge::is_authorized( $charge );
    209 
     209                }
     210                   
    210211                break;
    211212        }
  • omise/tags/4.29.0/includes/gateway/class-omise-payment-touch-n-go.php

    r2832733 r2876857  
    33
    44class Omise_Payment_TouchNGo extends Omise_Payment_Offsite {
     5
     6    private $touch_and_go_wallet_title = 'Touch \'n Go eWallet';
     7
    58    public function __construct() {
    69        parent::__construct();
     
    3134     */
    3235    public function init_form_fields() {
    33         $method_title = 'Touch \'n Go eWallet';
    34         $default_title = 'Touch \'n Go eWallet';
     36        $method_title = $this->touch_and_go_wallet_title;
     37        $default_title = $this->touch_and_go_wallet_title;
    3538
    3639        if ($this->provider === 'Alipay_plus') {
     
    6770        }
    6871       
    69         return 'Touch \'n Go eWallet';
     72        return $this->touch_and_go_wallet_title;
    7073    }
    7174
     
    9497        $icon = Omise_Image::get_image([
    9598            'file' => 'touch-n-go.png',
    96             'alternate_text' => 'Touch \'n Go eWallet',
     99            'alternate_text' => $this->touch_and_go_wallet_title,
    97100        ]);
    98101        return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
  • omise/tags/4.29.0/includes/gateway/class-omise-payment.php

    r2832733 r2876857  
    1111
    1212abstract class Omise_Payment extends WC_Payment_Gateway {
     13    use Sync_Order;
     14
     15    const WC_VERSION3 = '3.0.0';
     16
    1317    /** Omise charge id post meta key. */
    1418    const CHARGE_ID = 'omise_charge_id';
     
    420424
    421425    /**
    422      * Retrieve a charge by a given charge id (that attach to an order).
    423      * Find some diff, then merge it back to WooCommerce system.
    424      *
    425      * @param  WC_Order $order WooCommerce's order object
    426      *
    427      * @return void
    428      *
    429      * @see    WC_Meta_Box_Order_Actions::save( $post_id, $post )
    430      * @see    woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
    431      */
    432     public function sync_payment( $order ) {
    433         $this->load_order( $order );
    434 
    435         try {
    436             $charge = OmiseCharge::retrieve( $this->get_charge_id_from_order() );
    437 
    438             /**
    439              * Backward compatible with WooCommerce v2.x series
    440              * This case is likely not going to happen anymore as this was provided back then
    441              * when Omise-WooCommerce was introducing of adding charge.id into WC Order transaction id.
    442              **/
    443             if ( ! $this->order()->get_transaction_id() ) {
    444                 $this->set_order_transaction_id( $charge['id'] );
    445             }
    446 
    447             switch ( $charge['status'] ) {
    448                 case self::STATUS_SUCCESSFUL:
    449                     $this->delete_capture_metadata();
    450 
    451                     // Omise API 2017-11-02 uses `refunded`, Omise API 2019-05-29 uses `refunded_amount`.
    452                     $refunded_amount = isset( $charge['refunded_amount'] ) ? $charge['refunded_amount'] : $charge['refunded'];
    453                     if ( $charge['funding_amount'] == $refunded_amount ) {
    454                         if ( ! $this->order()->has_status( self::STATUS_REFUNDED ) ) {
    455                             $this->order()->update_status( self::STATUS_REFUNDED );
    456                         }
    457 
    458                         $message = wp_kses( __(
    459                             'Opn Payments: Payment refunded.<br/>An amount %1$s %2$s has been refunded (manual sync).', 'omise' ),
    460                             array( 'br' => array() )
    461                         );
    462                         $this->order()->add_order_note( sprintf( $message, $this->order()->get_total(), $this->order()->get_currency() ) );
    463                     } else {
    464                         $message = wp_kses( __(
    465                             'Opn Payments: Payment successful.<br/>An amount %1$s %2$s has been paid (manual sync).', 'omise' ),
    466                             array( 'br' => array() )
    467                         );
    468                         $this->order()->add_order_note( sprintf( $message, $this->order()->get_total(), $this->order()->get_currency() ) );
    469 
    470                         if ( ! $this->order()->is_paid() ) {
    471                             $this->order()->payment_complete();
    472                         }
    473                     }
    474                     break;
    475 
    476                 case self::STATUS_FAILED:
    477                     $this->delete_capture_metadata();
    478 
    479                     $message = wp_kses(
    480                         __( 'Opn Payments: Payment failed.<br/>%s (code: %s) (manual sync).', 'omise' ),
    481                         array( 'br' => array() )
    482                     );
    483                     $this->order()->add_order_note( sprintf( $message, Omise()->translate( $charge['failure_message'] ), $charge['failure_code'] ) );
    484 
    485                     if ( ! $this->order()->has_status( self::STATUS_FAILED ) ) {
    486                         $this->order()->update_status( self::STATUS_FAILED );
    487                     }
    488                     break;
    489 
    490                 case self::STATUS_PENDING:
    491                     $message = wp_kses( __(
    492                         'Opn Payments: Payment is still in progress.<br/>
    493                         You might wait for a moment before click sync the status again or contact Opn Payments support team at [email protected] if you have any questions (manual sync).',
    494                         'omise'
    495                     ), array( 'br' => array() ) );
    496 
    497                     $this->order()->add_order_note( $message );
    498                     break;
    499 
    500                 case self::STATUS_EXPIRED:
    501                     $this->delete_capture_metadata();
    502 
    503                     $message = wp_kses( __( 'Opn Payments: Payment expired. (manual sync).', 'omise' ), array( 'br' => array() ) );
    504                     $this->order()->add_order_note( $message );
    505 
    506                     if ( ! $this->order()->has_status( self::STATUS_CANCELLED ) ) {
    507                         $this->order()->update_status( self::STATUS_CANCELLED );
    508                     }
    509                     break;
    510 
    511                 case self::STATUS_REVERSED:
    512                     $this->delete_capture_metadata();
    513 
    514                     $message = wp_kses( __( 'Opn Payments: Payment reversed. (manual sync).', 'omise' ), array( 'br' => array() ) );
    515                     $this->order()->add_order_note( $message );
    516 
    517                     if ( ! $this->order()->has_status( self::STATUS_CANCELLED ) ) {
    518                         $this->order()->update_status( self::STATUS_CANCELLED );
    519                     }
    520                     break;
    521 
    522                 default:
    523                     throw new Exception(
    524                         __( 'Cannot read the payment status. Please try sync again or contact Opn Payments support team at [email protected] if you have any questions.', 'omise' )
    525                     );
    526                     break;
    527             }
    528         } catch ( Exception $e ) {
    529             $message = wp_kses(
    530                 __( 'Opn Payments: Sync failed (manual sync).<br/>%s.', 'omise' ),
    531                 array( 'br' => array() )
    532             );
    533 
    534             $order->add_order_note( sprintf( $message, $e->getMessage() ) );
    535         }
    536     }
    537 
    538     /**
    539426     * Set an order transaction id
    540427     *
     
    543430    protected function set_order_transaction_id( $transaction_id ) {
    544431        /** backward compatible with WooCommerce v2.x series **/
    545         if ( version_compare( WC()->version, '3.0.0', '>=' ) ) {
     432        if ( version_compare( WC()->version, self::WC_VERSION3, '>=' ) ) {
    546433            $this->order()->set_transaction_id( $transaction_id );
    547434            $this->order()->save();
     
    599486         */
    600487        // Backward compatible for Omise v3.0 - v3.3
    601         $order_id  = version_compare( WC()->version, '3.0.0', '>=' ) ? $this->order()->get_id() : $this->order()->id;
     488        $order_id  = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
    602489        $charge_id = get_post_meta( $order_id, self::CHARGE_ID, true );
    603490
     
    632519    protected function deprecated_get_charge_id_from_post() {
    633520        /** backward compatible with WooCommerce v2.x series **/
    634         $order_id  = version_compare( WC()->version, '3.0.0', '>=' ) ? $this->order()->get_id() : $this->order()->id;
     521        $order_id  = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
    635522
    636523        $posts = get_posts(
  • omise/tags/4.29.0/includes/libraries/omise-plugin/helpers/charge.php

    r2501457 r2876857  
    99        public static function isChargeObject($charge)
    1010        {
    11             if (! isset($charge['object']) || $charge['object'] !== 'charge')
     11            if (! isset($charge['object']) || $charge['object'] !== 'charge') {
    1212                return false;
    13 
     13            }
    1414            return true;
    1515        }
     
    3939        public static function isFailed($charge)
    4040        {
    41             if (! self::isChargeObject($charge))
     41            if (! self::isChargeObject($charge)) {
    4242                return true;
     43            }
     44               
     45            if ((! is_null($charge['failure_code']) && $charge['failure_code'] !== "")
     46                || (! is_null($charge['failure_message']) && $charge['failure_message'] !== "")) {
     47                return true;
     48            }
    4349
    44             if ((! is_null($charge['failure_code']) && $charge['failure_code'] !== "")
    45                 || (! is_null($charge['failure_message']) && $charge['failure_message'] !== ""))
     50            if (strtoupper($charge['status']) === 'FAILED') {
    4651                return true;
    47 
    48             if (strtoupper($charge['status']) === 'FAILED')
    49                 return true;
     52            }
    5053
    5154            return false;
  • omise/tags/4.29.0/includes/libraries/omise-plugin/helpers/mailer.php

    r2737840 r2876857  
    2323        public static function disable_merchant_order_on_hold( $recipient, $order ) {
    2424            $payment_gateway = wc_get_payment_gateway_by_order( $order );
    25             if (is_a($order, 'WC_Order') && is_a( $payment_gateway, 'Omise_Payment' ) &&
    26                 $order->get_status() == 'on-hold' ) $recipient = '';
     25            if (is_a($order, 'WC_Order') &&
     26                is_a( $payment_gateway, 'Omise_Payment' ) &&
     27                $order->get_status() == 'on-hold'
     28            ) {
     29                $recipient = '';
     30            }
    2731            return $recipient;
    2832        }
  • omise/tags/4.29.0/omise-woocommerce.php

    r2854110 r2876857  
    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:     4.28.1
     7 * Version:     4.29.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 = '4.28.1';
     25    public $version = '4.29.0';
    2626
    2727    /**
     
    149149        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/events/class-omise-event-charge-complete.php';
    150150        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/events/class-omise-event-charge-create.php';
     151        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/traits/sync-order-trait.php';
    151152        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/abstract-omise-payment-offline.php';
    152153        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/abstract-omise-payment-offsite.php';
  • omise/tags/4.29.0/readme.txt

    r2854110 r2876857  
    44Requires at least: 4.3.1
    55Tested up to: 6.0.2
    6 Stable tag: 4.28.1
     6Stable tag: 4.29.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 4.29.0 =
     38
     39- Added Krungthai NEXT mobile banking (PR [#347](https://github.com/omise/omise-woocommerce/pull/347))
    3640
    3741= 4.28.1 =
  • omise/tags/4.29.0/templates/payment/form-fpx.php

    r2783685 r2876857  
    99                        class="<?php echo $bank["code"];?>"
    1010                        value="<?php echo $bank["code"]; ?>"
    11                         <?= $bank['active'] ?: "disabled" ?>
     11                        <?php $bank['active'] ?: "disabled" ?>
    1212                    >
    1313                            <?php echo $bank["name"]; ?>
    14                             <?php if (!$bank['active']) echo " (offline)" ; ?>
     14                            <?php if (!$bank['active']) { echo " (offline)"; } ?>
    1515                    </option>
    1616            <?php endforeach; ?>
  • omise/trunk/CHANGELOG.md

    r2854110 r2876857  
    11# CHANGELOG
     2
     3### [v4.29.0 _(Mar 8, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.29.0)
     4- Added Krungthai NEXT mobile banking (PR [#347](https://github.com/omise/omise-woocommerce/pull/347))
    25
    36### [v4.28.1 _(Jan 25, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.28.1)
  • omise/trunk/assets/css/omise-css.css

    r2852769 r2876857  
    437437}
    438438
     439/** KTB **/
     440.mobile-banking-logo.ktb {
     441    background: url('../images/ktb-m.png');
     442    background-size: cover;
     443}
    439444
    440445/**
  • omise/trunk/includes/admin/class-omise-admin-page.php

    r2501457 r2876857  
    2626                $this->errors[] = $message;
    2727                break;
    28 
    29             case 'message':
     28            default:
    3029                $this->messages[] = $message;
    3130                break;
  • omise/trunk/includes/admin/views/omise-page-settings.php

    r2852769 r2876857  
    196196                                                        </td>';
    197197                                                        break;
     198
     199                                                    default:
     200                                                        break;
    198201                                                }
    199202                                            endforeach;
  • omise/trunk/includes/backends/class-omise-backend-mobile-banking.php

    r2783685 r2876857  
    2727                'title'              => __( 'Bualuang mBanking', 'omise' ),
    2828                'logo'               => 'bbl',
     29            ),
     30            'mobile_banking_ktb' => array(
     31                'title'              => __( 'Krungthai NEXT', 'omise' ),
     32                'logo'               => 'ktb',
    2933            )
    3034        );
  • omise/trunk/includes/class-omise-callback.php

    r2832733 r2876857  
    2222    public function __construct( $order ) {
    2323        $this->order = $order;
    24         if ( ! $this->order || ! $this->order instanceof WC_Abstract_Order ) $this->invalid_result();
     24        if ( ! $this->order || ! $this->order instanceof WC_Abstract_Order ) {
     25            $this->invalid_result();
     26        }
    2527    }
    2628
  • omise/trunk/includes/class-omise-money.php

    r2501457 r2876857  
    5050
    5151    /**
     52     * convert omise amount to human readable amount.
     53     */
     54    public static function convert_currency_unit( $amount, $currency ) {
     55        $amount   = self::purify_amount( $amount );
     56        $currency = strtoupper( $currency );
     57
     58        if ( ! isset( self::$subunit_multiplier[ $currency ] ) ) {
     59            throw new Exception( __( 'We do not support the currency you are using.', 'omise' ) );
     60        }
     61
     62        return $amount / self::$subunit_multiplier[ $currency ];
     63    }
     64
     65    /**
    5266     * @param  int|float $amount
    5367     *
  • omise/trunk/includes/class-omise-rest-webhooks-controller.php

    r2720994 r2876857  
    3030
    3131    /**
     32     * @var string
     33     */
     34    const RETURN_TRUE = '__return_true';
     35
     36    /**
    3237     * Register the routes for webhooks.
    3338     */
     
    3944                'methods' => WP_REST_Server::EDITABLE,
    4045                'callback' => array( $this, 'callback' ),
    41                 'permission_callback' => '__return_true'
     46                'permission_callback' => self::RETURN_TRUE
    4247            )
    4348        );
     
    4954                'methods' => WP_REST_Server::READABLE,
    5055                'callback' => array( $this, 'callback_paynow_payment_status' ),
    51                 'permission_callback' => '__return_true'
     56                'permission_callback' => self::RETURN_TRUE
    5257            )
    5358        );
     
    5964                'methods' => WP_REST_Server::READABLE,
    6065                'callback' => array( $this, 'callback_ocbc_pao_callback' ),
    61                 'permission_callback' => '__return_true'
     66                'permission_callback' => self::RETURN_TRUE
    6267            )
    6368        );
  • omise/trunk/includes/events/class-omise-event-charge-capture.php

    r2832733 r2876857  
    7979                    $this->order->update_status( 'processing' );
    8080                }
    81             break;
     81                break;
     82
     83            default:
     84                throw new Exception('invalid charge status');
     85                break;
    8286        }
    8387
  • omise/trunk/includes/events/class-omise-event-charge-complete.php

    r2832733 r2876857  
    11<?php
    22
    3 defined( 'ABSPATH' ) || exit;
     3defined('ABSPATH') || exit;
    44
    5 class Omise_Event_Charge_Complete extends Omise_Event {
     5class Omise_Event_Charge_Complete extends Omise_Event
     6{
    67    /**
    78     * @var string  of an event name.
     
    1213     * @inheritdoc
    1314     */
    14     public function validate() {
    15         if ( 'charge' !== $this->data['object'] || ! isset( $this->data['metadata']['order_id'] ) ) {
     15    public function validate()
     16    {
     17        if ('charge' !== $this->data['object'] || !isset($this->data['metadata']['order_id'])) {
    1618            return false;
    1719        }
    1820
    19         if ( ! $this->order = wc_get_order( $this->data['metadata']['order_id'] ) ) {
     21        if (!$this->order = wc_get_order($this->data['metadata']['order_id'])) {
    2022            return false;
    2123        }
    2224
    2325        // Making sure that an event's charge id is identical with an order transaction id.
    24         if ( $this->order->get_transaction_id() !== $this->data['id'] ) {
     26        if ($this->order->get_transaction_id() !== $this->data['id']) {
    2527            return false;
    2628        }
     
    2931    }
    3032
    31     public function is_resolvable() {
    32         if ( 'yes' === $this->order->get_meta( 'is_omise_payment_resolved' ) || $this->is_attempt_limit_exceeded() ) {
     33    public function is_resolvable()
     34    {
     35        if ('yes' === $this->order->get_meta('is_omise_payment_resolved') || $this->is_attempt_limit_exceeded()) {
    3336            return true;
    3437        }
     
    3639        $schedule_action = 'omise_async_webhook_event_handler';
    3740        $schedule_group  = 'omise_async_webhook';
    38         $data            = array( 'key' => self::EVENT_NAME, 'data' => serialize( $this->data ) );
    39         $this->schedule_single( $schedule_action, $data, $schedule_group );
     41        $data            = array('key' => self::EVENT_NAME, 'data' => serialize($this->data));
     42        $this->schedule_single($schedule_action, $data, $schedule_group);
    4043        return false;
    4144    }
     
    7376     * @return void
    7477     */
    75     public function resolve() {
    76         if ( ! $this->is_resolvable() ) return;
     78    public function resolve()
     79    {
     80        if (!$this->is_resolvable()) {
     81            return;
     82        }
    7783
    78         $this->order->add_order_note( __( 'Opn Payments: Received charge.complete webhook event.', 'omise' ) );
     84        $this->order->add_order_note(
     85            $this->allow_br('Opn Payments: Received charge.complete webhook event.'));
    7986
    80         switch ( $this->data['status'] ) {
     87        switch ($this->data['status']) {
    8188            case 'failed':
    82                 if ( $this->order->has_status( 'failed' ) ) {
    83                     return;
    84                 }
    85 
    86                 $message         = __( 'Opn Payments: Payment failed.<br/>%s', 'omise' );
    87                 $failure_message = Omise()->translate( $this->data['failure_message'] ) . ' (code: ' . $this->data['failure_code'] . ')';
    88                 $this->order->add_order_note(
    89                     sprintf(
    90                         wp_kses( $message, array( 'br' => array() ) ),
    91                         $failure_message
    92                     )
    93                 );
    94                 $this->order->update_status( 'failed' );
     89                $this->handle_failed_charge();
    9590                break;
    96 
    9791            case 'successful':
    98                 if ( $this->order->has_status( 'processing' ) ) {
    99                     return;
    100                 }
    101 
    102                 $message = __( 'Opn Payments: Payment successful.<br/>An amount %1$s %2$s has been paid', 'omise' );
    103 
    104                 $this->order->add_order_note(
    105                     sprintf(
    106                         wp_kses( $message, array( 'br' => array() ) ),
    107                         $this->order->get_total(),
    108                         $this->order->get_currency()
    109                     )
    110                 );
    111                 $this->order->payment_complete();
     92                $this->handle_successful_charge();
    11293                break;
    113            
    11494            case 'pending':
    115                 if ( $this->order->has_status( 'processing' ) ) {
    116                     return;
    117                 }
    118 
    119                 // Credit Card 3-D Secure with 'authorize only' payment action case.
    120                 if ( $this->data['authorized'] ) {
    121                     $this->order->update_meta_data( 'is_awaiting_capture', 'yes' );
    122                     $this->order->update_status( 'processing' );
    123                     $this->order->save();
    124                 }
     95                $this->handle_pending_charge();
     96                break;
     97            default:
    12598                break;
    12699        }
     
    128101        return;
    129102    }
     103
     104    /**
     105     * handler failed charge
     106     */
     107    private function handle_failed_charge()
     108    {
     109        if ($this->order->has_status('failed')) {
     110            return;
     111        }
     112
     113        $failure_message = sprintf(
     114            '%s  (code: %s)',
     115            Omise()->translate($this->data['failure_message']),
     116            $this->data['failure_code']
     117        );
     118
     119        $this->order->add_order_note(
     120            sprintf(
     121                $this->allow_br('Opn Payments: Payment failed.<br/>%s'),
     122                $failure_message
     123            )
     124        );
     125
     126        $this->order->update_status(Omise_Payment::STATUS_FAILED);
     127    }
     128
     129    /**
     130     * handler successful charge
     131     */
     132    private function handle_successful_charge()
     133    {
     134        if ($this->order->has_status('processing')) {
     135            return;
     136        }
     137        $this->order->add_order_note(
     138            sprintf(
     139                $this->allow_br('Opn Payments: Payment successful.<br/>An amount %1$s %2$s has been paid'),
     140                $this->order->get_total(),
     141                $this->order->get_currency()
     142            )
     143        );
     144        $this->order->payment_complete();
     145    }
     146
     147    /**
     148     * handler pending charge
     149     */
     150    private function handle_pending_charge()
     151    {
     152        if ($this->order->has_status('processing')) {
     153            return;
     154        }
     155        // Credit Card 3-D Secure with 'authorize only' payment action case.
     156        if ($this->data['authorized']) {
     157            $this->order->update_meta_data('is_awaiting_capture', 'yes');
     158            $this->order->update_status('processing');
     159            $this->order->save();
     160        }
     161    }
     162
     163    /**
     164     * allow br from the message.
     165     */
     166    private function  allow_br($message)
     167    {
     168        return wp_kses(__($message, 'omise'), ['br' => []]);
     169    }
    130170}
  • omise/trunk/includes/gateway/abstract-omise-payment-base-card.php

    r2832733 r2876857  
    205205
    206206                // Then, check is authorized after if the first condition is false.
    207                 if ( ! $success )
     207                if ( ! $success ) {
    208208                    $success = Omise_Charge::is_authorized( $charge );
    209 
     209                }
     210                   
    210211                break;
    211212        }
  • omise/trunk/includes/gateway/class-omise-payment-touch-n-go.php

    r2832733 r2876857  
    33
    44class Omise_Payment_TouchNGo extends Omise_Payment_Offsite {
     5
     6    private $touch_and_go_wallet_title = 'Touch \'n Go eWallet';
     7
    58    public function __construct() {
    69        parent::__construct();
     
    3134     */
    3235    public function init_form_fields() {
    33         $method_title = 'Touch \'n Go eWallet';
    34         $default_title = 'Touch \'n Go eWallet';
     36        $method_title = $this->touch_and_go_wallet_title;
     37        $default_title = $this->touch_and_go_wallet_title;
    3538
    3639        if ($this->provider === 'Alipay_plus') {
     
    6770        }
    6871       
    69         return 'Touch \'n Go eWallet';
     72        return $this->touch_and_go_wallet_title;
    7073    }
    7174
     
    9497        $icon = Omise_Image::get_image([
    9598            'file' => 'touch-n-go.png',
    96             'alternate_text' => 'Touch \'n Go eWallet',
     99            'alternate_text' => $this->touch_and_go_wallet_title,
    97100        ]);
    98101        return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
  • omise/trunk/includes/gateway/class-omise-payment.php

    r2832733 r2876857  
    1111
    1212abstract class Omise_Payment extends WC_Payment_Gateway {
     13    use Sync_Order;
     14
     15    const WC_VERSION3 = '3.0.0';
     16
    1317    /** Omise charge id post meta key. */
    1418    const CHARGE_ID = 'omise_charge_id';
     
    420424
    421425    /**
    422      * Retrieve a charge by a given charge id (that attach to an order).
    423      * Find some diff, then merge it back to WooCommerce system.
    424      *
    425      * @param  WC_Order $order WooCommerce's order object
    426      *
    427      * @return void
    428      *
    429      * @see    WC_Meta_Box_Order_Actions::save( $post_id, $post )
    430      * @see    woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
    431      */
    432     public function sync_payment( $order ) {
    433         $this->load_order( $order );
    434 
    435         try {
    436             $charge = OmiseCharge::retrieve( $this->get_charge_id_from_order() );
    437 
    438             /**
    439              * Backward compatible with WooCommerce v2.x series
    440              * This case is likely not going to happen anymore as this was provided back then
    441              * when Omise-WooCommerce was introducing of adding charge.id into WC Order transaction id.
    442              **/
    443             if ( ! $this->order()->get_transaction_id() ) {
    444                 $this->set_order_transaction_id( $charge['id'] );
    445             }
    446 
    447             switch ( $charge['status'] ) {
    448                 case self::STATUS_SUCCESSFUL:
    449                     $this->delete_capture_metadata();
    450 
    451                     // Omise API 2017-11-02 uses `refunded`, Omise API 2019-05-29 uses `refunded_amount`.
    452                     $refunded_amount = isset( $charge['refunded_amount'] ) ? $charge['refunded_amount'] : $charge['refunded'];
    453                     if ( $charge['funding_amount'] == $refunded_amount ) {
    454                         if ( ! $this->order()->has_status( self::STATUS_REFUNDED ) ) {
    455                             $this->order()->update_status( self::STATUS_REFUNDED );
    456                         }
    457 
    458                         $message = wp_kses( __(
    459                             'Opn Payments: Payment refunded.<br/>An amount %1$s %2$s has been refunded (manual sync).', 'omise' ),
    460                             array( 'br' => array() )
    461                         );
    462                         $this->order()->add_order_note( sprintf( $message, $this->order()->get_total(), $this->order()->get_currency() ) );
    463                     } else {
    464                         $message = wp_kses( __(
    465                             'Opn Payments: Payment successful.<br/>An amount %1$s %2$s has been paid (manual sync).', 'omise' ),
    466                             array( 'br' => array() )
    467                         );
    468                         $this->order()->add_order_note( sprintf( $message, $this->order()->get_total(), $this->order()->get_currency() ) );
    469 
    470                         if ( ! $this->order()->is_paid() ) {
    471                             $this->order()->payment_complete();
    472                         }
    473                     }
    474                     break;
    475 
    476                 case self::STATUS_FAILED:
    477                     $this->delete_capture_metadata();
    478 
    479                     $message = wp_kses(
    480                         __( 'Opn Payments: Payment failed.<br/>%s (code: %s) (manual sync).', 'omise' ),
    481                         array( 'br' => array() )
    482                     );
    483                     $this->order()->add_order_note( sprintf( $message, Omise()->translate( $charge['failure_message'] ), $charge['failure_code'] ) );
    484 
    485                     if ( ! $this->order()->has_status( self::STATUS_FAILED ) ) {
    486                         $this->order()->update_status( self::STATUS_FAILED );
    487                     }
    488                     break;
    489 
    490                 case self::STATUS_PENDING:
    491                     $message = wp_kses( __(
    492                         'Opn Payments: Payment is still in progress.<br/>
    493                         You might wait for a moment before click sync the status again or contact Opn Payments support team at [email protected] if you have any questions (manual sync).',
    494                         'omise'
    495                     ), array( 'br' => array() ) );
    496 
    497                     $this->order()->add_order_note( $message );
    498                     break;
    499 
    500                 case self::STATUS_EXPIRED:
    501                     $this->delete_capture_metadata();
    502 
    503                     $message = wp_kses( __( 'Opn Payments: Payment expired. (manual sync).', 'omise' ), array( 'br' => array() ) );
    504                     $this->order()->add_order_note( $message );
    505 
    506                     if ( ! $this->order()->has_status( self::STATUS_CANCELLED ) ) {
    507                         $this->order()->update_status( self::STATUS_CANCELLED );
    508                     }
    509                     break;
    510 
    511                 case self::STATUS_REVERSED:
    512                     $this->delete_capture_metadata();
    513 
    514                     $message = wp_kses( __( 'Opn Payments: Payment reversed. (manual sync).', 'omise' ), array( 'br' => array() ) );
    515                     $this->order()->add_order_note( $message );
    516 
    517                     if ( ! $this->order()->has_status( self::STATUS_CANCELLED ) ) {
    518                         $this->order()->update_status( self::STATUS_CANCELLED );
    519                     }
    520                     break;
    521 
    522                 default:
    523                     throw new Exception(
    524                         __( 'Cannot read the payment status. Please try sync again or contact Opn Payments support team at [email protected] if you have any questions.', 'omise' )
    525                     );
    526                     break;
    527             }
    528         } catch ( Exception $e ) {
    529             $message = wp_kses(
    530                 __( 'Opn Payments: Sync failed (manual sync).<br/>%s.', 'omise' ),
    531                 array( 'br' => array() )
    532             );
    533 
    534             $order->add_order_note( sprintf( $message, $e->getMessage() ) );
    535         }
    536     }
    537 
    538     /**
    539426     * Set an order transaction id
    540427     *
     
    543430    protected function set_order_transaction_id( $transaction_id ) {
    544431        /** backward compatible with WooCommerce v2.x series **/
    545         if ( version_compare( WC()->version, '3.0.0', '>=' ) ) {
     432        if ( version_compare( WC()->version, self::WC_VERSION3, '>=' ) ) {
    546433            $this->order()->set_transaction_id( $transaction_id );
    547434            $this->order()->save();
     
    599486         */
    600487        // Backward compatible for Omise v3.0 - v3.3
    601         $order_id  = version_compare( WC()->version, '3.0.0', '>=' ) ? $this->order()->get_id() : $this->order()->id;
     488        $order_id  = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
    602489        $charge_id = get_post_meta( $order_id, self::CHARGE_ID, true );
    603490
     
    632519    protected function deprecated_get_charge_id_from_post() {
    633520        /** backward compatible with WooCommerce v2.x series **/
    634         $order_id  = version_compare( WC()->version, '3.0.0', '>=' ) ? $this->order()->get_id() : $this->order()->id;
     521        $order_id  = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
    635522
    636523        $posts = get_posts(
  • omise/trunk/includes/libraries/omise-plugin/helpers/charge.php

    r2501457 r2876857  
    99        public static function isChargeObject($charge)
    1010        {
    11             if (! isset($charge['object']) || $charge['object'] !== 'charge')
     11            if (! isset($charge['object']) || $charge['object'] !== 'charge') {
    1212                return false;
    13 
     13            }
    1414            return true;
    1515        }
     
    3939        public static function isFailed($charge)
    4040        {
    41             if (! self::isChargeObject($charge))
     41            if (! self::isChargeObject($charge)) {
    4242                return true;
     43            }
     44               
     45            if ((! is_null($charge['failure_code']) && $charge['failure_code'] !== "")
     46                || (! is_null($charge['failure_message']) && $charge['failure_message'] !== "")) {
     47                return true;
     48            }
    4349
    44             if ((! is_null($charge['failure_code']) && $charge['failure_code'] !== "")
    45                 || (! is_null($charge['failure_message']) && $charge['failure_message'] !== ""))
     50            if (strtoupper($charge['status']) === 'FAILED') {
    4651                return true;
    47 
    48             if (strtoupper($charge['status']) === 'FAILED')
    49                 return true;
     52            }
    5053
    5154            return false;
  • omise/trunk/includes/libraries/omise-plugin/helpers/mailer.php

    r2737840 r2876857  
    2323        public static function disable_merchant_order_on_hold( $recipient, $order ) {
    2424            $payment_gateway = wc_get_payment_gateway_by_order( $order );
    25             if (is_a($order, 'WC_Order') && is_a( $payment_gateway, 'Omise_Payment' ) &&
    26                 $order->get_status() == 'on-hold' ) $recipient = '';
     25            if (is_a($order, 'WC_Order') &&
     26                is_a( $payment_gateway, 'Omise_Payment' ) &&
     27                $order->get_status() == 'on-hold'
     28            ) {
     29                $recipient = '';
     30            }
    2731            return $recipient;
    2832        }
  • omise/trunk/omise-woocommerce.php

    r2854110 r2876857  
    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:     4.28.1
     7 * Version:     4.29.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 = '4.28.1';
     25    public $version = '4.29.0';
    2626
    2727    /**
     
    149149        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/events/class-omise-event-charge-complete.php';
    150150        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/events/class-omise-event-charge-create.php';
     151        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/traits/sync-order-trait.php';
    151152        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/abstract-omise-payment-offline.php';
    152153        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/gateway/abstract-omise-payment-offsite.php';
  • omise/trunk/readme.txt

    r2854110 r2876857  
    44Requires at least: 4.3.1
    55Tested up to: 6.0.2
    6 Stable tag: 4.28.1
     6Stable tag: 4.29.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 4.29.0 =
     38
     39- Added Krungthai NEXT mobile banking (PR [#347](https://github.com/omise/omise-woocommerce/pull/347))
    3640
    3741= 4.28.1 =
  • omise/trunk/templates/payment/form-fpx.php

    r2783685 r2876857  
    99                        class="<?php echo $bank["code"];?>"
    1010                        value="<?php echo $bank["code"]; ?>"
    11                         <?= $bank['active'] ?: "disabled" ?>
     11                        <?php $bank['active'] ?: "disabled" ?>
    1212                    >
    1313                            <?php echo $bank["name"]; ?>
    14                             <?php if (!$bank['active']) echo " (offline)" ; ?>
     14                            <?php if (!$bank['active']) { echo " (offline)"; } ?>
    1515                    </option>
    1616            <?php endforeach; ?>
Note: See TracChangeset for help on using the changeset viewer.