Changeset 3398568
- Timestamp:
- 11/19/2025 07:05:51 AM (5 months ago)
- Location:
- gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk
- Files:
-
- 3 edited
-
grconnect.php (modified) (4 diffs)
-
includes/grwoo-api.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/grconnect.php
r3386951 r3398568 3 3 /** 4 4 * @package Gratisfaction Connect 5 * @version 4.5. 25 * @version 4.5.3 6 6 */ 7 7 /* … … 9 9 Plugin URI: http://appsmav.com 10 10 Description: Loyalty + Referral + Rewards + Birthdays and Anniversaries + Giveaways + Sweepstakes. 11 Version: 4.5. 211 Version: 4.5.3 12 12 Author: Appsmav 13 13 Author URI: http://appsmav.com … … 47 47 const REDEEM_COUPON = 'GRPAYPOINTS'; 48 48 49 public static $_plugin_version = '4.5. 2';49 public static $_plugin_version = '4.5.3'; 50 50 public static $_callback_url = 'https://gratisfaction.appsmav.com/'; 51 51 public static $_api_version = 'newapi/v2/'; … … 103 103 // Check if our plugin was updated 104 104 $plugin_path = plugin_basename(__FILE__); 105 if (i n_array($plugin_path, $options['plugins'], true)) {105 if (isset($options['plugins']) && is_array($options['plugins']) && in_array($plugin_path, $options['plugins'], true)) { 106 106 107 107 // Safely get plugin data -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-api.php
r3386951 r3398568 196 196 'permission_callback' => array($this, 'check_api_permission'), 197 197 '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() 198 205 )); 199 206 } … … 1379 1386 1380 1387 if(empty($_POST['cpn_type']) || empty($_POST['grcpn_code'])) 1381 throw new Exception('InvalidRequest 1');1388 throw new Exception('InvalidRequest'); 1382 1389 1383 1390 if(!isset($_POST['cpn_value']) || !isset($_POST['free_ship']) || !isset($_POST['min_order']) || !isset($_POST['cpn_descp'])) 1384 throw new Exception('InvalidRequest 2');1391 throw new Exception('InvalidRequest'); 1385 1392 1386 1393 if(!class_exists('WC_Integration')) … … 1571 1578 1572 1579 /** 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 /** 1573 1682 * Safe JSON decode with error handling 1574 1683 * … … 1583 1692 $decoded = json_decode($json_string, true); 1584 1693 1585 if (json_last_error() !== JSON_ERROR_NONE) { 1694 if (json_last_error() !== JSON_ERROR_NONE) { 1586 1695 return array(); 1587 1696 } -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/readme.txt
r3388643 r3398568 5 5 Requires at least: 3.0.1 6 6 Tested up to: 6.8 7 Stable tag: 4.5. 27 Stable tag: 4.5.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 254 254 255 255 == Changelog == 256 = 4.5.3 = 257 Improvements and bug fixes 258 256 259 = 4.5.2 = 257 260 PHP version 8.4 release compatibility … … 620 623 621 624 == Upgrade Notice == 622 = 4.5. 2=623 PHP version 8.4 release compatibility 625 = 4.5.3 = 626 Improvements and bug fixes
Note: See TracChangeset
for help on using the changeset viewer.