Plugin Directory

Changeset 2852769


Ignore:
Timestamp:
01/23/2023 08:49:04 AM (3 years ago)
Author:
omise
Message:

Update to version 4.28.0 from GitHub

Location:
omise
Files:
2 added
34 edited
1 copied

Legend:

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

    r2832733 r2852769  
    11# CHANGELOG
     2
     3### [v4.28.0 _(Jan 24, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.28.0)
     4- Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339))
     5- Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336))
     6- Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333))
     7- Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338))
     8- Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337))
     9- Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342))
    210
    311### [v4.27.0 _(Dec 7, 2022)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.27.0)
  • omise/tags/4.28.0/assets/css/omise-css.css

    r2809311 r2852769  
    6565
    6666/**
    67  * Omise Bill Payment Tesco
     67 * Omise Bill Payment Lotus
    6868 * CSS for the 'Thank You' (order-received) page.
    6969 */
     
    404404
    405405/** MAYBANK **/
    406 .bank-logo.ezypay {
     406.bank-logo.mbb {
    407407    background: url('../images/maybank.svg') #ffcf00;
    408408    border-color: #ffcf00;
  • omise/tags/4.28.0/composer.json

    r2501457 r2852769  
    55    "license": "MIT",
    66    "require-dev": {
    7         "phpunit/phpunit": "^8.1"
     7        "phpunit/phpunit": "^5.7 || ^9.5"
    88    }
    99}
  • omise/tags/4.28.0/includes/admin/views/omise-page-settings.php

    r2832733 r2852769  
    3030                )
    3131            ),
    32             esc_url( 'https://dashboard.omise.co/v2/settings/keys' ),
     32            esc_url( 'https://dashboard.omise.co/v2/settings/keys' )
    3333        );
    3434        ?>
  • omise/tags/4.28.0/includes/backends/class-omise-backend-installment.php

    r2783685 r2852769  
    11<?php
     2
    23/**
    34 * Note: The calculations in this class depend on the countries that
     
    1112 * @method public calculate_monthly_payment_amount
    1213 */
    13 class Omise_Backend_Installment extends Omise_Backend {
     14class Omise_Backend_Installment extends Omise_Backend
     15{
    1416    /**
    1517     * @var array  of known installment providers.
     
    1719    protected static $providers = array();
    1820
    19     public function initiate() {
     21    public function initiate()
     22    {
    2023        self::$providers = array(
    2124            'installment_first_choice' => array(
    2225                'bank_code'          => 'first_choice',
    23                 'title'              => __( 'Krungsri First Choice', 'omise' ),
     26                'title'              => __('Krungsri First Choice', 'omise'),
    2427                'interest_rate'      => 1.3,
    2528                'min_allowed_amount' => 300.00,
     
    2831            'installment_bay' => array(
    2932                'bank_code'          => 'bay',
    30                 'title'              => __( 'Krungsri', 'omise' ),
     33                'title'              => __('Krungsri', 'omise'),
    3134                'interest_rate'      => 0.8,
    3235                'min_allowed_amount' => 500.00,
     
    3538            'installment_ktc' => array(
    3639                'bank_code'          => 'ktc',
    37                 'title'              => __( 'Krungthai Card (KTC)', 'omise' ),
     40                'title'              => __('Krungthai Card (KTC)', 'omise'),
    3841                'interest_rate'      => 0.8,
    3942                'min_allowed_amount' => 300.00,
     
    4245            'installment_bbl' => array(
    4346                'bank_code'          => 'bbl',
    44                 'title'              => __( 'Bangkok Bank', 'omise' ),
     47                'title'              => __('Bangkok Bank', 'omise'),
    4548                'interest_rate'      => 0.8,
    4649                'min_allowed_amount' => 500.00,
     
    4952            'installment_kbank' => array(
    5053                'bank_code'          => 'kbank',
    51                 'title'              => __( 'Kasikorn Bank', 'omise' ),
     54                'title'              => __('Kasikorn Bank', 'omise'),
    5255                'interest_rate'      => 0.65,
    5356                'min_allowed_amount' => 300.00,
     
    5659            'installment_scb' => array(
    5760                'bank_code'          => 'scb',
    58                 'title'              => __( 'Siam Commercial Bank', 'omise' ),
     61                'title'              => __('Siam Commercial Bank', 'omise'),
    5962                'interest_rate'      => 0.74,
    6063                'min_allowed_amount' => 500.00,
     
    6366            'installment_citi' => array(
    6467                'bank_code'          => 'citi',
    65                 'title'              => __( 'Citibank', 'omise' ),
     68                'title'              => __('Citibank', 'omise'),
    6669                'interest_rate'      => 0,
    6770                'min_allowed_amount' => 500.00,
     
    7073            'installment_ttb' => array(
    7174                'bank_code'          => 'ttb',
    72                 'title'              => __( 'TMBThanachart Bank', 'omise' ),
     75                'title'              => __('TMBThanachart Bank', 'omise'),
    7376                'interest_rate'      => 0,
    7477                'min_allowed_amount' => 500.00,
     
    7780            'installment_uob' => array(
    7881                'bank_code'          => 'uob',
    79                 'title'              => __( 'United Overseas Bank', 'omise' ),
    80                 'interest_rate'      => 0,
    81                 'min_allowed_amount' => 500.00,
    82             ),
    83 
    84             'installment_ezypay' => array(
    85                 'bank_code'          => 'ezypay',
    86                 'title'              => __( 'Maybank (EzyPay)', 'omise' ),
    87                 'interest_rate'      => 0,
    88                 'min_allowed_amount' => 500.00,
     82                'title'              => __('United Overseas Bank', 'omise'),
     83                'interest_rate'      => 0,
     84                'min_allowed_amount' => 500.00,
     85            ),
     86
     87            'installment_mbb' => array(
     88                'bank_code'          => 'mbb',
     89                'title'              => __('Maybank', 'omise'),
     90                'interest_rate'      => 0,
     91                'min_allowed_amount' => 500.00,
     92                'zero_interest_installments' => true,
     93                'terms_min_allowed_amount' => [
     94                    6 => 500.00,
     95                    12 => 1000.00,
     96                    18 => 1500.00,
     97                    24 => 2000.00
     98                ]
    8999            ),
    90100        );
     101    }
     102
     103    public function get_provider($id)
     104    {
     105        return self::$providers[$id];
    91106    }
    92107
     
    97112     * @return array  of an available installment providers
    98113     */
    99     public function get_available_providers( $currency, $purchase_amount ) {
     114    public function get_available_providers($currency, $purchase_amount)
     115    {
    100116        $capabilities = $this->capabilities();
    101117
    102         if ( !$capabilities ){
     118        if (!$capabilities) {
    103119            return null;
    104120        }
    105121
     122        $supportedProviderList = [];
     123
    106124        // Note: As installment payment at the moment only supports THB and MYR currency, the
    107125        //       $purchase_amount is multiplied with 100 to convert the amount into subunit (satang and sen).
    108         $providers = $capabilities->getInstallmentBackends( $currency, ( $purchase_amount * 100 ) );
    109 
    110         foreach ( $providers as &$provider ) {
    111             $provider_detail = self::$providers[ $provider->_id ];
    112 
    113             $provider->provider_code   = str_replace( 'installment_', '', $provider->_id );
    114             $provider->provider_name   = isset( $provider_detail ) ? $provider_detail['title'] : strtoupper( $provider->code );
    115             $provider->interest_rate   = $capabilities->is_zero_interest() ? 0 : ( $provider_detail['interest_rate'] );
    116             $provider->available_plans = $this->get_available_plans(
    117                 $purchase_amount,
    118                 $provider->allowed_installment_terms,
    119                 $provider->interest_rate,
    120                 $provider_detail['min_allowed_amount']
    121             );
     126        $providers = $capabilities->getInstallmentBackends($currency, ($purchase_amount * 100));
     127
     128        foreach ($providers as &$provider) {
     129            if (isset(self::$providers[$provider->_id])) {
     130                $provider_detail = self::$providers[$provider->_id];
     131
     132                $provider->provider_code   = str_replace('installment_', '', $provider->_id);
     133                $provider->provider_name   = isset($provider_detail)
     134                    ? $provider_detail['title']
     135                    : strtoupper($provider->code);
     136                $provider->interest_rate   = $capabilities->is_zero_interest()
     137                    ? 0 : ($provider_detail['interest_rate']);
     138                $provider->available_plans = $this->get_available_plans(
     139                    $purchase_amount,
     140                    $provider->allowed_installment_terms,
     141                    $provider->interest_rate,
     142                    $provider_detail
     143                );
     144                if (count($provider->available_plans) > 0) {
     145                    $supportedProviderList[] = $provider;
     146                }
     147            }
    122148        }
    123149
    124         usort( $providers, function( $a, $b ) {
    125             return strcmp( $a->provider_name, $b->provider_name );
     150        usort($supportedProviderList, function ($a, $b) {
     151            return strcmp($a->provider_name, $b->provider_name);
    126152        });
    127153
    128         return $providers;
     154        return $supportedProviderList;
    129155    }
    130156
     
    137163     * @return array  of an filtered available terms
    138164     */
    139     public function get_available_plans( $purchase_amount, $allowed_installment_terms, $interest_rate, $min_allowed_amount ) {
     165    public function get_available_plans($purchase_amount, $allowed_installment_terms, $interest_rate, $provider_detail)
     166    {
    140167        $plans = array();
    141168
    142         sort( $allowed_installment_terms );
    143 
    144         foreach ( $allowed_installment_terms as $term_length ) {
    145             $monthly_amount = $this->calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate );
    146 
    147             if ( $monthly_amount < $min_allowed_amount ) {
     169        $min_allowed_amount = $provider_detail['min_allowed_amount'];
     170        sort($allowed_installment_terms);
     171
     172        foreach ($allowed_installment_terms as $term_length) {
     173            $monthly_amount = $this->calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate);
     174
     175            if (isset($provider_detail['terms_min_allowed_amount'])) {
     176                $terms_min_allowed_amount = $provider_detail['terms_min_allowed_amount'];
     177                $min_allowed_amount = round($terms_min_allowed_amount[$term_length] / $term_length, 2);
     178            }
     179
     180            if ($monthly_amount < $min_allowed_amount) {
    148181                break;
    149182            }
     
    165198     * @return float  of a installment monthly payment (round up to 2 decimals).
    166199     */
    167     public function calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate ) {
     200    public function calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate)
     201    {
    168202        $interest = $purchase_amount * $interest_rate * $term_length / 100;
    169         return round( ( $purchase_amount + $interest ) / $term_length, 2 );
     203        return round(($purchase_amount + $interest) / $term_length, 2);
    170204    }
    171205}
  • omise/tags/4.28.0/includes/class-omise-capabilities.php

    r2795404 r2852769  
    157157     * @return string
    158158     */
    159     public function getTouchNGoBackends() {
    160         $params   = array();
    161         $params[] = $this->capabilities->backendFilter['type']('touch_n_go');
    162    
    163         return $this->capabilities->getBackends( $params );
     159    public function getTouchNGoBackends()
     160    {
     161        return $this->getBackendByType('touch_n_go');
     162    }
     163
     164    /**
     165     * Retrieves backend by type
     166     */
     167    public function getBackendByType($sourceType)
     168    {
     169        $params = [];
     170        $params[] = $this->capabilities->backendFilter['type']($sourceType);
     171        return $this->capabilities->getBackends($params);
    164172    }
    165173
    166174    /**
    167175     * Retrieves details of fpx bank list from capabilities.
    168      *
    169      * @return string
    170      */
    171     public function getFPXBanks() {
    172         $params   = array();
    173         $params[] = $this->capabilities->backendFilter['type']('fpx');
    174    
    175         return $this->capabilities->getBackends( $params );
     176     */
     177    public function getFPXBanks()
     178    {
     179        return $this->getBackendByType('fpx');
    176180    }
    177181
     
    189193     * @return bool  True if merchant absorbs the interest or else, false.
    190194     */
    191     public function is_zero_interest() {
     195    public function is_zero_interest()
     196    {
    192197        return $this->capabilities['zero_interest_installments'];
    193198    }
     
    196201     * @return array list of omise backends sourc_type.
    197202     */
    198     public function get_available_payment_methods() {
     203    public function get_available_payment_methods()
     204    {
    199205        $backends = $this->getBackends();
    200206        $backends = json_decode(json_encode($backends), true);
     
    202208        return array_merge(array_column($backends, '_id'),$token_methods);
    203209    }
     210
     211    /**
     212     * Retrieves details of Shopee Pay from capabilities.
     213     *
     214     * @param string $sourceType
     215     */
     216    public function getShopeeBackend($sourceType)
     217    {
     218        $shopeePaySourceTypes = [Omise_Payment_ShopeePay::ID, Omise_Payment_ShopeePay::JUMPAPP_ID];
     219
     220        if (!in_array($sourceType, $shopeePaySourceTypes)) {
     221            return null;
     222        }
     223
     224        return $this->getBackendByType($sourceType);
     225    }
    204226}
  • omise/tags/4.28.0/includes/gateway/class-omise-payment-alipay.php

    r2832733 r2852769  
    5858    public function charge($order_id, $order)
    5959    {
    60         $currency = $order->getCurrency();
     60        $currency = $order->get_currency();
    6161        return OmiseCharge::create([
    6262            'amount'      => Omise_Money::to_subunit($order->get_total(), $currency),
  • omise/tags/4.28.0/includes/gateway/class-omise-payment-billpayment-tesco.php

    r2832733 r2852769  
    1111        $this->id                 = 'omise_billpayment_tesco';
    1212        $this->has_fields         = false;
    13         $this->method_title       = __( 'Opn Payments Bill Payment: Tesco', 'omise' );
     13        $this->method_title       = __( 'Opn Payments Lotus\'s Bill Payment', 'omise' );
    1414        $this->method_description = wp_kses(
    15             __( 'Accept payments through <strong>Tesco Bill Payment</strong> via Opn Payments payment gateway.', 'omise' ),
     15            __( 'Accept payments through <strong>Lotus\'s Bill Payment</strong> via Opn Payments payment gateway.', 'omise' ),
    1616            array( 'strong' => array() )
    1717        );
     
    4141                'title'   => __( 'Enable/Disable', 'omise' ),
    4242                'type'    => 'checkbox',
    43                 'label'   => __( 'Enable Opn Payments Tesco Bill Payment', 'omise' ),
     43                'label'   => __( 'Enable Opn Payments Lotus\'s Bill Payment', 'omise' ),
    4444                'default' => 'no'
    4545            ),
     
    4949                'type'        => 'text',
    5050                'description' => __( 'This controls the title the user sees during checkout.', 'omise' ),
    51                 'default'     => __( 'Bill Payment: Tesco', 'omise' ),
     51                'default'     => __( 'Lotus\'s Bill Payment', 'omise' ),
    5252            ),
    5353
     
    125125                echo sprintf(
    126126                    wp_kses(
    127                         __( 'Please bring this barcode to pay at Tesco Lotus by:<br/><strong>%1$s %2$s</strong>.', 'omise' ),
     127                        __( 'Please bring this barcode to pay at Lotus\'s by:<br/><strong>%1$s %2$s</strong>.', 'omise' ),
    128128                        array( 'br' => array(), 'strong' => array() )
    129129                    ),
     
    154154                        __(
    155155                            '
    156                             Tesco Lotus may charge a small fee for the transaction.<br/>
     156                            Lotus\'s Bill Payment may charge a small fee for the transaction.<br/>
    157157                            If you fail to make payment by the stated time, your order will be automatically canceled.
    158158                            ', 'omise'
     
    189189
    190190    /**
    191      * Convert a given SVG Bill Payment Tesco's barcode to HTML format.
     191     * Convert a given SVG Bill Payment Lotus's barcode to HTML format.
    192192     *
    193193     * Note that the SVG barcode contains with the following structure:
     
    211211     * @param  string $barcode_svg
    212212     *
    213      * @return string  of a generated Bill Payment Tesco's barcode in HTML format.
     213     * @return string  of a generated Bill Payment Lotus's barcode in HTML format.
    214214     */
    215215    public function barcode_svg_to_html( $barcode_svg ) {
     
    231231            // Set HTML attributes based on <rect> node's attributes.
    232232            $div_rect = $xhtml->createElement( 'div' );
    233             $div_rect->setAttribute( 'style', "float: left; position: relative; height: 50px; border-left: $width solid #000000; width: 0; margin-left: $margin" );
     233            $div_rect->setAttribute('style', sprintf(
     234                'float: left; position: relative;
     235                height: 50px;
     236                border-left:  %spx solid #000000;
     237                width: 0; margin-left: %s',
     238                $width,
     239                $margin
     240            ));
    234241            $div_wrapper->appendChild( $div_rect );
    235242
  • omise/tags/4.28.0/includes/gateway/class-omise-payment-installment.php

    r2832733 r2852769  
    11<?php
    2 defined( 'ABSPATH' ) or die( 'No direct script access allowed.' );
     2defined('ABSPATH') or die('No direct script access allowed.');
    33
    44/**
    55 * @since 3.4
    66 */
    7 class Omise_Payment_Installment extends Omise_Payment_Offsite {
    8     public function __construct() {
     7class Omise_Payment_Installment extends Omise_Payment_Offsite
     8{
     9    public function __construct()
     10    {
    911        parent::__construct();
    1012
    1113        $this->id                 = 'omise_installment';
    1214        $this->has_fields         = true;
    13         $this->method_title       = __( 'Opn Payments Installments', 'omise' );
     15        $this->method_title       = __('Opn Payments Installments', 'omise');
    1416        $this->method_description = wp_kses(
    15             __( 'Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise' ),
    16             array( 'strong' => array() )
     17            __('Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise'),
     18            array('strong' => array())
    1719        );
    18         $this->supports           = array( 'products', 'refunds' );
     20        $this->supports           = array('products', 'refunds');
    1921
    2022        $this->init_form_fields();
    2123        $this->init_settings();
    2224
    23         $this->title                = $this->get_option( 'title' );
    24         $this->description          = $this->get_option( 'description' );
    25         $this->restricted_countries = array( 'TH', 'MY' );
     25        $this->title                = $this->get_option('title');
     26        $this->description          = $this->get_option('description');
     27        $this->restricted_countries = array('TH', 'MY');
    2628
    2729        $this->backend     = new Omise_Backend_Installment;
    2830
    29         add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
    30         add_action( 'woocommerce_order_action_' . $this->id . '_sync_payment', array( $this, 'sync_payment' ) );
    31         add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' );
     31        add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
     32        add_action('woocommerce_order_action_' . $this->id . '_sync_payment', array($this, 'sync_payment'));
     33        add_action('woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute');
    3234    }
    3335
     
    3638     * @see woocommerce/includes/abstracts/abstract-wc-settings-api.php
    3739     */
    38     public function init_form_fields() {
     40    public function init_form_fields()
     41    {
    3942        $this->form_fields = array(
    4043            'enabled' => array(
    41                 'title'   => __( 'Enable/Disable', 'omise' ),
     44                'title'   => __('Enable/Disable', 'omise'),
    4245                'type'    => 'checkbox',
    43                 'label'   => __( 'Enable Opn Payments Installment Payments', 'omise' ),
     46                'label'   => __('Enable Opn Payments Installment Payments', 'omise'),
    4447                'default' => 'no'
    4548            ),
    4649
    4750            'title' => array(
    48                 'title'       => __( 'Title', 'omise' ),
     51                'title'       => __('Title', 'omise'),
    4952                'type'        => 'text',
    50                 'description' => __( 'This controls the title the user sees during checkout.', 'omise' ),
    51                 'default'     => __( 'Installments', 'omise' ),
     53                'description' => __('This controls the title the user sees during checkout.', 'omise'),
     54                'default'     => __('Installments', 'omise'),
    5255            ),
    5356
    5457            'description' => array(
    55                 'title'       => __( 'Description', 'omise' ),
     58                'title'       => __('Description', 'omise'),
    5659                'type'        => 'textarea',
    57                 'description' => __( 'This controls the description the user sees during checkout.', 'omise' )
     60                'description' => __('This controls the description the user sees during checkout.', 'omise')
    5861            ),
    5962        );
     
    6366     * @inheritdoc
    6467     */
    65     public function payment_fields() {
     68    public function payment_fields()
     69    {
    6670        parent::payment_fields();
    6771
     
    7377            'templates/payment/form-installment.php',
    7478            array(
    75                 'installment_backends' => $this->backend->get_available_providers( $currency, $cart_total ),
     79                'installment_backends' => $this->backend->get_available_providers($currency, $cart_total),
    7680                'is_zero_interest'     => $capabilities ? $capabilities->is_zero_interest() : false
    7781            )
     
    8589    {
    8690        $source_type = isset($_POST['source']['type']) ? $_POST['source']['type'] : '';
    87         $installment_terms = isset( $_POST[ $source_type . '_installment_terms'] ) ? $_POST[ $source_type . '_installment_terms'] : '';
     91        $installment_terms = isset($_POST[$source_type . '_installment_terms']) ? $_POST[$source_type . '_installment_terms'] : '';
    8892        $currency = $order->get_currency();
     93        $provider = $this->backend->get_provider($source_type);
    8994
    90         return OmiseCharge::create([
     95        $payload = [
    9196            'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
    9297            'currency' => $currency,
     
    98103            'return_uri' => $this->getRedirectUrl('omise_installment_callback', $order_id, $order),
    99104            'metadata' => $this->getMetadata($order_id, $order)
    100         ]);
     105        ];
     106
     107        if (isset($provider['zero_interest_installments'])) {
     108            $payload['zero_interest_installments'] = $provider['zero_interest_installments'];
     109        }
     110
     111        return OmiseCharge::create($payload);
    101112    }
    102113
     
    108119     * @return array|false
    109120     */
    110     public function is_capability_support( $available_payment_methods ) {
     121    public function is_capability_support($available_payment_methods)
     122    {
    111123        return preg_grep('/^installment_/', $available_payment_methods);
    112124    }
  • omise/tags/4.28.0/includes/gateway/class-omise-payment-shopeepay.php

    r2832733 r2852769  
    22defined( 'ABSPATH' ) or die( 'No direct script access allowed.' );
    33
    4 class Omise_Payment_ShopeePay extends Omise_Payment_Offsite {
     4class Omise_Payment_ShopeePay extends Omise_Payment_Offsite
     5{
     6    /**
     7     * Backends identifier
     8     * @var string
     9     */
     10    const ID = 'shopeepay';
     11    const JUMPAPP_ID = 'shopeepay_jumpapp';
     12
    513    public function __construct() {
    614        parent::__construct();
     
    1119        $this->method_description = __( 'Accept payment through <strong>ShopeePay</strong> via Opn Payments payment gateway.', 'omise' );
    1220        $this->supports           = array( 'products', 'refunds' );
     21        $this->source_type        = $this->getSource();
    1322
    1423        $this->init_form_fields();
     
    1726        $this->title                = $this->get_option( 'title' );
    1827        $this->description          = $this->get_option( 'description' );
    19         $this->restricted_countries = array( 'MY' );
    20         $this->source_type          = 'shopeepay';
     28        $this->restricted_countries = array( 'MY', 'TH', 'SG' );
    2129
    2230        add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' );
     
    7078
    7179    /**
     80     * Return the right ShopeePay backend depending on the platform and availability of
     81     * the backend in the capability
     82     */
     83    private function getSource()
     84    {
     85        $capabilities = Omise_Capabilities::retrieve();
     86        $isShopeepayJumpAppEnabled = $capabilities->getShopeeBackend(self::JUMPAPP_ID);
     87        $isShopeepayEnabled = $capabilities->getShopeeBackend(self::ID);
     88
     89        // If user is in mobile and jump app is enabled then return shopeepay_jumpapp as source
     90        if (Omise_Util::isMobilePlatform() && !empty($isShopeepayJumpAppEnabled)) {
     91            return self::JUMPAPP_ID;
     92        }
     93
     94        // If above condition fails then it means either
     95        //
     96        // Case 1.
     97        // User is using mobile device but jump app is not enabled.
     98        // This means shopeepay direct is enabled otherwise this code would not execute.
     99        //
     100        // Case 2.
     101        // Jump app is enabled but user is not using mobile device
     102        //
     103        // In both cases we will want to show the shopeepay MPM backend first if MPM is enabled.
     104        // If MPM is not enabled then it means jump app is enabled because this code would never
     105        // execute if none of the shopee backends were disabled.
     106        return !empty($isShopeepayEnabled) ? self::ID : self::JUMPAPP_ID;
     107    }
     108
     109    /**
    72110     * Get icons
    73111     *
  • omise/tags/4.28.0/includes/libraries/omise-php/lib/omise/OmiseCapabilities.php

    r2783685 r2852769  
    127127        return function ($backend) use ($amount, $defMin, $defMax) {
    128128            // temporary hack for now to correct min value for installments to fixed minimum (different to normal charge minimum)
    129             if ($backend->type === 'installment') {
     129            if ($backend->type === 'installment' && get_woocommerce_currency() === 'THB') {
    130130                $min = self::INSTALLMENT_MINIMUM;
    131131            } else {
  • omise/tags/4.28.0/omise-util.php

    r2588190 r2852769  
    3636            return null;
    3737        }
     38
     39        /**
     40         * Check if current platform is mobile or not
     41         */
     42        public static function isMobilePlatform()
     43        {
     44            return null !== self::get_platform_type(wc_get_user_agent());
     45        }
    3846    }
    3947}
    40 ?>
  • omise/tags/4.28.0/omise-woocommerce.php

    r2832733 r2852769  
    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.27.0
     7 * Version:     4.28.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.27.0';
     25    public $version = '4.28.0';
    2626
    2727    /**
  • omise/tags/4.28.0/phpunit.xml

    r2501457 r2852769  
    1616        </testsuite>
    1717    </testsuites>
     18    <coverage>
     19        <include>
     20            <directory suffix=".php">./*</directory>
     21        </include>
     22        <exclude>
     23            <directory suffix=".php">tests</directory>
     24            <directory suffix=".php">vendor</directory>
     25        </exclude>
     26    </coverage>
    1827</phpunit>
  • omise/tags/4.28.0/readme.txt

    r2832733 r2852769  
    44Requires at least: 4.3.1
    55Tested up to: 6.0.2
    6 Stable tag: 4.27.0
     6Stable tag: 4.28.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 4.28.0 =
     38
     39- Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339))
     40- Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336))
     41- Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333))
     42- Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338))
     43- Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337))
     44- Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342))
    3645
    3746= 4.27.0 =
  • omise/tags/4.28.0/templates/payment/form-installment.php

    r2809311 r2852769  
    4747<?php else: ?>
    4848    <p>
    49         <?php echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' ); ?>
     49        <?php
     50            if(get_woocommerce_currency() === 'THB') {
     51                echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' );
     52            } else {
     53                echo __( 'Purchase Amount is lower than the monthly minimum payment amount.', 'omise' );
     54            }
     55        ?>
    5056    </p>
    5157<?php endif; ?>
  • omise/tags/4.28.0/tests/unit/includes/backends/class-omise-backend-installment-test.php

    r2621135 r2852769  
    11<?php
     2
    23use PHPUnit\Framework\TestCase;
     4
    35require_once __DIR__ . '/../../class-omise-unit-test.php';
    46
    5 class Omise_Backend_Installment_Test extends TestCase {
    6     public static function setUpBeforeClass(): void {
    7         Omise_Unit_Test::include_class( 'backends/class-omise-backend.php' );
    8         Omise_Unit_Test::include_class( 'backends/class-omise-backend-installment.php' );
    9     }
    10 
    11     /**
    12      * @test
    13      */
    14     public function get_only_valid_plans_from_given_bay_allowed_installment_terms() {
    15         $installment_backend = new Omise_Backend_Installment();
    16         $purchase_amount     = 2000.00;
    17         $allowed_terms       = array( 3, 4, 6, 9, 10 );
    18         $interest_rate       = 0.8;
    19         $min_allowed_amount  = 500.00;
    20 
    21         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    22 
    23         $this->assertEquals( 2, count( $result ) );
    24         $this->assertEquals( array(
    25             array( 'term_length' => 3, 'monthly_amount' => 682.67 ),
    26             array( 'term_length' => 4, 'monthly_amount' => 516.00 ),
    27         ), $result );
    28     }
    29    
    30     /**
    31      * @test
    32      */
    33     public function get_only_valid_plans_from_given_kbank_allowed_installment_terms() {
    34         $installment_backend = new Omise_Backend_Installment();
    35         $purchase_amount     = 2000.00;
    36         $allowed_terms       = array( 3, 4, 6, 10 );
     7class Omise_Backend_Installment_Test extends TestCase
     8{
     9    public static function setUpBeforeClass(): void
     10    {
     11        Omise_Unit_Test::include_class('backends/class-omise-backend.php');
     12        Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php');
     13    }
     14
     15    /**
     16     * @test
     17     */
     18    public function get_only_valid_plans_from_given_bay_allowed_installment_terms()
     19    {
     20        $installment_backend = new Omise_Backend_Installment();
     21        $purchase_amount     = 2000.00;
     22        $allowed_terms       = array(3, 4, 6, 9, 10);
     23        $interest_rate       = 0.8;
     24        $provider            = $installment_backend->get_provider('installment_bay');
     25
     26        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     27
     28        $this->assertEquals(2, count($result));
     29        $this->assertEquals(array(
     30            array('term_length' => 3, 'monthly_amount' => 682.67),
     31            array('term_length' => 4, 'monthly_amount' => 516.00),
     32        ), $result);
     33    }
     34
     35    /**
     36     * @test
     37     */
     38    public function get_only_valid_plans_from_given_kbank_allowed_installment_terms()
     39    {
     40        $installment_backend = new Omise_Backend_Installment();
     41        $purchase_amount     = 2000.00;
     42        $allowed_terms       = array(3, 4, 6, 10);
    3743        $interest_rate       = 0.65;
    38         $min_allowed_amount  = 300.00;
    39 
    40         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    41 
    42         $this->assertEquals( 3, count( $result ) );
    43         $this->assertEquals( array(
    44             array( 'term_length' => 3, 'monthly_amount' => 679.67 ),
    45             array( 'term_length' => 4, 'monthly_amount' => 513.00 ),
    46             array( 'term_length' => 6, 'monthly_amount' => 346.33 ),
    47         ), $result );
    48     }
    49 
    50     /**
    51      * @test
    52      */
    53     public function get_only_valid_plans_from_given_scb_allowed_installment_terms() {
    54         $installment_backend = new Omise_Backend_Installment();
    55         $purchase_amount     = 2000.00;
    56         $allowed_terms       = array( 3, 4, 6, 8, 10 );
     44        $provider            = $installment_backend->get_provider('installment_kbank');
     45
     46        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     47
     48        $this->assertEquals(3, count($result));
     49        $this->assertEquals(array(
     50            array('term_length' => 3, 'monthly_amount' => 679.67),
     51            array('term_length' => 4, 'monthly_amount' => 513.00),
     52            array('term_length' => 6, 'monthly_amount' => 346.33),
     53        ), $result);
     54    }
     55
     56    /**
     57     * @test
     58     */
     59    public function get_only_valid_plans_from_given_scb_allowed_installment_terms()
     60    {
     61        $installment_backend = new Omise_Backend_Installment();
     62        $purchase_amount     = 2000.00;
     63        $allowed_terms       = array(3, 4, 6, 8, 10);
    5764        $interest_rate       = 0.74;
    58         $min_allowed_amount  = 500.00;
    59 
    60         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    61 
    62         $this->assertEquals( 2, count( $result ) );
    63         $this->assertEquals( array(
    64             array( 'term_length' => 3, 'monthly_amount' => 681.47 ),
    65             array( 'term_length' => 4, 'monthly_amount' => 514.80 ),
    66         ), $result );
    67     }
    68 
    69     /**
    70      * @test
    71      */
    72     public function get_only_valid_plans_from_given_bbl_allowed_installment_terms() {
     65        $provider            = $installment_backend->get_provider('installment_scb');
     66
     67        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     68
     69        $this->assertEquals(2, count($result));
     70        $this->assertEquals(array(
     71            array('term_length' => 3, 'monthly_amount' => 681.47),
     72            array('term_length' => 4, 'monthly_amount' => 514.80),
     73        ), $result);
     74    }
     75
     76    /**
     77     * @test
     78     */
     79    public function get_only_valid_plans_from_given_bbl_allowed_installment_terms()
     80    {
    7381        $installment_backend = new Omise_Backend_Installment();
    7482        $purchase_amount     = 3000.00;
    75         $allowed_terms       = array( 3, 4, 6, 8, 10 );
    76         $interest_rate       = 0.8;
    77         $min_allowed_amount  = 500.00;
    78 
    79         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    80 
    81         $this->assertEquals( 3, count( $result ) );
    82         $this->assertEquals( array(
    83             array( 'term_length' => 3, 'monthly_amount' => 1024.00 ),
    84             array( 'term_length' => 4, 'monthly_amount' => 774.00 ),
    85             array( 'term_length' => 6, 'monthly_amount' => 524.00 ),
    86         ), $result );
    87     }
    88 
    89     /**
    90      * @test
    91      */
    92     public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms() {
     83        $allowed_terms       = array(3, 4, 6, 8, 10);
     84        $interest_rate       = 0.8;
     85        $provider            = $installment_backend->get_provider('installment_bbl');
     86
     87        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     88
     89        $this->assertEquals(3, count($result));
     90        $this->assertEquals(array(
     91            array('term_length' => 3, 'monthly_amount' => 1024.00),
     92            array('term_length' => 4, 'monthly_amount' => 774.00),
     93            array('term_length' => 6, 'monthly_amount' => 524.00),
     94        ), $result);
     95    }
     96
     97    /**
     98     * @test
     99     */
     100    public function get_only_valid_plans_from_given_mbb_allowed_installment_terms()
     101    {
     102        $installment_backend = new Omise_Backend_Installment();
     103        $purchase_amount     = 20000.00;
     104        $allowed_terms       = array(6, 12, 18, 24);
     105        $interest_rate       = 0.8;
     106        $provider            = $installment_backend->get_provider('installment_mbb');
     107
     108        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     109
     110        $this->assertEquals(4, count($result));
     111        $this->assertEquals(array(
     112            array('term_length' => 6, 'monthly_amount' => 3493.33),
     113            array('term_length' => 12, 'monthly_amount' => 1826.67),
     114            array('term_length' => 18, 'monthly_amount' => 1271.11),
     115            array('term_length' => 24, 'monthly_amount' => 993.33),
     116        ), $result);
     117    }
     118
     119    /**
     120     * @test
     121     */
     122    public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms()
     123    {
    93124        $installment_backend = new Omise_Backend_Installment();
    94125        $purchase_amount     = 3000.00;
    95         $allowed_terms       = array( 3, 10, 4, 8, 6 );
    96         $interest_rate       = 0.8;
    97         $min_allowed_amount  = 500.00;
    98 
    99         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    100 
    101         $this->assertEquals( 3, count( $result ) );
    102         $this->assertEquals( array(
    103             array( 'term_length' => 3, 'monthly_amount' => 1024.00 ),
    104             array( 'term_length' => 4, 'monthly_amount' => 774.00 ),
    105             array( 'term_length' => 6, 'monthly_amount' => 524.00 ),
    106         ), $result );
    107     }
    108 
    109     /**
    110      * @test
    111      */
    112     public function get_only_valid_plans_from_zero_interest_installments() {
    113         $installment_backend = new Omise_Backend_Installment();
    114         $purchase_amount     = 2000.00;
    115         $allowed_terms       = array( 3, 4, 5 );
     126        $allowed_terms       = array(3, 10, 4, 8, 6);
     127        $interest_rate       = 0.8;
     128        $provider            = $installment_backend->get_provider('installment_bbl');
     129
     130        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     131
     132        $this->assertEquals(3, count($result));
     133        $this->assertEquals(array(
     134            array('term_length' => 3, 'monthly_amount' => 1024.00),
     135            array('term_length' => 4, 'monthly_amount' => 774.00),
     136            array('term_length' => 6, 'monthly_amount' => 524.00),
     137        ), $result);
     138    }
     139
     140    /**
     141     * @test
     142     */
     143    public function get_only_valid_plans_from_zero_interest_installments()
     144    {
     145        $installment_backend = new Omise_Backend_Installment();
     146        $purchase_amount     = 2000.00;
     147        $allowed_terms       = array(3, 4, 5);
    116148        $interest_rate       = 0;
    117         $min_allowed_amount  = 500.00;
    118 
    119         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    120 
    121         $this->assertEquals( 2, count( $result ) );
    122         $this->assertEquals( array(
    123             array( 'term_length' => 3, 'monthly_amount' => 666.67 ),
    124             array( 'term_length' => 4, 'monthly_amount' => 500.00 ),
    125         ), $result );
    126     }
    127 
    128     /**
    129      * @test
    130      */
    131     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1() {
     149        $provider            = $installment_backend->get_provider('installment_bbl');
     150
     151        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     152
     153        $this->assertEquals(2, count($result));
     154        $this->assertEquals(array(
     155            array('term_length' => 3, 'monthly_amount' => 666.67),
     156            array('term_length' => 4, 'monthly_amount' => 500.00),
     157        ), $result);
     158    }
     159
     160    /**
     161     * @test
     162     */
     163    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1()
     164    {
    132165        $installment_backend = new Omise_Backend_Installment();
    133166        $purchase_amount     = 10000.00;
     
    135168        $interest_rate       = 0.8;
    136169
    137         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    138 
    139         $this->assertEquals( 1080.00, $result );
    140     }
    141 
    142     /**
    143      * @test
    144      */
    145     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2() {
     170        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     171
     172        $this->assertEquals(1080.00, $result);
     173    }
     174
     175    /**
     176     * @test
     177     */
     178    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2()
     179    {
    146180        $installment_backend = new Omise_Backend_Installment();
    147181        $purchase_amount     = 17900.00;
     
    149183        $interest_rate       = 0.69;
    150184
    151         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    152 
    153         $this->assertEquals( 3106.84, $result );
    154     }
    155 
    156     /**
    157      * @test
    158      */
    159     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3() {
     185        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     186
     187        $this->assertEquals(3106.84, $result);
     188    }
     189
     190    /**
     191     * @test
     192     */
     193    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3()
     194    {
    160195        $installment_backend = new Omise_Backend_Installment();
    161196        $purchase_amount     = 5000.00;
     
    163198        $interest_rate       = 0.8;
    164199
    165         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    166 
    167         $this->assertEquals( 540.00, $result );
    168     }
    169 
    170     /**
    171      * @test
    172      */
    173     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4() {
     200        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     201
     202        $this->assertEquals(540.00, $result);
     203    }
     204
     205    /**
     206     * @test
     207     */
     208    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4()
     209    {
    174210        $installment_backend = new Omise_Backend_Installment();
    175211        $purchase_amount     = 3000.00;
     
    177213        $interest_rate       = 0.74;
    178214
    179         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    180 
    181         $this->assertEquals( 772.20, $result );
    182     }
    183 
    184     /**
    185      * @test
    186      */
    187     public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1() {
     215        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     216
     217        $this->assertEquals(772.20, $result);
     218    }
     219
     220    /**
     221     * @test
     222     */
     223    public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1()
     224    {
    188225        $installment_backend = new Omise_Backend_Installment();
    189226        $purchase_amount     = 10000.00;
     
    191228        $interest_rate       = 0;
    192229
    193         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    194 
    195         $this->assertEquals( 1000.00, $result );
    196     }
    197 
    198     /**
    199      * @test
    200      */
    201     public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2() {
     230        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     231
     232        $this->assertEquals(1000.00, $result);
     233    }
     234
     235    /**
     236     * @test
     237     */
     238    public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2()
     239    {
    202240        $installment_backend = new Omise_Backend_Installment();
    203241        $purchase_amount     = 5000.00;
     
    205243        $interest_rate       = 0;
    206244
    207         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    208 
    209         $this->assertEquals( 833.33, $result );
     245        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     246
     247        $this->assertEquals(833.33, $result);
    210248    }
    211249}
     
    218256 * @see includes/class-omise-capabilities
    219257 */
    220 class Omise_Capabilities {
     258class Omise_Capabilities
     259{
    221260    /**
    222261     * @var self
     
    224263    protected static $the_instance = null;
    225264
    226     public static function retrieve() {
     265    public static function retrieve()
     266    {
    227267        self::$the_instance = self::$the_instance ?: new self();
    228268        return self::$the_instance;
    229269    }
    230270
    231     public function is_zero_interest() {
     271    public function is_zero_interest()
     272    {
    232273        return false;
    233274    }
  • omise/trunk/CHANGELOG.md

    r2832733 r2852769  
    11# CHANGELOG
     2
     3### [v4.28.0 _(Jan 24, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.28.0)
     4- Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339))
     5- Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336))
     6- Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333))
     7- Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338))
     8- Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337))
     9- Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342))
    210
    311### [v4.27.0 _(Dec 7, 2022)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.27.0)
  • omise/trunk/assets/css/omise-css.css

    r2809311 r2852769  
    6565
    6666/**
    67  * Omise Bill Payment Tesco
     67 * Omise Bill Payment Lotus
    6868 * CSS for the 'Thank You' (order-received) page.
    6969 */
     
    404404
    405405/** MAYBANK **/
    406 .bank-logo.ezypay {
     406.bank-logo.mbb {
    407407    background: url('../images/maybank.svg') #ffcf00;
    408408    border-color: #ffcf00;
  • omise/trunk/composer.json

    r2501457 r2852769  
    55    "license": "MIT",
    66    "require-dev": {
    7         "phpunit/phpunit": "^8.1"
     7        "phpunit/phpunit": "^5.7 || ^9.5"
    88    }
    99}
  • omise/trunk/includes/admin/views/omise-page-settings.php

    r2832733 r2852769  
    3030                )
    3131            ),
    32             esc_url( 'https://dashboard.omise.co/v2/settings/keys' ),
     32            esc_url( 'https://dashboard.omise.co/v2/settings/keys' )
    3333        );
    3434        ?>
  • omise/trunk/includes/backends/class-omise-backend-installment.php

    r2783685 r2852769  
    11<?php
     2
    23/**
    34 * Note: The calculations in this class depend on the countries that
     
    1112 * @method public calculate_monthly_payment_amount
    1213 */
    13 class Omise_Backend_Installment extends Omise_Backend {
     14class Omise_Backend_Installment extends Omise_Backend
     15{
    1416    /**
    1517     * @var array  of known installment providers.
     
    1719    protected static $providers = array();
    1820
    19     public function initiate() {
     21    public function initiate()
     22    {
    2023        self::$providers = array(
    2124            'installment_first_choice' => array(
    2225                'bank_code'          => 'first_choice',
    23                 'title'              => __( 'Krungsri First Choice', 'omise' ),
     26                'title'              => __('Krungsri First Choice', 'omise'),
    2427                'interest_rate'      => 1.3,
    2528                'min_allowed_amount' => 300.00,
     
    2831            'installment_bay' => array(
    2932                'bank_code'          => 'bay',
    30                 'title'              => __( 'Krungsri', 'omise' ),
     33                'title'              => __('Krungsri', 'omise'),
    3134                'interest_rate'      => 0.8,
    3235                'min_allowed_amount' => 500.00,
     
    3538            'installment_ktc' => array(
    3639                'bank_code'          => 'ktc',
    37                 'title'              => __( 'Krungthai Card (KTC)', 'omise' ),
     40                'title'              => __('Krungthai Card (KTC)', 'omise'),
    3841                'interest_rate'      => 0.8,
    3942                'min_allowed_amount' => 300.00,
     
    4245            'installment_bbl' => array(
    4346                'bank_code'          => 'bbl',
    44                 'title'              => __( 'Bangkok Bank', 'omise' ),
     47                'title'              => __('Bangkok Bank', 'omise'),
    4548                'interest_rate'      => 0.8,
    4649                'min_allowed_amount' => 500.00,
     
    4952            'installment_kbank' => array(
    5053                'bank_code'          => 'kbank',
    51                 'title'              => __( 'Kasikorn Bank', 'omise' ),
     54                'title'              => __('Kasikorn Bank', 'omise'),
    5255                'interest_rate'      => 0.65,
    5356                'min_allowed_amount' => 300.00,
     
    5659            'installment_scb' => array(
    5760                'bank_code'          => 'scb',
    58                 'title'              => __( 'Siam Commercial Bank', 'omise' ),
     61                'title'              => __('Siam Commercial Bank', 'omise'),
    5962                'interest_rate'      => 0.74,
    6063                'min_allowed_amount' => 500.00,
     
    6366            'installment_citi' => array(
    6467                'bank_code'          => 'citi',
    65                 'title'              => __( 'Citibank', 'omise' ),
     68                'title'              => __('Citibank', 'omise'),
    6669                'interest_rate'      => 0,
    6770                'min_allowed_amount' => 500.00,
     
    7073            'installment_ttb' => array(
    7174                'bank_code'          => 'ttb',
    72                 'title'              => __( 'TMBThanachart Bank', 'omise' ),
     75                'title'              => __('TMBThanachart Bank', 'omise'),
    7376                'interest_rate'      => 0,
    7477                'min_allowed_amount' => 500.00,
     
    7780            'installment_uob' => array(
    7881                'bank_code'          => 'uob',
    79                 'title'              => __( 'United Overseas Bank', 'omise' ),
    80                 'interest_rate'      => 0,
    81                 'min_allowed_amount' => 500.00,
    82             ),
    83 
    84             'installment_ezypay' => array(
    85                 'bank_code'          => 'ezypay',
    86                 'title'              => __( 'Maybank (EzyPay)', 'omise' ),
    87                 'interest_rate'      => 0,
    88                 'min_allowed_amount' => 500.00,
     82                'title'              => __('United Overseas Bank', 'omise'),
     83                'interest_rate'      => 0,
     84                'min_allowed_amount' => 500.00,
     85            ),
     86
     87            'installment_mbb' => array(
     88                'bank_code'          => 'mbb',
     89                'title'              => __('Maybank', 'omise'),
     90                'interest_rate'      => 0,
     91                'min_allowed_amount' => 500.00,
     92                'zero_interest_installments' => true,
     93                'terms_min_allowed_amount' => [
     94                    6 => 500.00,
     95                    12 => 1000.00,
     96                    18 => 1500.00,
     97                    24 => 2000.00
     98                ]
    8999            ),
    90100        );
     101    }
     102
     103    public function get_provider($id)
     104    {
     105        return self::$providers[$id];
    91106    }
    92107
     
    97112     * @return array  of an available installment providers
    98113     */
    99     public function get_available_providers( $currency, $purchase_amount ) {
     114    public function get_available_providers($currency, $purchase_amount)
     115    {
    100116        $capabilities = $this->capabilities();
    101117
    102         if ( !$capabilities ){
     118        if (!$capabilities) {
    103119            return null;
    104120        }
    105121
     122        $supportedProviderList = [];
     123
    106124        // Note: As installment payment at the moment only supports THB and MYR currency, the
    107125        //       $purchase_amount is multiplied with 100 to convert the amount into subunit (satang and sen).
    108         $providers = $capabilities->getInstallmentBackends( $currency, ( $purchase_amount * 100 ) );
    109 
    110         foreach ( $providers as &$provider ) {
    111             $provider_detail = self::$providers[ $provider->_id ];
    112 
    113             $provider->provider_code   = str_replace( 'installment_', '', $provider->_id );
    114             $provider->provider_name   = isset( $provider_detail ) ? $provider_detail['title'] : strtoupper( $provider->code );
    115             $provider->interest_rate   = $capabilities->is_zero_interest() ? 0 : ( $provider_detail['interest_rate'] );
    116             $provider->available_plans = $this->get_available_plans(
    117                 $purchase_amount,
    118                 $provider->allowed_installment_terms,
    119                 $provider->interest_rate,
    120                 $provider_detail['min_allowed_amount']
    121             );
     126        $providers = $capabilities->getInstallmentBackends($currency, ($purchase_amount * 100));
     127
     128        foreach ($providers as &$provider) {
     129            if (isset(self::$providers[$provider->_id])) {
     130                $provider_detail = self::$providers[$provider->_id];
     131
     132                $provider->provider_code   = str_replace('installment_', '', $provider->_id);
     133                $provider->provider_name   = isset($provider_detail)
     134                    ? $provider_detail['title']
     135                    : strtoupper($provider->code);
     136                $provider->interest_rate   = $capabilities->is_zero_interest()
     137                    ? 0 : ($provider_detail['interest_rate']);
     138                $provider->available_plans = $this->get_available_plans(
     139                    $purchase_amount,
     140                    $provider->allowed_installment_terms,
     141                    $provider->interest_rate,
     142                    $provider_detail
     143                );
     144                if (count($provider->available_plans) > 0) {
     145                    $supportedProviderList[] = $provider;
     146                }
     147            }
    122148        }
    123149
    124         usort( $providers, function( $a, $b ) {
    125             return strcmp( $a->provider_name, $b->provider_name );
     150        usort($supportedProviderList, function ($a, $b) {
     151            return strcmp($a->provider_name, $b->provider_name);
    126152        });
    127153
    128         return $providers;
     154        return $supportedProviderList;
    129155    }
    130156
     
    137163     * @return array  of an filtered available terms
    138164     */
    139     public function get_available_plans( $purchase_amount, $allowed_installment_terms, $interest_rate, $min_allowed_amount ) {
     165    public function get_available_plans($purchase_amount, $allowed_installment_terms, $interest_rate, $provider_detail)
     166    {
    140167        $plans = array();
    141168
    142         sort( $allowed_installment_terms );
    143 
    144         foreach ( $allowed_installment_terms as $term_length ) {
    145             $monthly_amount = $this->calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate );
    146 
    147             if ( $monthly_amount < $min_allowed_amount ) {
     169        $min_allowed_amount = $provider_detail['min_allowed_amount'];
     170        sort($allowed_installment_terms);
     171
     172        foreach ($allowed_installment_terms as $term_length) {
     173            $monthly_amount = $this->calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate);
     174
     175            if (isset($provider_detail['terms_min_allowed_amount'])) {
     176                $terms_min_allowed_amount = $provider_detail['terms_min_allowed_amount'];
     177                $min_allowed_amount = round($terms_min_allowed_amount[$term_length] / $term_length, 2);
     178            }
     179
     180            if ($monthly_amount < $min_allowed_amount) {
    148181                break;
    149182            }
     
    165198     * @return float  of a installment monthly payment (round up to 2 decimals).
    166199     */
    167     public function calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate ) {
     200    public function calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate)
     201    {
    168202        $interest = $purchase_amount * $interest_rate * $term_length / 100;
    169         return round( ( $purchase_amount + $interest ) / $term_length, 2 );
     203        return round(($purchase_amount + $interest) / $term_length, 2);
    170204    }
    171205}
  • omise/trunk/includes/class-omise-capabilities.php

    r2795404 r2852769  
    157157     * @return string
    158158     */
    159     public function getTouchNGoBackends() {
    160         $params   = array();
    161         $params[] = $this->capabilities->backendFilter['type']('touch_n_go');
    162    
    163         return $this->capabilities->getBackends( $params );
     159    public function getTouchNGoBackends()
     160    {
     161        return $this->getBackendByType('touch_n_go');
     162    }
     163
     164    /**
     165     * Retrieves backend by type
     166     */
     167    public function getBackendByType($sourceType)
     168    {
     169        $params = [];
     170        $params[] = $this->capabilities->backendFilter['type']($sourceType);
     171        return $this->capabilities->getBackends($params);
    164172    }
    165173
    166174    /**
    167175     * Retrieves details of fpx bank list from capabilities.
    168      *
    169      * @return string
    170      */
    171     public function getFPXBanks() {
    172         $params   = array();
    173         $params[] = $this->capabilities->backendFilter['type']('fpx');
    174    
    175         return $this->capabilities->getBackends( $params );
     176     */
     177    public function getFPXBanks()
     178    {
     179        return $this->getBackendByType('fpx');
    176180    }
    177181
     
    189193     * @return bool  True if merchant absorbs the interest or else, false.
    190194     */
    191     public function is_zero_interest() {
     195    public function is_zero_interest()
     196    {
    192197        return $this->capabilities['zero_interest_installments'];
    193198    }
     
    196201     * @return array list of omise backends sourc_type.
    197202     */
    198     public function get_available_payment_methods() {
     203    public function get_available_payment_methods()
     204    {
    199205        $backends = $this->getBackends();
    200206        $backends = json_decode(json_encode($backends), true);
     
    202208        return array_merge(array_column($backends, '_id'),$token_methods);
    203209    }
     210
     211    /**
     212     * Retrieves details of Shopee Pay from capabilities.
     213     *
     214     * @param string $sourceType
     215     */
     216    public function getShopeeBackend($sourceType)
     217    {
     218        $shopeePaySourceTypes = [Omise_Payment_ShopeePay::ID, Omise_Payment_ShopeePay::JUMPAPP_ID];
     219
     220        if (!in_array($sourceType, $shopeePaySourceTypes)) {
     221            return null;
     222        }
     223
     224        return $this->getBackendByType($sourceType);
     225    }
    204226}
  • omise/trunk/includes/gateway/class-omise-payment-alipay.php

    r2832733 r2852769  
    5858    public function charge($order_id, $order)
    5959    {
    60         $currency = $order->getCurrency();
     60        $currency = $order->get_currency();
    6161        return OmiseCharge::create([
    6262            'amount'      => Omise_Money::to_subunit($order->get_total(), $currency),
  • omise/trunk/includes/gateway/class-omise-payment-billpayment-tesco.php

    r2832733 r2852769  
    1111        $this->id                 = 'omise_billpayment_tesco';
    1212        $this->has_fields         = false;
    13         $this->method_title       = __( 'Opn Payments Bill Payment: Tesco', 'omise' );
     13        $this->method_title       = __( 'Opn Payments Lotus\'s Bill Payment', 'omise' );
    1414        $this->method_description = wp_kses(
    15             __( 'Accept payments through <strong>Tesco Bill Payment</strong> via Opn Payments payment gateway.', 'omise' ),
     15            __( 'Accept payments through <strong>Lotus\'s Bill Payment</strong> via Opn Payments payment gateway.', 'omise' ),
    1616            array( 'strong' => array() )
    1717        );
     
    4141                'title'   => __( 'Enable/Disable', 'omise' ),
    4242                'type'    => 'checkbox',
    43                 'label'   => __( 'Enable Opn Payments Tesco Bill Payment', 'omise' ),
     43                'label'   => __( 'Enable Opn Payments Lotus\'s Bill Payment', 'omise' ),
    4444                'default' => 'no'
    4545            ),
     
    4949                'type'        => 'text',
    5050                'description' => __( 'This controls the title the user sees during checkout.', 'omise' ),
    51                 'default'     => __( 'Bill Payment: Tesco', 'omise' ),
     51                'default'     => __( 'Lotus\'s Bill Payment', 'omise' ),
    5252            ),
    5353
     
    125125                echo sprintf(
    126126                    wp_kses(
    127                         __( 'Please bring this barcode to pay at Tesco Lotus by:<br/><strong>%1$s %2$s</strong>.', 'omise' ),
     127                        __( 'Please bring this barcode to pay at Lotus\'s by:<br/><strong>%1$s %2$s</strong>.', 'omise' ),
    128128                        array( 'br' => array(), 'strong' => array() )
    129129                    ),
     
    154154                        __(
    155155                            '
    156                             Tesco Lotus may charge a small fee for the transaction.<br/>
     156                            Lotus\'s Bill Payment may charge a small fee for the transaction.<br/>
    157157                            If you fail to make payment by the stated time, your order will be automatically canceled.
    158158                            ', 'omise'
     
    189189
    190190    /**
    191      * Convert a given SVG Bill Payment Tesco's barcode to HTML format.
     191     * Convert a given SVG Bill Payment Lotus's barcode to HTML format.
    192192     *
    193193     * Note that the SVG barcode contains with the following structure:
     
    211211     * @param  string $barcode_svg
    212212     *
    213      * @return string  of a generated Bill Payment Tesco's barcode in HTML format.
     213     * @return string  of a generated Bill Payment Lotus's barcode in HTML format.
    214214     */
    215215    public function barcode_svg_to_html( $barcode_svg ) {
     
    231231            // Set HTML attributes based on <rect> node's attributes.
    232232            $div_rect = $xhtml->createElement( 'div' );
    233             $div_rect->setAttribute( 'style', "float: left; position: relative; height: 50px; border-left: $width solid #000000; width: 0; margin-left: $margin" );
     233            $div_rect->setAttribute('style', sprintf(
     234                'float: left; position: relative;
     235                height: 50px;
     236                border-left:  %spx solid #000000;
     237                width: 0; margin-left: %s',
     238                $width,
     239                $margin
     240            ));
    234241            $div_wrapper->appendChild( $div_rect );
    235242
  • omise/trunk/includes/gateway/class-omise-payment-installment.php

    r2832733 r2852769  
    11<?php
    2 defined( 'ABSPATH' ) or die( 'No direct script access allowed.' );
     2defined('ABSPATH') or die('No direct script access allowed.');
    33
    44/**
    55 * @since 3.4
    66 */
    7 class Omise_Payment_Installment extends Omise_Payment_Offsite {
    8     public function __construct() {
     7class Omise_Payment_Installment extends Omise_Payment_Offsite
     8{
     9    public function __construct()
     10    {
    911        parent::__construct();
    1012
    1113        $this->id                 = 'omise_installment';
    1214        $this->has_fields         = true;
    13         $this->method_title       = __( 'Opn Payments Installments', 'omise' );
     15        $this->method_title       = __('Opn Payments Installments', 'omise');
    1416        $this->method_description = wp_kses(
    15             __( 'Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise' ),
    16             array( 'strong' => array() )
     17            __('Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise'),
     18            array('strong' => array())
    1719        );
    18         $this->supports           = array( 'products', 'refunds' );
     20        $this->supports           = array('products', 'refunds');
    1921
    2022        $this->init_form_fields();
    2123        $this->init_settings();
    2224
    23         $this->title                = $this->get_option( 'title' );
    24         $this->description          = $this->get_option( 'description' );
    25         $this->restricted_countries = array( 'TH', 'MY' );
     25        $this->title                = $this->get_option('title');
     26        $this->description          = $this->get_option('description');
     27        $this->restricted_countries = array('TH', 'MY');
    2628
    2729        $this->backend     = new Omise_Backend_Installment;
    2830
    29         add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
    30         add_action( 'woocommerce_order_action_' . $this->id . '_sync_payment', array( $this, 'sync_payment' ) );
    31         add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' );
     31        add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
     32        add_action('woocommerce_order_action_' . $this->id . '_sync_payment', array($this, 'sync_payment'));
     33        add_action('woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute');
    3234    }
    3335
     
    3638     * @see woocommerce/includes/abstracts/abstract-wc-settings-api.php
    3739     */
    38     public function init_form_fields() {
     40    public function init_form_fields()
     41    {
    3942        $this->form_fields = array(
    4043            'enabled' => array(
    41                 'title'   => __( 'Enable/Disable', 'omise' ),
     44                'title'   => __('Enable/Disable', 'omise'),
    4245                'type'    => 'checkbox',
    43                 'label'   => __( 'Enable Opn Payments Installment Payments', 'omise' ),
     46                'label'   => __('Enable Opn Payments Installment Payments', 'omise'),
    4447                'default' => 'no'
    4548            ),
    4649
    4750            'title' => array(
    48                 'title'       => __( 'Title', 'omise' ),
     51                'title'       => __('Title', 'omise'),
    4952                'type'        => 'text',
    50                 'description' => __( 'This controls the title the user sees during checkout.', 'omise' ),
    51                 'default'     => __( 'Installments', 'omise' ),
     53                'description' => __('This controls the title the user sees during checkout.', 'omise'),
     54                'default'     => __('Installments', 'omise'),
    5255            ),
    5356
    5457            'description' => array(
    55                 'title'       => __( 'Description', 'omise' ),
     58                'title'       => __('Description', 'omise'),
    5659                'type'        => 'textarea',
    57                 'description' => __( 'This controls the description the user sees during checkout.', 'omise' )
     60                'description' => __('This controls the description the user sees during checkout.', 'omise')
    5861            ),
    5962        );
     
    6366     * @inheritdoc
    6467     */
    65     public function payment_fields() {
     68    public function payment_fields()
     69    {
    6670        parent::payment_fields();
    6771
     
    7377            'templates/payment/form-installment.php',
    7478            array(
    75                 'installment_backends' => $this->backend->get_available_providers( $currency, $cart_total ),
     79                'installment_backends' => $this->backend->get_available_providers($currency, $cart_total),
    7680                'is_zero_interest'     => $capabilities ? $capabilities->is_zero_interest() : false
    7781            )
     
    8589    {
    8690        $source_type = isset($_POST['source']['type']) ? $_POST['source']['type'] : '';
    87         $installment_terms = isset( $_POST[ $source_type . '_installment_terms'] ) ? $_POST[ $source_type . '_installment_terms'] : '';
     91        $installment_terms = isset($_POST[$source_type . '_installment_terms']) ? $_POST[$source_type . '_installment_terms'] : '';
    8892        $currency = $order->get_currency();
     93        $provider = $this->backend->get_provider($source_type);
    8994
    90         return OmiseCharge::create([
     95        $payload = [
    9196            'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
    9297            'currency' => $currency,
     
    98103            'return_uri' => $this->getRedirectUrl('omise_installment_callback', $order_id, $order),
    99104            'metadata' => $this->getMetadata($order_id, $order)
    100         ]);
     105        ];
     106
     107        if (isset($provider['zero_interest_installments'])) {
     108            $payload['zero_interest_installments'] = $provider['zero_interest_installments'];
     109        }
     110
     111        return OmiseCharge::create($payload);
    101112    }
    102113
     
    108119     * @return array|false
    109120     */
    110     public function is_capability_support( $available_payment_methods ) {
     121    public function is_capability_support($available_payment_methods)
     122    {
    111123        return preg_grep('/^installment_/', $available_payment_methods);
    112124    }
  • omise/trunk/includes/gateway/class-omise-payment-shopeepay.php

    r2832733 r2852769  
    22defined( 'ABSPATH' ) or die( 'No direct script access allowed.' );
    33
    4 class Omise_Payment_ShopeePay extends Omise_Payment_Offsite {
     4class Omise_Payment_ShopeePay extends Omise_Payment_Offsite
     5{
     6    /**
     7     * Backends identifier
     8     * @var string
     9     */
     10    const ID = 'shopeepay';
     11    const JUMPAPP_ID = 'shopeepay_jumpapp';
     12
    513    public function __construct() {
    614        parent::__construct();
     
    1119        $this->method_description = __( 'Accept payment through <strong>ShopeePay</strong> via Opn Payments payment gateway.', 'omise' );
    1220        $this->supports           = array( 'products', 'refunds' );
     21        $this->source_type        = $this->getSource();
    1322
    1423        $this->init_form_fields();
     
    1726        $this->title                = $this->get_option( 'title' );
    1827        $this->description          = $this->get_option( 'description' );
    19         $this->restricted_countries = array( 'MY' );
    20         $this->source_type          = 'shopeepay';
     28        $this->restricted_countries = array( 'MY', 'TH', 'SG' );
    2129
    2230        add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' );
     
    7078
    7179    /**
     80     * Return the right ShopeePay backend depending on the platform and availability of
     81     * the backend in the capability
     82     */
     83    private function getSource()
     84    {
     85        $capabilities = Omise_Capabilities::retrieve();
     86        $isShopeepayJumpAppEnabled = $capabilities->getShopeeBackend(self::JUMPAPP_ID);
     87        $isShopeepayEnabled = $capabilities->getShopeeBackend(self::ID);
     88
     89        // If user is in mobile and jump app is enabled then return shopeepay_jumpapp as source
     90        if (Omise_Util::isMobilePlatform() && !empty($isShopeepayJumpAppEnabled)) {
     91            return self::JUMPAPP_ID;
     92        }
     93
     94        // If above condition fails then it means either
     95        //
     96        // Case 1.
     97        // User is using mobile device but jump app is not enabled.
     98        // This means shopeepay direct is enabled otherwise this code would not execute.
     99        //
     100        // Case 2.
     101        // Jump app is enabled but user is not using mobile device
     102        //
     103        // In both cases we will want to show the shopeepay MPM backend first if MPM is enabled.
     104        // If MPM is not enabled then it means jump app is enabled because this code would never
     105        // execute if none of the shopee backends were disabled.
     106        return !empty($isShopeepayEnabled) ? self::ID : self::JUMPAPP_ID;
     107    }
     108
     109    /**
    72110     * Get icons
    73111     *
  • omise/trunk/includes/libraries/omise-php/lib/omise/OmiseCapabilities.php

    r2783685 r2852769  
    127127        return function ($backend) use ($amount, $defMin, $defMax) {
    128128            // temporary hack for now to correct min value for installments to fixed minimum (different to normal charge minimum)
    129             if ($backend->type === 'installment') {
     129            if ($backend->type === 'installment' && get_woocommerce_currency() === 'THB') {
    130130                $min = self::INSTALLMENT_MINIMUM;
    131131            } else {
  • omise/trunk/omise-util.php

    r2588190 r2852769  
    3636            return null;
    3737        }
     38
     39        /**
     40         * Check if current platform is mobile or not
     41         */
     42        public static function isMobilePlatform()
     43        {
     44            return null !== self::get_platform_type(wc_get_user_agent());
     45        }
    3846    }
    3947}
    40 ?>
  • omise/trunk/omise-woocommerce.php

    r2832733 r2852769  
    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.27.0
     7 * Version:     4.28.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.27.0';
     25    public $version = '4.28.0';
    2626
    2727    /**
  • omise/trunk/phpunit.xml

    r2501457 r2852769  
    1616        </testsuite>
    1717    </testsuites>
     18    <coverage>
     19        <include>
     20            <directory suffix=".php">./*</directory>
     21        </include>
     22        <exclude>
     23            <directory suffix=".php">tests</directory>
     24            <directory suffix=".php">vendor</directory>
     25        </exclude>
     26    </coverage>
    1827</phpunit>
  • omise/trunk/readme.txt

    r2832733 r2852769  
    44Requires at least: 4.3.1
    55Tested up to: 6.0.2
    6 Stable tag: 4.27.0
     6Stable tag: 4.28.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== Changelog ==
     36
     37= 4.28.0 =
     38
     39- Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339))
     40- Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336))
     41- Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333))
     42- Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338))
     43- Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337))
     44- Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342))
    3645
    3746= 4.27.0 =
  • omise/trunk/templates/payment/form-installment.php

    r2809311 r2852769  
    4747<?php else: ?>
    4848    <p>
    49         <?php echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' ); ?>
     49        <?php
     50            if(get_woocommerce_currency() === 'THB') {
     51                echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' );
     52            } else {
     53                echo __( 'Purchase Amount is lower than the monthly minimum payment amount.', 'omise' );
     54            }
     55        ?>
    5056    </p>
    5157<?php endif; ?>
  • omise/trunk/tests/unit/includes/backends/class-omise-backend-installment-test.php

    r2621135 r2852769  
    11<?php
     2
    23use PHPUnit\Framework\TestCase;
     4
    35require_once __DIR__ . '/../../class-omise-unit-test.php';
    46
    5 class Omise_Backend_Installment_Test extends TestCase {
    6     public static function setUpBeforeClass(): void {
    7         Omise_Unit_Test::include_class( 'backends/class-omise-backend.php' );
    8         Omise_Unit_Test::include_class( 'backends/class-omise-backend-installment.php' );
    9     }
    10 
    11     /**
    12      * @test
    13      */
    14     public function get_only_valid_plans_from_given_bay_allowed_installment_terms() {
    15         $installment_backend = new Omise_Backend_Installment();
    16         $purchase_amount     = 2000.00;
    17         $allowed_terms       = array( 3, 4, 6, 9, 10 );
    18         $interest_rate       = 0.8;
    19         $min_allowed_amount  = 500.00;
    20 
    21         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    22 
    23         $this->assertEquals( 2, count( $result ) );
    24         $this->assertEquals( array(
    25             array( 'term_length' => 3, 'monthly_amount' => 682.67 ),
    26             array( 'term_length' => 4, 'monthly_amount' => 516.00 ),
    27         ), $result );
    28     }
    29    
    30     /**
    31      * @test
    32      */
    33     public function get_only_valid_plans_from_given_kbank_allowed_installment_terms() {
    34         $installment_backend = new Omise_Backend_Installment();
    35         $purchase_amount     = 2000.00;
    36         $allowed_terms       = array( 3, 4, 6, 10 );
     7class Omise_Backend_Installment_Test extends TestCase
     8{
     9    public static function setUpBeforeClass(): void
     10    {
     11        Omise_Unit_Test::include_class('backends/class-omise-backend.php');
     12        Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php');
     13    }
     14
     15    /**
     16     * @test
     17     */
     18    public function get_only_valid_plans_from_given_bay_allowed_installment_terms()
     19    {
     20        $installment_backend = new Omise_Backend_Installment();
     21        $purchase_amount     = 2000.00;
     22        $allowed_terms       = array(3, 4, 6, 9, 10);
     23        $interest_rate       = 0.8;
     24        $provider            = $installment_backend->get_provider('installment_bay');
     25
     26        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     27
     28        $this->assertEquals(2, count($result));
     29        $this->assertEquals(array(
     30            array('term_length' => 3, 'monthly_amount' => 682.67),
     31            array('term_length' => 4, 'monthly_amount' => 516.00),
     32        ), $result);
     33    }
     34
     35    /**
     36     * @test
     37     */
     38    public function get_only_valid_plans_from_given_kbank_allowed_installment_terms()
     39    {
     40        $installment_backend = new Omise_Backend_Installment();
     41        $purchase_amount     = 2000.00;
     42        $allowed_terms       = array(3, 4, 6, 10);
    3743        $interest_rate       = 0.65;
    38         $min_allowed_amount  = 300.00;
    39 
    40         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    41 
    42         $this->assertEquals( 3, count( $result ) );
    43         $this->assertEquals( array(
    44             array( 'term_length' => 3, 'monthly_amount' => 679.67 ),
    45             array( 'term_length' => 4, 'monthly_amount' => 513.00 ),
    46             array( 'term_length' => 6, 'monthly_amount' => 346.33 ),
    47         ), $result );
    48     }
    49 
    50     /**
    51      * @test
    52      */
    53     public function get_only_valid_plans_from_given_scb_allowed_installment_terms() {
    54         $installment_backend = new Omise_Backend_Installment();
    55         $purchase_amount     = 2000.00;
    56         $allowed_terms       = array( 3, 4, 6, 8, 10 );
     44        $provider            = $installment_backend->get_provider('installment_kbank');
     45
     46        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     47
     48        $this->assertEquals(3, count($result));
     49        $this->assertEquals(array(
     50            array('term_length' => 3, 'monthly_amount' => 679.67),
     51            array('term_length' => 4, 'monthly_amount' => 513.00),
     52            array('term_length' => 6, 'monthly_amount' => 346.33),
     53        ), $result);
     54    }
     55
     56    /**
     57     * @test
     58     */
     59    public function get_only_valid_plans_from_given_scb_allowed_installment_terms()
     60    {
     61        $installment_backend = new Omise_Backend_Installment();
     62        $purchase_amount     = 2000.00;
     63        $allowed_terms       = array(3, 4, 6, 8, 10);
    5764        $interest_rate       = 0.74;
    58         $min_allowed_amount  = 500.00;
    59 
    60         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    61 
    62         $this->assertEquals( 2, count( $result ) );
    63         $this->assertEquals( array(
    64             array( 'term_length' => 3, 'monthly_amount' => 681.47 ),
    65             array( 'term_length' => 4, 'monthly_amount' => 514.80 ),
    66         ), $result );
    67     }
    68 
    69     /**
    70      * @test
    71      */
    72     public function get_only_valid_plans_from_given_bbl_allowed_installment_terms() {
     65        $provider            = $installment_backend->get_provider('installment_scb');
     66
     67        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     68
     69        $this->assertEquals(2, count($result));
     70        $this->assertEquals(array(
     71            array('term_length' => 3, 'monthly_amount' => 681.47),
     72            array('term_length' => 4, 'monthly_amount' => 514.80),
     73        ), $result);
     74    }
     75
     76    /**
     77     * @test
     78     */
     79    public function get_only_valid_plans_from_given_bbl_allowed_installment_terms()
     80    {
    7381        $installment_backend = new Omise_Backend_Installment();
    7482        $purchase_amount     = 3000.00;
    75         $allowed_terms       = array( 3, 4, 6, 8, 10 );
    76         $interest_rate       = 0.8;
    77         $min_allowed_amount  = 500.00;
    78 
    79         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    80 
    81         $this->assertEquals( 3, count( $result ) );
    82         $this->assertEquals( array(
    83             array( 'term_length' => 3, 'monthly_amount' => 1024.00 ),
    84             array( 'term_length' => 4, 'monthly_amount' => 774.00 ),
    85             array( 'term_length' => 6, 'monthly_amount' => 524.00 ),
    86         ), $result );
    87     }
    88 
    89     /**
    90      * @test
    91      */
    92     public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms() {
     83        $allowed_terms       = array(3, 4, 6, 8, 10);
     84        $interest_rate       = 0.8;
     85        $provider            = $installment_backend->get_provider('installment_bbl');
     86
     87        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     88
     89        $this->assertEquals(3, count($result));
     90        $this->assertEquals(array(
     91            array('term_length' => 3, 'monthly_amount' => 1024.00),
     92            array('term_length' => 4, 'monthly_amount' => 774.00),
     93            array('term_length' => 6, 'monthly_amount' => 524.00),
     94        ), $result);
     95    }
     96
     97    /**
     98     * @test
     99     */
     100    public function get_only_valid_plans_from_given_mbb_allowed_installment_terms()
     101    {
     102        $installment_backend = new Omise_Backend_Installment();
     103        $purchase_amount     = 20000.00;
     104        $allowed_terms       = array(6, 12, 18, 24);
     105        $interest_rate       = 0.8;
     106        $provider            = $installment_backend->get_provider('installment_mbb');
     107
     108        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     109
     110        $this->assertEquals(4, count($result));
     111        $this->assertEquals(array(
     112            array('term_length' => 6, 'monthly_amount' => 3493.33),
     113            array('term_length' => 12, 'monthly_amount' => 1826.67),
     114            array('term_length' => 18, 'monthly_amount' => 1271.11),
     115            array('term_length' => 24, 'monthly_amount' => 993.33),
     116        ), $result);
     117    }
     118
     119    /**
     120     * @test
     121     */
     122    public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms()
     123    {
    93124        $installment_backend = new Omise_Backend_Installment();
    94125        $purchase_amount     = 3000.00;
    95         $allowed_terms       = array( 3, 10, 4, 8, 6 );
    96         $interest_rate       = 0.8;
    97         $min_allowed_amount  = 500.00;
    98 
    99         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    100 
    101         $this->assertEquals( 3, count( $result ) );
    102         $this->assertEquals( array(
    103             array( 'term_length' => 3, 'monthly_amount' => 1024.00 ),
    104             array( 'term_length' => 4, 'monthly_amount' => 774.00 ),
    105             array( 'term_length' => 6, 'monthly_amount' => 524.00 ),
    106         ), $result );
    107     }
    108 
    109     /**
    110      * @test
    111      */
    112     public function get_only_valid_plans_from_zero_interest_installments() {
    113         $installment_backend = new Omise_Backend_Installment();
    114         $purchase_amount     = 2000.00;
    115         $allowed_terms       = array( 3, 4, 5 );
     126        $allowed_terms       = array(3, 10, 4, 8, 6);
     127        $interest_rate       = 0.8;
     128        $provider            = $installment_backend->get_provider('installment_bbl');
     129
     130        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     131
     132        $this->assertEquals(3, count($result));
     133        $this->assertEquals(array(
     134            array('term_length' => 3, 'monthly_amount' => 1024.00),
     135            array('term_length' => 4, 'monthly_amount' => 774.00),
     136            array('term_length' => 6, 'monthly_amount' => 524.00),
     137        ), $result);
     138    }
     139
     140    /**
     141     * @test
     142     */
     143    public function get_only_valid_plans_from_zero_interest_installments()
     144    {
     145        $installment_backend = new Omise_Backend_Installment();
     146        $purchase_amount     = 2000.00;
     147        $allowed_terms       = array(3, 4, 5);
    116148        $interest_rate       = 0;
    117         $min_allowed_amount  = 500.00;
    118 
    119         $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );
    120 
    121         $this->assertEquals( 2, count( $result ) );
    122         $this->assertEquals( array(
    123             array( 'term_length' => 3, 'monthly_amount' => 666.67 ),
    124             array( 'term_length' => 4, 'monthly_amount' => 500.00 ),
    125         ), $result );
    126     }
    127 
    128     /**
    129      * @test
    130      */
    131     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1() {
     149        $provider            = $installment_backend->get_provider('installment_bbl');
     150
     151        $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider);
     152
     153        $this->assertEquals(2, count($result));
     154        $this->assertEquals(array(
     155            array('term_length' => 3, 'monthly_amount' => 666.67),
     156            array('term_length' => 4, 'monthly_amount' => 500.00),
     157        ), $result);
     158    }
     159
     160    /**
     161     * @test
     162     */
     163    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1()
     164    {
    132165        $installment_backend = new Omise_Backend_Installment();
    133166        $purchase_amount     = 10000.00;
     
    135168        $interest_rate       = 0.8;
    136169
    137         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    138 
    139         $this->assertEquals( 1080.00, $result );
    140     }
    141 
    142     /**
    143      * @test
    144      */
    145     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2() {
     170        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     171
     172        $this->assertEquals(1080.00, $result);
     173    }
     174
     175    /**
     176     * @test
     177     */
     178    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2()
     179    {
    146180        $installment_backend = new Omise_Backend_Installment();
    147181        $purchase_amount     = 17900.00;
     
    149183        $interest_rate       = 0.69;
    150184
    151         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    152 
    153         $this->assertEquals( 3106.84, $result );
    154     }
    155 
    156     /**
    157      * @test
    158      */
    159     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3() {
     185        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     186
     187        $this->assertEquals(3106.84, $result);
     188    }
     189
     190    /**
     191     * @test
     192     */
     193    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3()
     194    {
    160195        $installment_backend = new Omise_Backend_Installment();
    161196        $purchase_amount     = 5000.00;
     
    163198        $interest_rate       = 0.8;
    164199
    165         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    166 
    167         $this->assertEquals( 540.00, $result );
    168     }
    169 
    170     /**
    171      * @test
    172      */
    173     public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4() {
     200        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     201
     202        $this->assertEquals(540.00, $result);
     203    }
     204
     205    /**
     206     * @test
     207     */
     208    public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4()
     209    {
    174210        $installment_backend = new Omise_Backend_Installment();
    175211        $purchase_amount     = 3000.00;
     
    177213        $interest_rate       = 0.74;
    178214
    179         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    180 
    181         $this->assertEquals( 772.20, $result );
    182     }
    183 
    184     /**
    185      * @test
    186      */
    187     public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1() {
     215        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     216
     217        $this->assertEquals(772.20, $result);
     218    }
     219
     220    /**
     221     * @test
     222     */
     223    public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1()
     224    {
    188225        $installment_backend = new Omise_Backend_Installment();
    189226        $purchase_amount     = 10000.00;
     
    191228        $interest_rate       = 0;
    192229
    193         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    194 
    195         $this->assertEquals( 1000.00, $result );
    196     }
    197 
    198     /**
    199      * @test
    200      */
    201     public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2() {
     230        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     231
     232        $this->assertEquals(1000.00, $result);
     233    }
     234
     235    /**
     236     * @test
     237     */
     238    public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2()
     239    {
    202240        $installment_backend = new Omise_Backend_Installment();
    203241        $purchase_amount     = 5000.00;
     
    205243        $interest_rate       = 0;
    206244
    207         $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate );
    208 
    209         $this->assertEquals( 833.33, $result );
     245        $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate);
     246
     247        $this->assertEquals(833.33, $result);
    210248    }
    211249}
     
    218256 * @see includes/class-omise-capabilities
    219257 */
    220 class Omise_Capabilities {
     258class Omise_Capabilities
     259{
    221260    /**
    222261     * @var self
     
    224263    protected static $the_instance = null;
    225264
    226     public static function retrieve() {
     265    public static function retrieve()
     266    {
    227267        self::$the_instance = self::$the_instance ?: new self();
    228268        return self::$the_instance;
    229269    }
    230270
    231     public function is_zero_interest() {
     271    public function is_zero_interest()
     272    {
    232273        return false;
    233274    }
Note: See TracChangeset for help on using the changeset viewer.