Plugin Directory

Changeset 3398568


Ignore:
Timestamp:
11/19/2025 07:05:51 AM (5 months ago)
Author:
akashmalik
Message:

Improvements and bug fixes

Location:
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/grconnect.php

    r3386951 r3398568  
    33/**
    44 * @package Gratisfaction Connect
    5  * @version 4.5.2
     5 * @version 4.5.3
    66 */
    77/*
     
    99  Plugin URI: http://appsmav.com
    1010  Description: Loyalty + Referral + Rewards + Birthdays and Anniversaries + Giveaways + Sweepstakes.
    11   Version: 4.5.2
     11  Version: 4.5.3
    1212  Author: Appsmav
    1313  Author URI: http://appsmav.com
     
    4747        const REDEEM_COUPON = 'GRPAYPOINTS';
    4848
    49         public static $_plugin_version  = '4.5.2';
     49        public static $_plugin_version  = '4.5.3';
    5050        public static $_callback_url = 'https://gratisfaction.appsmav.com/';
    5151        public static $_api_version  = 'newapi/v2/';
     
    103103                    // Check if our plugin was updated
    104104                    $plugin_path = plugin_basename(__FILE__);
    105                     if (in_array($plugin_path, $options['plugins'], true)) {
     105                    if (isset($options['plugins']) && is_array($options['plugins']) && in_array($plugin_path, $options['plugins'], true)) {
    106106
    107107                        // Safely get plugin data
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-api.php

    r3386951 r3398568  
    196196            'permission_callback'       =>  array($this, 'check_api_permission'),
    197197            'args'                      =>  array()
     198        ));
     199
     200        register_rest_route('grwoo/v1', '/updateCouponAttributes', array(
     201            'methods'               =>  'POST',
     202            'callback'              =>  array($this, 'update_coupon_attributes'),
     203            'permission_callback'   =>  array($this, 'check_api_permission'),
     204            'args'                  =>  array()
    198205        ));
    199206    }
     
    13791386
    13801387            if(empty($_POST['cpn_type']) || empty($_POST['grcpn_code']))
    1381                 throw new Exception('InvalidRequest1');
     1388                throw new Exception('InvalidRequest');
    13821389
    13831390            if(!isset($_POST['cpn_value']) || !isset($_POST['free_ship']) || !isset($_POST['min_order']) || !isset($_POST['cpn_descp']))
    1384                 throw new Exception('InvalidRequest2');
     1391                throw new Exception('InvalidRequest');
    13851392
    13861393            if(!class_exists('WC_Integration'))
     
    15711578
    15721579    /**
     1580     * Update coupon attributes including value, type, minimum amount and description
     1581     *
     1582     * @param WP_REST_Request $request Full data about the request
     1583     * @return WP_REST_Response
     1584     */
     1585    public function update_coupon_attributes($request)
     1586    {
     1587        try
     1588        {
     1589            $data['error'] = 0;
     1590
     1591            // Validate required parameters
     1592            if (empty($_POST['coupon_code'])) {
     1593                throw new Exception('Coupon code is required');
     1594            }
     1595
     1596            if (empty($_POST['coupon_type'])) {
     1597                throw new Exception('Coupon type is required');
     1598            }
     1599
     1600            if (!isset($_POST['coupon_value']) || !is_numeric($_POST['coupon_value'])) {
     1601                throw new Exception('Valid coupon value is required');
     1602            }
     1603
     1604            // Validate minimum amount before sanitization
     1605            if (!empty($_POST['min_order']) && !is_numeric($_POST['min_order'])) {
     1606                throw new Exception('Minimum amount must be a valid number');
     1607            }
     1608
     1609            $coupon_code = sanitize_text_field($_POST['coupon_code']);
     1610            $coupon_type = sanitize_text_field($_POST['coupon_type']);
     1611            $coupon_value = (float) wc_format_decimal($_POST['coupon_value']);
     1612            $minimum_amount = !empty($_POST['min_order']) ? (float) wc_format_decimal($_POST['min_order']) : 0;
     1613
     1614            // Additional validation for numeric value
     1615            if ($coupon_value <= 0) {
     1616                throw new Exception('Coupon value must be a positive number');
     1617            }
     1618
     1619            // Validate minimum amount
     1620            if ($minimum_amount < 0) {
     1621                throw new Exception('Minimum amount must be a positive number');
     1622            }
     1623
     1624            // Validate coupon type using WooCommerce function for future compatibility
     1625            if (!in_array($coupon_type, array_keys(wc_get_coupon_types()), true)) {
     1626                throw new Exception('Invalid coupon type. Allowed types: ' . implode(', ', array_keys(wc_get_coupon_types())));
     1627            }
     1628
     1629            // Additional validation for percent types
     1630            if (in_array($coupon_type, array('percent', 'percent_product'), true) && $coupon_value > 100) {
     1631                throw new Exception('Percent discount cannot exceed 100%');
     1632            }
     1633
     1634            // Get coupon by code
     1635            $coupon_id = wc_get_coupon_id_by_code($coupon_code);
     1636
     1637            if (!$coupon_id) {
     1638                throw new Exception('Coupon not found');
     1639            }
     1640
     1641            // Get the coupon object
     1642            $coupon = new WC_Coupon($coupon_id);
     1643
     1644            if (!$coupon || !$coupon->get_id()) {
     1645                throw new Exception('Invalid coupon');
     1646            }
     1647
     1648            // Use WooCommerce CRUD methods for better compatibility
     1649            $coupon->set_discount_type($coupon_type);
     1650            $coupon->set_amount($coupon_value);
     1651
     1652            // Update minimum amount if provided
     1653            $coupon->set_minimum_amount($minimum_amount);
     1654
     1655            // Save changes (automatically handles cache clearing)
     1656            $coupon->save();
     1657
     1658            $data['msg'] = 'Coupon updated successfully';
     1659            $data['coupon_code'] = $coupon_code;
     1660            $data['coupon_id'] = $coupon_id;
     1661            $data['type'] = $coupon_type;
     1662            $data['value'] = $coupon_value;
     1663
     1664            if (!empty($minimum_amount)) {
     1665                $data['minimum_amount'] = $minimum_amount;
     1666            }
     1667        }
     1668        catch(Exception $ex) {
     1669            $data['error'] = 1;
     1670            $data['msg'] = $ex->getMessage();
     1671        }
     1672
     1673        $data['plugin_version'] = GR_Connect::$_plugin_version;
     1674
     1675        $result = new WP_REST_Response($data, 200);
     1676        // Set headers.
     1677        $result->set_headers(array('Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0'));
     1678        return $result;
     1679    }
     1680
     1681    /**
    15731682     * Safe JSON decode with error handling
    15741683     *
     
    15831692        $decoded = json_decode($json_string, true);
    15841693       
    1585         if (json_last_error() !== JSON_ERROR_NONE) {           
     1694        if (json_last_error() !== JSON_ERROR_NONE) {
    15861695            return array();
    15871696        }
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/readme.txt

    r3388643 r3398568  
    55Requires at least: 3.0.1
    66Tested up to: 6.8
    7 Stable tag: 4.5.2
     7Stable tag: 4.5.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    254254
    255255== Changelog ==
     256= 4.5.3 =
     257Improvements and bug fixes
     258
    256259= 4.5.2 =
    257260PHP version 8.4 release compatibility
     
    620623
    621624== Upgrade Notice ==
    622 = 4.5.2 =
    623 PHP version 8.4 release compatibility
     625= 4.5.3 =
     626Improvements and bug fixes
Note: See TracChangeset for help on using the changeset viewer.