Plugin Directory

Changeset 3163614


Ignore:
Timestamp:
10/06/2024 02:58:37 PM (17 months ago)
Author:
squarewoosync
Message:

Google pay hotfix

Location:
squarewoosync
Files:
109 added
5 edited

Legend:

Unmodified
Added
Removed
  • squarewoosync/trunk/includes/Payments/WC_SquareSync_Gateway.php

    r3163070 r3163614  
    10211021            $order = wc_get_order($order_id);
    10221022            $settings = get_option('square-woo-sync_settings', []);
    1023 
     1023   
    10241024            // Sanitize and validate token
    10251025            $token = sanitize_text_field($_POST['wc-squaresync_credit-payment-nonce'] ?? $_POST['square_payment_token'] ?? '');
    1026 
     1026   
    10271027            if (empty($token)) {
    10281028                return $this->handle_error($order_id, 'Payment token is missing.');
    10291029            }
    1030 
     1030   
    10311031            $squareHelper = new SquareHelper();
    10321032            $ordersController = new OrdersController();
    10331033            $total_amount = intval(round($order->get_total() * 100));
    1034             error_log($total_amount);
    10351034            $currency = $order->get_currency();
    1036 
     1035   
    10371036            // Retrieve or create the Square customer ID, log warning if missing but continue
    10381037            $square_customer_id = $ordersController->getOrCreateSquareCustomer($order, $squareHelper);
     
    10401039                error_log("Warning: Square customer ID not available for Order ID: $order_id.");
    10411040            }
    1042 
     1041   
    10431042            // Prepare and attempt to create the Square order, log warning if failed but continue
    10441043            $square_order_response = $this->attempt_create_square_order($ordersController, $order, $square_customer_id, $squareHelper, $order_id);
     
    10461045                error_log("Warning: Square order could not be created for Order ID: $order_id.");
    10471046            }
    1048 
     1047   
    10491048            $this->check_net_amount_due($square_order_response, $total_amount, $currency, $order_id);
    1050 
    1051             // Prepare payment data
     1049   
     1050            // Prepare payment data and check if 'order_id' is included
    10521051            $payment_data = $this->prepare_payment_data($token, $order_id, $total_amount, $currency, $square_customer_id, $settings['location'], $square_order_response);
    1053 
     1052            $is_order_included = isset($payment_data['order_id']);
     1053   
    10541054            // Check for verification token and add to payment data if it exists
    10551055            if (!empty($_POST['square_verification_token'])) {
     
    10571057                $payment_data['verification_token'] = $verification_token;
    10581058            }
    1059 
    1060             // Process the payment
    1061             $payment_response = $squareHelper->square_api_request("/payments", 'POST', $payment_data);
    1062 
     1059   
     1060            // First payment attempt with order ID (if included)
     1061            $payment_response = $squareHelper->square_api_request("/payments", 'POST', $payment_data, null, false);
     1062   
     1063            // Retry without order ID if payment fails and order ID was included
     1064            if (!$this->validate_payment_response($payment_response, $order_id) && $is_order_included) {
     1065                // Remove order_id from payment data and try again
     1066                unset($payment_data['order_id']);
     1067                $payment_response = $squareHelper->square_api_request("/payments", 'POST', $payment_data, null, false);
     1068   
     1069                // If the second attempt also fails, return the error
     1070                if (!$this->validate_payment_response($payment_response, $order_id)) {
     1071                    // Extract the error message from the Square response.
     1072                    $error_message = 'Square payment failed.';
     1073                    if (isset($payment_response['error'])) {
     1074                        $error_message = $payment_response['error'];
     1075                    }
     1076   
     1077                    // Pass the extracted error message to the handle_error method.
     1078                    return $this->handle_error($order_id, $error_message);
     1079                }
     1080            }
     1081           
    10631082            if (!$this->validate_payment_response($payment_response, $order_id)) {
    1064                 // Extract the error message from the Square response.
    1065                 $error_message = 'Square payment failed.';  // Default error message.
     1083                // If no order ID was included initially and payment failed, return the error directly
     1084                $error_message = 'Square payment failed without order ID.';
    10661085                if (isset($payment_response['error'])) {
    10671086                    $error_message = $payment_response['error'];
    10681087                }
    1069 
    1070                 // Pass the extracted error message to the handle_error method.
     1088       
     1089                // Pass the extracted error message to the handle_error method
    10711090                return $this->handle_error($order_id, $error_message);
    10721091            }
    1073 
     1092   
    10741093            // Finalize the payment and update order status
    10751094            $this->finalize_order_payment($order, $payment_response, $square_order_response, $total_amount);
    1076 
     1095   
    10771096            // Clear the cart and return success
    10781097            WC()->cart->empty_cart();
    1079 
     1098   
    10801099            unset($token);
    10811100            unset($_POST);
    1082 
     1101   
    10831102            return ['result' => 'success', 'redirect' => $this->get_return_url($order)];
    10841103        } catch (\Exception $e) {
  • squarewoosync/trunk/languages/square-woo-sync.pot

    r3163070 r3163614  
    22msgid ""
    33msgstr ""
    4 "Project-Id-Version: Square Sync for Woocommerce 5.0.0\n"
     4"Project-Id-Version: Square Sync for Woocommerce 5.0.1\n"
    55"Report-Msgid-Bugs-To: https://github.com/LiamHillier/square-woo-sync/issues\n"
    66"Last-Translator: liam@pixeldev.com.au\n"
     
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "POT-Creation-Date: 2024-10-05T17:55:18+10:00\n"
     11"POT-Creation-Date: 2024-10-07T01:50:16+11:00\n"
    1212"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1313"X-Generator: WP-CLI 2.10.0\n"
  • squarewoosync/trunk/readme.txt

    r3163075 r3163614  
    55Tested up to: 6.6
    66Requires PHP: 7.4
    7 Stable tag: 5.0.0
     7Stable tag: 5.0.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    158158
    159159== Changelog ==
     160= 5.0.1 =
     161* Google pay hotfix
     162
    160163= 5.0.0 =
    161 Integrate Square Payments
     164* Integrate Square Payments
    162165
    163166= 4.0.0 =
  • squarewoosync/trunk/squarewoosync.php

    r3163070 r3163614  
    1212 * License URI:     http://www.gnu.org/licenses/gpl-2.0.html
    1313 * Domain Path:     /languages
    14  * Version:         5.0.0
     14 * Version:         5.0.1
    1515 * Requires at least: 5.4
    1616 * Requires PHP:      7.4
     
    2525final class SquareWooSync
    2626{
    27     const VERSION = '5.0.0';
     27    const VERSION = '5.0.1';
    2828    const SLUG = 'squarewoosync';
    2929
  • squarewoosync/trunk/vendor/composer/installed.php

    r3163070 r3163614  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => 'b4e741f77f0f7945069c52415afaecefdfd07536',
     6        'reference' => '04b8ce966399f3fc1ce9c85e62e8ff49e1bc2d1d',
    77        'type' => 'project',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => 'b4e741f77f0f7945069c52415afaecefdfd07536',
     16            'reference' => '04b8ce966399f3fc1ce9c85e62e8ff49e1bc2d1d',
    1717            'type' => 'project',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.