Plugin Directory

Changeset 3421433


Ignore:
Timestamp:
12/16/2025 10:17:36 PM (3 months ago)
Author:
peachpay
Message:

1.119.5

Location:
peachpay-for-woocommerce
Files:
918 added
6 edited

Legend:

Unmodified
Added
Removed
  • peachpay-for-woocommerce/trunk/changelog.txt

    r3418615 r3421433  
    11*** PeachPay for WooCommerce Changelog ***
     2
     32025-12-16 - version 1.119.5
     4* CPay: Move from using $(document.body) to triggerHandler()
    25
    362025-12-13 - version 1.119.2
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/assets/js/checkout.js

    r3418397 r3421433  
    443443    $(document).on('change', 'input[name="payment_method"]', function() {
    444444        if ($(this).val() === 'peachpay_convesiopay_card') {
    445             // Add transaction ID immediately to prevent race condition
    446             addTransactionIdToPaymentData('convesio-tx-' + Date.now());
    447445            // Create transaction immediately when payment method is selected
    448446            createPeachPayTransaction();
     
    453451    // Initialize if ConvesioPay is already selected
    454452    if ($('input[name="payment_method"][value="peachpay_convesiopay_card"]').is(':checked')) {
    455         // Add transaction ID immediately to prevent race condition
    456         addTransactionIdToPaymentData('convesio-tx-' + Date.now());
    457453        createPeachPayTransaction();
    458454        setTimeout(initConvesioPayComponent, 1000);
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/assets/js/convesiopay-unified-classic.js

    r3418615 r3421433  
    244244        $convesioPayRadio.on('change', function() {
    245245            if ($(this).is(':checked')) {
    246                 addHiddenField('peachpay_transaction_id', 'convesio-tx-' + Date.now());
    247246                setTimeout(initConvesioPayComponent, 100);
    248247                // Disable button initially until payment methods are confirmed available
     
    256255        // Initialize immediately if already selected
    257256        if ($convesioPayRadio.is(':checked')) {
    258             addHiddenField('peachpay_transaction_id', 'convesio-tx-' + Date.now());
    259257            setTimeout(initConvesioPayComponent, 100);
    260258            // Disable button initially until payment methods are confirmed available
     
    267265        });
    268266
    269         // Handle checkout form submission (register on document.body to match trigger)
    270         $(document.body).on('checkout_place_order_peachpay_convesiopay_unified', handleCheckoutSubmission);
     267        // CRITICAL FIX: Bind directly to form.checkout, NOT document.body
     268        // WooCommerce uses triggerHandler() for checkout_place_order events, which does NOT bubble!
     269        // Events triggered with triggerHandler() only fire on the exact element they're bound to.
     270        // Using $(document.body).on() would never catch these events.
     271       
     272        // Use namespaced events (.convesiopay) and unbind before binding to prevent duplicate handlers
     273        // when initConvesioPayClassic is called multiple times (e.g., after updated_checkout)
     274        $('form.checkout')
     275            .off('checkout_place_order_peachpay_convesiopay_unified.convesiopay')
     276            .on('checkout_place_order_peachpay_convesiopay_unified.convesiopay', handleCheckoutSubmission);
     277       
     278        // Hook into the general checkout_place_order event (fires BEFORE payment-specific event)
     279        // This ensures payment data is added before WooCommerce serializes the form
     280        $('form.checkout')
     281            .off('checkout_place_order.convesiopay')
     282            .on('checkout_place_order.convesiopay', function() {
     283                const $selectedPayment = $('input[name="payment_method"]:checked');
     284                if ($selectedPayment.val() === 'peachpay_convesiopay_unified') {
     285                    // Ensure form fields are present before any form serialization
     286                    addPaymentDataToForm();
     287                }
     288                return true; // Allow checkout to continue
     289            });
    271290       
    272291        // Fallback: Also listen for form submission to ensure transaction ID is added
    273         $('form.checkout').on('submit', function(e) {
    274             const $selectedPayment = $('input[name="payment_method"]:checked');
    275             if ($selectedPayment.val() === 'peachpay_convesiopay_unified') {
    276                 addPaymentDataToForm();
    277             }
    278         });
     292        $('form.checkout')
     293            .off('submit.convesiopay')
     294            .on('submit.convesiopay', function(e) {
     295                const $selectedPayment = $('input[name="payment_method"]:checked');
     296                if ($selectedPayment.val() === 'peachpay_convesiopay_unified') {
     297                    addPaymentDataToForm();
     298                }
     299            });
    279300    }
    280301
     
    694715        storePaymentTokenUnified(token);
    695716
     717        // CRITICAL: Add payment data to form IMMEDIATELY after setting paymentConfirmedData
     718        // This ensures the hidden fields are present BEFORE WooCommerce serializes the form
     719        // on the first checkout attempt (fixes race condition where fields were only added
     720        // during checkout_place_order event which is too late - form is already serialized)
     721        addPaymentDataToForm();
     722
    696723        // Component is valid, enable checkout (exactly like blocks version enableSubmitButton)
    697724        enableSubmitButtonUnified();
     
    11531180    function addHiddenField(name, value) {
    11541181        const $form = $('form.checkout');
     1182       
     1183        if (!$form.length) {
     1184            // Fallback: try to find the form by other selectors (for Elementor compatibility)
     1185            const $altForm = $('form.woocommerce-checkout, form[name="checkout"]');
     1186            if ($altForm.length) {
     1187                $altForm.find('input[name="' + name + '"]').remove();
     1188                $('<input>')
     1189                    .attr('type', 'hidden')
     1190                    .attr('name', name)
     1191                    .attr('value', value)
     1192                    .prependTo($altForm);
     1193                return;
     1194            }
     1195            return;
     1196        }
    11551197
    11561198        // Remove existing field if present
    11571199        $form.find('input[name="' + name + '"]').remove();
    11581200
    1159         // Add new hidden field
     1201        // CRITICAL: Use prependTo instead of appendTo
     1202        // Prepending ensures the field is at the beginning of the form,
     1203        // making it less likely to be removed by WooCommerce partial re-renders
     1204        // which typically replace content sections further down in the form
    11601205        $('<input>')
    11611206            .attr('type', 'hidden')
    11621207            .attr('name', name)
    11631208            .attr('value', value)
    1164             .appendTo($form);
     1209            .prependTo($form);
    11651210    }
    11661211
     
    18691914
    18701915    $(document.body).on('updated_checkout', function() {
     1916        // CRITICAL FIX: Save current payment data before reset
     1917        // When WooCommerce re-renders the checkout, the hidden fields are removed from the DOM.
     1918        // We need to preserve the payment data and re-add the fields after the checkout is updated.
     1919        const savedPaymentData = paymentConfirmedData;
     1920        const savedPaymentMethod = currentPaymentMethod;
     1921        const savedToken = window.convesiopayPaymentToken;
     1922       
    18711923        resetSessionState();
     1924       
     1925        // If we had valid payment data with a token, restore it and re-add form fields
     1926        // This ensures payment data persists across checkout updates (e.g., shipping method changes)
     1927        if (savedPaymentData && savedPaymentData.token) {
     1928            paymentConfirmedData = savedPaymentData;
     1929            currentPaymentMethod = savedPaymentMethod;
     1930            window.convesiopayPaymentToken = savedToken;
     1931           
     1932            // Re-add form fields after a short delay to ensure DOM is fully updated
     1933            setTimeout(function() {
     1934                addPaymentDataToForm();
     1935            }, 100);
     1936        }
     1937       
    18721938        setTimeout(initConvesioPayClassic, 500);
    18731939    });
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/gateways/class-peachpay-convesiopay-unified-gateway.php

    r3418615 r3421433  
    863863            plugins_url( 'core/payments/convesiopay/assets/js/convesiopay-unified-classic.js', PEACHPAY_PLUGIN_FILE ),
    864864            array( 'jquery', 'convesiopay-sdk' ),
    865             '1.0.6',
     865            '1.0.7', // Bumped version to force cache refresh for checkout fix
    866866            true
    867867        );
  • peachpay-for-woocommerce/trunk/peachpay.php

    r3418615 r3421433  
    44 * Plugin URI: https://woocommerce.com/products/peachpay
    55 * Description: Connect and manage all your payment methods, offer shoppers a beautiful Express Checkout, and reduce cart abandonment.
    6  * Version: 1.119.2
     6 * Version: 1.119.5
    77 * Text Domain: peachpay-for-woocommerce
    88 * Domain Path: /languages
  • peachpay-for-woocommerce/trunk/readme.txt

    r3418615 r3421433  
    44Requires at least: 5.8
    55Tested up to: 6.8.1
    6 Stable tag: 1.119.2
     6Stable tag: 1.119.5
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    262262
    263263== Changelog ==
     264
     265= 1.119.5 =
     266* CPay: Move from using $(document.body) to triggerHandler()
    264267
    265268= 1.119.2 =
Note: See TracChangeset for help on using the changeset viewer.