Plugin Directory

Changeset 3169110


Ignore:
Timestamp:
10/15/2024 08:45:09 AM (18 months ago)
Author:
webimpian
Message:

Add 4.2.5

Location:
bayarcash-wc
Files:
337 added
9 edited

Legend:

Unmodified
Added
Removed
  • bayarcash-wc/trunk/bayarcash-wc.php

    r3168764 r3169110  
    1313 * Plugin Name:         Bayarcash WC
    1414 * Plugin URI:          https://bayarcash.com/
    15  * Version:             4.2.4
     15 * Version:             4.2.5
    1616 * Description:         Accept payment from Malaysia. Bayarcash support FPX, Direct Debit, DuitNow OBW & DuitNow QR payment channels.
    1717 * Author:              Web Impian
  • bayarcash-wc/trunk/includes/admin/bayarcash-wc-script.js

    r3168764 r3169110  
    1616        // Use Promise.all for parallel initialization
    1717        Promise.all(paymentMethods.map(setupVerifyToken))
    18             .then(() => console.log('All payment methods initialized'));
     18            .then(() => {
     19                console.log('All payment methods initialized');
     20                setupAdditionalChargeFields();
     21            });
    1922
    2023        async function setupVerifyToken(method) {
     
    245248            });
    246249        }
     250
     251        function setupAdditionalChargeFields() {
     252            paymentMethods.forEach(method => {
     253                const chargeTypeField = $(`select#woocommerce_${method}_additional_charge_type`);
     254                const percentageField = $(`#woocommerce_${method}_additional_charge_percentage`).closest('tr');
     255
     256                function updatePercentageFieldVisibility() {
     257                    const selected = chargeTypeField.val();
     258                    if (selected === 'both') {
     259                        percentageField.show();
     260                    } else {
     261                        percentageField.hide();
     262                    }
     263                }
     264
     265                chargeTypeField.on('change', updatePercentageFieldVisibility);
     266                updatePercentageFieldVisibility(); // Initial setup
     267            });
     268        }
    247269    });
    248270})(jQuery);
  • bayarcash-wc/trunk/includes/src/AdminFormFields.php

    r3165859 r3169110  
    44class AdminFormFields {
    55    public static function get_form_fields($payment_method, $titles): array {
    6 
    7         return [
     6        $fields = [
    87            'enabled' => [
    98                'title'       => esc_html__('Enable/Disable', $payment_method . '-wc'),
     
    3635                'default'     => esc_html__('Pay with online banking Maybank2u, CIMB Clicks, Bank Islam GO and more banks from Malaysia.'),
    3736            ],
    38 
    3937            'credentials' => [
    4038                'title'       => esc_html__('Credentials', $payment_method . '-wc'),
     
    6866                ],
    6967            ],
    70 
    7168            'miscellaneous' => [
    7269                'title'       => esc_html__('Miscellaneous', $payment_method . '-wc'),
     
    9693                'title'       => 'Debug Mode',
    9794                'type'        => 'checkbox',
    98                 'label'       => esc_html__('Enable debug mode', $payment_method . '-wc'),
     95                'label'       => esc_html__('Enable debug mode', $payment_method . '-wc'),
    9996                'default'     => '0',
    10097                'desc_tip'    => true,
     
    120117                'placeholder' => esc_html__('This is the text for place order button', $payment_method . '-wc'),
    121118            ],
     119        ];
    122120
     121        // DuitNow QR Setting under Miscellaneous
     122        if (in_array($payment_method, ['duitnowshopee', 'duitnowboost'])) {
     123            $fields['duitnow_qr_setting'] = [
     124                'title'       => esc_html__('DuitNow QR Setting', $payment_method . '-wc'),
     125                'type'        => 'title',
     126                'description' => esc_html__('Settings specific to DuitNow Shopee and DuitNow Boost', $payment_method . '-wc'),
     127            ];
     128            $fields['enable_logo_on_catalog'] = [
     129                'title'       => esc_html__('Enable Logo on Catalog', $payment_method . '-wc'),
     130                'type'        => 'checkbox',
     131                'label'       => esc_html__('Display the logo on the product catalog', $payment_method . '-wc'),
     132                'description' => esc_html__('Enable this to show the payment method logo on the product catalog pages.', $payment_method . '-wc'),
     133                'desc_tip'    => true,
     134                'default'     => 'no',
     135            ];
     136        }
     137
     138        return array_merge($fields, [
    123139            'additional_charges' => [
    124140                'title'       => esc_html__('Additional Charges', $payment_method . '-wc'),
     
    140156                    'fixed'     => esc_html__('Fixed Fee', $payment_method . '-wc'),
    141157                    'percentage' => esc_html__('Percentage', $payment_method . '-wc'),
     158                    'both'      => esc_html__('Both', $payment_method . '-wc'),
    142159                ],
    143160                'description' => esc_html__('Select the type of additional charge', $payment_method . '-wc'),
     
    147164            'additional_charge_amount' => [
    148165                'title'       => esc_html__('Charge Amount', $payment_method . '-wc'),
    149                 'type'        => 'number',
     166                'type'        => 'text',
    150167                'description' => esc_html__('Enter the amount for the additional charge. For fixed fee, enter the amount in RM. For percentage, enter the percentage value (e.g., 8 for 8%)', $payment_method . '-wc'),
    151168                'default'     => '1',
    152169            ],
    153         ];
     170            'additional_charge_percentage' => [
     171                'title'       => esc_html__('Additional Percentage Charge (%)', $payment_method . '-wc'),
     172                'type'        => 'text',
     173                'description' => esc_html__('Enter the percentage value for the additional charge (e.g., 8 for 8%). This is used when charge type is set to "Both" only.', $payment_method . '-wc'),
     174                'default'     => '0',
     175                'custom_attributes' => [
     176                    'data-show-if-additional_charge_type' => 'both',
     177                ],
     178            ],
     179        ]);
    154180    }
    155181
  • bayarcash-wc/trunk/includes/src/Bayarcash.php

    r3165859 r3169110  
    242242        $this->register_admin_hooks();
    243243        $this->register_cronjob();
    244         $this->register_subscription_cancellation_hooks();
    245         $this->init_order_cancellation_prevention();
    246         $this->init_checkout_fee();
    247         $this->init_custom_field_funnelkit();
    248     }
    249 
    250     private function init_checkout_fee(): void
     244        $this->register_subscription_cancellation_hooks();
     245        $this->init_features();
     246    }
     247
     248    private function init_features(): void
    251249    {
    252250        new BayarcashCheckoutFee();
    253     }
    254 
    255     private function init_order_cancellation_prevention(): void
    256     {
    257251        new OrderCancellationPrevention();
    258     }
    259 
    260     private function init_custom_field_funnelkit(): void
    261     {
    262252        new CustomFieldFunnelKit();
     253        new CustomProductText();
    263254    }
    264255
  • bayarcash-wc/trunk/includes/src/BayarcashCheckoutFee.php

    r3165859 r3169110  
    44class BayarcashCheckoutFee {
    55    private array $payment_methods;
     6    private const DISABLE_GATEWAY_ID = 'duitnowshopee-wc';
     7    private const DISABLE_MESSAGE = '<div class="woocommerce-error">SPayLater can only be used for orders up to RM 1000.</div>';
     8    private const CHECKOUT_ERROR_MESSAGE = 'There was an error processing your order using SPayLater. The order total exceeds the RM 1000 limit for this payment method. Please choose a different payment method or reduce your order total.';
    69
    710    public function __construct() {
     
    2326        add_action('woocommerce_cart_calculate_fees', [$this, 'add_checkout_fee']);
    2427        add_filter('woocommerce_available_payment_gateways', [$this, 'disable_gateway_by_country']);
     28        add_filter('woocommerce_available_payment_gateways', [$this, 'disable_duitnowshopee_over_limit']);
     29        add_action('wp_footer', [$this, 'disable_checkout_button_for_payment_method']);
     30        add_action('woocommerce_before_checkout_process', [$this, 'check_payment_method_before_processing']);
     31        add_filter('woocommerce_checkout_error_message', [$this, 'custom_checkout_error_message'], 10, 2);
    2532    }
    2633
     
    2936            return;
    3037        }
    31 
    3238        $chosen_payment_method = WC()->session->get('chosen_payment_method');
    33 
    3439        if (!$this->is_bayarcash_payment_method($chosen_payment_method)) {
    3540            return;
    3641        }
    37 
    3842        $settings = get_option('woocommerce_' . $chosen_payment_method . '_settings', []);
    39 
    40         // Extract only fee-related settings
     43        // Extract fee-related settings
    4144        $fee_settings = [
    4245            'enable_additional_charges' => $settings['enable_additional_charges'] ?? 'no',
    4346            'additional_charge_type' => $settings['additional_charge_type'] ?? '',
    4447            'additional_charge_amount' => $settings['additional_charge_amount'] ?? '',
     48            'additional_charge_percentage' => $settings['additional_charge_percentage'] ?? '',
    4549        ];
    46 
    4750        if ($fee_settings['enable_additional_charges'] !== 'yes') {
    4851            return;
    4952        }
    50 
    5153        if (empty($fee_settings['additional_charge_type']) || empty($fee_settings['additional_charge_amount'])) {
    5254            return;
    5355        }
    54 
    5556        $charge_type = $fee_settings['additional_charge_type'];
    5657        $charge_amount = floatval($fee_settings['additional_charge_amount']);
     58        $charge_percentage = floatval($fee_settings['additional_charge_percentage']);
    5759
    58         if ($charge_amount <= 0) {
     60        if ($charge_amount <= 0 && $charge_percentage <= 0) {
    5961            return;
    6062        }
    6163
    6264        $cart_total = $cart->get_subtotal() + $cart->get_shipping_total();
     65        $fee = 0;
     66        $fee_label = '';
    6367
    64         if ($charge_type === 'fixed') {
    65             $fee = $charge_amount;
    66             $fee_label = __('Bayarcash Processing Fee (RM)', 'bayarcash-wc');
    67         } else { // percentage
    68             $fee = ($cart_total * $charge_amount) / 100;
    69             $fee_label = sprintf(__('Bayarcash Processing Fee (%s%%)', 'bayarcash-wc'), $charge_amount);
     68        switch ($charge_type) {
     69            case 'fixed':
     70                $fee = $charge_amount;
     71                $fee_label = sprintf(__('Bayarcash Processing Fee (RM %s)', 'bayarcash-wc'), number_format($charge_amount, 2));
     72                break;
     73            case 'percentage':
     74                $fee = ($cart_total * $charge_amount) / 100;
     75                $fee_label = sprintf(__('Bayarcash Processing Fee (%s%%)', 'bayarcash-wc'), $charge_amount);
     76                break;
     77            case 'both':
     78                $fixed_fee = $charge_amount;
     79                $percentage_fee = ($cart_total * $charge_percentage) / 100;
     80                $fee = $fixed_fee + $percentage_fee;
     81                $fee_label = sprintf(__('Bayarcash Processing Fee (RM %s + %s%%)', 'bayarcash-wc'), number_format($charge_amount, 2), $charge_percentage);
     82                break;
    7083        }
    7184
    72         $cart->add_fee($fee_label, $fee);
     85        if ($fee > 0) {
     86            $cart->add_fee($fee_label, $fee);
     87        }
    7388    }
    7489
     
    7792            return $available_gateways;
    7893        }
    79 
    8094        if (!WC()->customer) {
    8195            return $available_gateways;
    8296        }
    83 
    8497        $customer_country = WC()->customer->get_billing_country();
    85 
    8698        foreach ($this->payment_methods as $method) {
    8799            if (isset($available_gateways[$method])) {
    88100                $settings = get_option('woocommerce_' . $method . '_settings', []);
    89101                $enabled_country = $settings['enabled_country'] ?? '';
    90 
    91102                // Show for all countries if 'ALL' is selected or if enabled_country is empty
    92103                if ($enabled_country === 'ALL' || empty($enabled_country)) {
    93104                    continue;
    94105                }
    95 
    96106                if ($customer_country !== $enabled_country) {
    97107                    unset($available_gateways[$method]);
     
    99109            }
    100110        }
     111        return $available_gateways;
     112    }
     113
     114    public function disable_duitnowshopee_over_limit($available_gateways) {
     115        if (is_admin() || !is_checkout()) {
     116            return $available_gateways;
     117        }
     118
     119        $cart_total = WC()->cart->get_total('edit');
     120
     121        if ($cart_total > 1000 && isset($available_gateways[self::DISABLE_GATEWAY_ID])) {
     122            // Disable the payment method but still display it
     123            $available_gateways[self::DISABLE_GATEWAY_ID]->enabled = false;
     124            // Add custom message to the description
     125            $available_gateways[self::DISABLE_GATEWAY_ID]->description = self::DISABLE_MESSAGE . $available_gateways[self::DISABLE_GATEWAY_ID]->description;
     126        }
    101127
    102128        return $available_gateways;
     129    }
     130
     131    public function disable_checkout_button_for_payment_method() {
     132        if (is_checkout()) {
     133            ?>
     134            <script type="text/javascript">
     135                jQuery(document).ready(function($) {
     136                    // Continuously check for changes in payment method selection
     137                    $('form.checkout').on('change', 'input[name="payment_method"]', function() {
     138                        // Check if the disabled payment method is selected
     139                        if ($('input[name="payment_method"]:checked').val() === '<?php echo self::DISABLE_GATEWAY_ID; ?>') {
     140                            // Disable the place order button
     141                            $('#place_order').prop('disabled', true).css('opacity', '0.5');
     142                        } else {
     143                            // Enable the place order button if other methods are selected
     144                            $('#place_order').prop('disabled', false).css('opacity', '1');
     145                        }
     146                    });
     147                    // Trigger the change event on page load in case the method is already selected
     148                    $('input[name="payment_method"]:checked').trigger('change');
     149                });
     150            </script>
     151            <?php
     152        }
     153    }
     154
     155    public function check_payment_method_before_processing() {
     156        $chosen_payment_method = WC()->session->get('chosen_payment_method');
     157        $cart_total = WC()->cart->get_total('edit');
     158
     159        if ($chosen_payment_method === self::DISABLE_GATEWAY_ID && $cart_total > 1000) {
     160            wc_add_notice(self::CHECKOUT_ERROR_MESSAGE, 'error');
     161        }
     162    }
     163
     164    public function custom_checkout_error_message($error_message, $error_type) {
     165        if ($error_type === 'checkout') {
     166            $chosen_payment_method = WC()->session->get('chosen_payment_method');
     167            $cart_total = WC()->cart->get_total('edit');
     168
     169            if ($chosen_payment_method === self::DISABLE_GATEWAY_ID && $cart_total > 1000) {
     170                return self::CHECKOUT_ERROR_MESSAGE;
     171            }
     172        }
     173        return $error_message;
    103174    }
    104175
  • bayarcash-wc/trunk/includes/vendor/composer/autoload_classmap.php

    r3165859 r3169110  
    1212    'Bayarcash\\WooCommerce\\CronEvent' => $baseDir . '/includes/src/CronEvent.php',
    1313    'Bayarcash\\WooCommerce\\CustomFieldFunnelKit' => $baseDir . '/includes/src/CustomFieldFunnelKit.php',
     14    'Bayarcash\\WooCommerce\\CustomProductText' => $baseDir . '/includes/src/CustomProductText.php',
    1415    'Bayarcash\\WooCommerce\\DataRequest' => $baseDir . '/includes/src/DataRequest.php',
    1516    'Bayarcash\\WooCommerce\\DataStore' => $baseDir . '/includes/src/DataStore.php',
  • bayarcash-wc/trunk/includes/vendor/composer/autoload_static.php

    r3165859 r3169110  
    8383        'Bayarcash\\WooCommerce\\CronEvent' => __DIR__ . '/../../..' . '/includes/src/CronEvent.php',
    8484        'Bayarcash\\WooCommerce\\CustomFieldFunnelKit' => __DIR__ . '/../../..' . '/includes/src/CustomFieldFunnelKit.php',
     85        'Bayarcash\\WooCommerce\\CustomProductText' => __DIR__ . '/../../..' . '/includes/src/CustomProductText.php',
    8586        'Bayarcash\\WooCommerce\\DataRequest' => __DIR__ . '/../../..' . '/includes/src/DataRequest.php',
    8687        'Bayarcash\\WooCommerce\\DataStore' => __DIR__ . '/../../..' . '/includes/src/DataStore.php',
  • bayarcash-wc/trunk/includes/vendor/composer/installed.php

    r3165859 r3169110  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => 'b53376e690592061526a65ac1a5552619e3bf3c1',
     6        'reference' => 'e1aaf99e28972fbf73a3dbcfcf7ae36141eb64c4',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../../',
     
    1414            'pretty_version' => 'dev-master',
    1515            'version' => 'dev-master',
    16             'reference' => 'b53376e690592061526a65ac1a5552619e3bf3c1',
     16            'reference' => 'e1aaf99e28972fbf73a3dbcfcf7ae36141eb64c4',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../../',
  • bayarcash-wc/trunk/readme.txt

    r3168764 r3169110  
    55Tested up to: 6.6.1
    66Requires PHP: 7.4
    7 Stable tag: 4.2.4
     7Stable tag: 4.2.5
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.txt
     
    8383
    8484== Changelog ==
     85
     86= 4.2.5 =
     87* Gateway Fees: Added option to combine flat rate and percentage
     88* Buy Now, Pay Later (BNPL): New promotional label on catalog and product pages
     89* SPayLater: Added warning for orders over RM 1,000
    8590
    8691= 4.2.4 =
Note: See TracChangeset for help on using the changeset viewer.