Plugin Directory

Changeset 3399128


Ignore:
Timestamp:
11/19/2025 04:35:24 PM (4 months ago)
Author:
peachpay
Message:

1.118.5

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

Legend:

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

    r3395317 r3399128  
    11*** PeachPay for WooCommerce Changelog ***
     2
     32025-11-19 - version 1.118.5
     4* CPay/BTCPay payment initialization fix
    25
    362025-11-13 - version 1.118.4
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/assets/js/convesiopay-unified-blocks.js

    r3395317 r3399128  
    2222    // Get active payment methods from settings
    2323    const activeMethods = settings.active_methods || [];
     24
     25    // Helper: determine if BTCPay/crypto is enabled according to the
     26    // unified gateway configuration. This is the client-side source of
     27    // truth for deciding whether any BTCPay sessions/intents should be
     28    // created.
     29    //
     30    // STRICT CHECK: Only returns true if 'crypto' is explicitly in active_methods,
     31    // which should only happen when the BTC Pay gateway is enabled in WooCommerce.
     32    const isBtcpayEnabled = () => {
     33        // Only return true if 'crypto' is explicitly in the array
     34        // This ensures BTC Pay is only enabled when the gateway is actually enabled
     35        const isEnabled = activeMethods.includes('crypto') || activeMethods.includes('btcpay');
     36       
     37        // Additional safety: if active_methods is empty or doesn't include crypto, BTC Pay is disabled
     38        if (activeMethods.length === 0) {
     39            return false;
     40        }
     41       
     42        return isEnabled;
     43    };
    2444
    2545    // Global state management
     
    573593     */
    574594    const setupBTCPayMessageListener = () => {
     595        // If BTCPay is disabled, do not attach any listeners.
     596        if (!isBtcpayEnabled()) {
     597            return;
     598        }
     599
    575600        window.addEventListener('message', (event) => {
    576601            // Verify the origin is from BTCPay
     
    835860            }
    836861
    837             // Step 6: Create BTCPay session and intent if it was previously active
    838             if (hadBtcPaySession) {
     862            // Step 6: Create BTCPay session and intent if it was previously active (only if BTC Pay is enabled)
     863            // GUARD: Only create BTC Pay session and intent if BTC Pay is enabled
     864            if (hadBtcPaySession && isBtcpayEnabled()) {
    839865                try {
    840 
    841866                    // Create new BTCPay session with updated amount
    842867                    const sessionResult = await createBTCPaySession();
    843868
    844                     if (sessionResult.success && sessionResult.session) {
     869                    // Only proceed if session creation was successful
     870                    // If disabled or failed, continue without BTC Pay session
     871                    if (sessionResult.success && sessionResult.session && !sessionResult.disabled) {
    845872                        // Update the global session variable
    846873                        btcPaySession = sessionResult.session;
     
    856883                        // Re-setup the message listener
    857884                        setupBTCPayMessageListener();
     885                    } else if (sessionResult.disabled) {
     886                        // BTC Pay is disabled - continue without BTC Pay session
     887                        // Component will work with Card and Apple Pay only
     888                    } else {
     889                        // Session creation failed but BTC Pay should be enabled
     890                        // Log error but continue - component will work without BTC Pay
     891                        console.warn('[ConvesioPay Blocks] BTCPay session creation failed during amount update:', sessionResult.message);
    858892                    }
    859893                } catch (btcPayError) {
    860                     // BTCPay session/intent recreation failed
    861                 }
     894                    // Silently fail if BTC Pay intent creation fails when BTC Pay is disabled
     895                    // Only log error if BTC Pay should be enabled
     896                    if (isBtcpayEnabled()) {
     897                        console.warn('[ConvesioPay Blocks] BTCPay session/intent recreation failed:', btcPayError);
     898                    }
     899                }
     900            } else if (hadBtcPaySession && !isBtcpayEnabled()) {
     901                // BTC Pay was previously active but is now disabled - skip session/intent creation
    862902            }
    863903
     
    10241064    /**
    10251065     * Create BTCPay session via AJAX call
     1066     *
     1067     * STRICT GUARD: Returns early with success:false (not an error) when disabled
     1068     * to prevent any error messages from being shown.
    10261069     */
    10271070    const createBTCPaySession = async () => {
     1071        // STRICT CHECK: Do not create BTCPay sessions when the method is disabled in
     1072        // PeachPay/WooCommerce settings. This prevents unnecessary
     1073        // ConvesioPay API calls and avoids leaking BTCPay behaviour
     1074        // into sites that have explicitly disabled crypto.
     1075        if (!isBtcpayEnabled()) {
     1076            // Return success:false with a message indicating it's disabled
     1077            // This is NOT an error - it's expected behavior when disabled
     1078            return { success: false, message: 'BTCPay payment method is disabled', disabled: true };
     1079        }
     1080
     1081        // If session already created and exists, return it
    10281082        if (isSessionCreated && btcPaySession) {
    10291083            return { success: true, session: btcPaySession };
     
    10631117           
    10641118            if (!sessionResponse.success || !sessionResponse.data?.session) {
    1065                 throw new Error(sessionResponse.message || 'Failed to create BTCPay session');
     1119                // Extract message from WordPress AJAX response structure
     1120                // WordPress error responses have message in data.message or directly in message
     1121                const errorMessage = sessionResponse.data?.message || sessionResponse.message || 'Failed to create BTCPay session';
     1122               
     1123                // Check if the error is because BTC Pay is disabled
     1124                const isDisabled = errorMessage.toLowerCase().includes('disabled') ||
     1125                                 errorMessage.toLowerCase().includes('btcpay payment method is disabled');
     1126               
     1127                // Return with disabled flag so error won't be shown
     1128                return {
     1129                    success: false,
     1130                    message: errorMessage,
     1131                    disabled: isDisabled
     1132                };
    10661133            }
    10671134           
     
    10731140           
    10741141        } catch (error) {
    1075             return { success: false, message: error.message };
     1142            // On error, check if BTC Pay is still enabled before reporting error
     1143            // If disabled, this is expected behavior
     1144            const isDisabled = !isBtcpayEnabled();
     1145            return {
     1146                success: false,
     1147                message: error.message,
     1148                disabled: isDisabled
     1149            };
    10761150        }
    10771151    };
     
    11311205                } else if (event.type === 'btcpay') {
    11321206                    // Handle BTCPay payments directly when event.type is btcpay
    1133                     handleBTCPayPayment(event);
     1207                    // GUARD: Only handle BTC Pay events if BTC Pay is enabled
     1208                    if (isBtcpayEnabled()) {
     1209                        handleBTCPayPayment(event);
     1210                    } else {
     1211                        // BTC Pay is disabled - ignore BTC Pay events
     1212                        console.warn('[ConvesioPay Blocks] Received BTC Pay event but BTC Pay is disabled');
     1213                    }
    11341214                } else if (event.type === 'applepay') {
    11351215                    // Handle ApplePay payments with auto-submit when successful
     
    11501230                        handleCardPayment(component, event);
    11511231                    } else if (paymentMethod === 'btcpay' && event.isValid === true && event.isSuccessful === true) {
    1152                         handleBTCPayPayment(event);
     1232                        // GUARD: Only handle BTC Pay payments if BTC Pay is enabled
     1233                        if (isBtcpayEnabled()) {
     1234                            handleBTCPayPayment(event);
     1235                        } else {
     1236                            // BTC Pay is disabled - ignore BTC Pay payment events
     1237                            console.warn('[ConvesioPay Blocks] Received BTC Pay payment but BTC Pay is disabled');
     1238                        }
    11531239                    } else if (paymentMethod === 'applepay' && event.isValid === true && event.isSuccessful === true) {
    11541240                        handleApplePayPayment(component, event);
     
    12981384
    12991385                // Create BTCPay intent using the mounted component (following BTCPay blocks pattern)
    1300                 // Include required address fields for ConvesioPay API
    1301                 await convesioPayComponent.createBTCPayIntent(btcPayIntentData);
    1302                
    1303                 // Set up postMessage listener for iframe communication
    1304                 setupBTCPayMessageListener();
    1305                
    1306                 // Check again after BTCPay intent is created
    1307                 setTimeout(() => {
    1308                     updateSubmitButtonState();
    1309                 }, 1000);
     1386                // Include required address fields for ConvesioPay API. Only do this
     1387                // when BTCPay is actually enabled for the site and we have a session.
     1388                // GUARD: Check if BTC Pay is enabled and we have a session before attempting to create intent
     1389                if (isBtcpayEnabled() && btcPaySession) {
     1390                    try {
     1391                        await convesioPayComponent.createBTCPayIntent(btcPayIntentData);
     1392                       
     1393                        // Set up postMessage listener for iframe communication
     1394                        setupBTCPayMessageListener();
     1395
     1396                        // Check again after BTCPay intent is created
     1397                        setTimeout(() => {
     1398                            updateSubmitButtonState();
     1399                        }, 1000);
     1400                    } catch (error) {
     1401                        // Silently fail if BTC Pay intent creation fails when BTC Pay is disabled
     1402                        // Only log error if BTC Pay should be enabled
     1403                        if (isBtcpayEnabled()) {
     1404                            console.error('[ConvesioPay Blocks] BTCPay intent creation failed:', error);
     1405                        }
     1406                    }
     1407                } else {
     1408                    // BTC Pay is disabled or no session - do not create intent or set up listeners
     1409                    // Component will work with Card and Apple Pay only
     1410                }
    13101411               
    13111412               
     
    13511452            // Disable submit button initially until payment methods are confirmed available
    13521453            disableSubmitButtonUnified();
     1454
     1455            // If BTCPay is disabled in the unified configuration, skip the
     1456            // BTCPay session entirely and just mount the component for
     1457            // card/Apple Pay.
     1458            if (!isBtcpayEnabled()) {
     1459                // BTC Pay is disabled - mount component without BTC Pay session
     1460                setTimeout(() => {
     1461                    mountConvesioPayComponent();
     1462                }, 100);
     1463                return;
     1464            }
    13531465           
    13541466            // Create BTCPay session immediately when radio button is selected
    1355             createBTCPaySession().then(sessionResult => {
    1356                 if (sessionResult.success) {
    1357                     // After session is created, mount the ConvesioPay component
     1467            // Only attempt session creation if BTC Pay is enabled
     1468            if (isBtcpayEnabled()) {
     1469                createBTCPaySession().then(sessionResult => {
     1470                    if (sessionResult.success) {
     1471                        // After session is created, mount the ConvesioPay component
     1472                        setTimeout(() => {
     1473                            mountConvesioPayComponent();
     1474                        }, 100); // Small delay to ensure DOM is ready
     1475                    } else {
     1476                        // BTC Pay session creation failed - mount component anyway so Card and Apple Pay can work
     1477                        // Only show a warning (not blocking error) if BTC Pay was supposed to be enabled
     1478                        // The component will work with Card and Apple Pay even without BTC Pay session
     1479                        if (sessionResult.disabled || sessionResult.message?.toLowerCase().includes('disabled')) {
     1480                            // BTC Pay is intentionally disabled - this is expected, don't log as error
     1481                            console.log('[ConvesioPay Blocks] BTC Pay is disabled, mounting component for Card/Apple Pay only');
     1482                        } else if (isBtcpayEnabled() && sessionResult.message && !sessionResult.disabled) {
     1483                            // BTC Pay session failed but it should be enabled - log warning but still mount
     1484                            console.warn('[ConvesioPay Blocks] BTC Pay session creation failed, but mounting component for Card/Apple Pay:', sessionResult.message);
     1485                        }
     1486                        // Always mount the component so Card and Apple Pay can work
     1487                        // BTC Pay will simply not be available if session creation failed
     1488                        setTimeout(() => {
     1489                            mountConvesioPayComponent();
     1490                        }, 100);
     1491                    }
     1492                }).catch(error => {
     1493                    // BTC Pay session creation error - mount component anyway so Card and Apple Pay can work
     1494                    // Log the error but don't block the component from mounting
     1495                    if (isBtcpayEnabled()) {
     1496                        console.warn('[ConvesioPay Blocks] BTC Pay session creation error, but mounting component for Card/Apple Pay:', error);
     1497                    }
     1498                    // Always mount the component so Card and Apple Pay can work
     1499                    // BTC Pay will simply not be available if session creation failed
    13581500                    setTimeout(() => {
    13591501                        mountConvesioPayComponent();
    1360                     }, 100); // Small delay to ensure DOM is ready
    1361                 } else {
    1362                     // Session creation failed, ensure button is disabled
    1363                     disableSubmitButtonUnified();
    1364                 }
    1365             }).catch(error => {
    1366                 // Error creating session, ensure button is disabled
    1367                 disableSubmitButtonUnified();
    1368             });
     1502                    }, 100);
     1503                });
     1504            } else {
     1505                // Double-check: if somehow we got here but BTC Pay is disabled, just mount
     1506                mountConvesioPayComponent();
     1507            }
    13691508        }, []);
    13701509
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/assets/js/convesiopay-unified-classic.js

    r3393772 r3399128  
    107107        const config = window.peachpay_convesiopay_unified_data || {};
    108108        return config;
     109    }
     110
     111    /**
     112     * Determine if BTCPay/crypto is enabled for this site based on the
     113     * unified gateway configuration. This is the client-side source of
     114     * truth for deciding whether any BTCPay sessions/intents should be
     115     * created.
     116     *
     117     * STRICT CHECK: Only returns true if 'crypto' is explicitly in active_methods,
     118     * which should only happen when the BTC Pay gateway is enabled in WooCommerce.
     119     */
     120    function isBtcpayEnabled() {
     121        const config = getConfig();
     122        const activeMethods = config.active_methods || [];
     123        // Only return true if 'crypto' is explicitly in the array
     124        // This ensures BTC Pay is only enabled when the gateway is actually enabled
     125        const isEnabled = activeMethods.includes('crypto') || activeMethods.includes('btcpay');
     126       
     127        // Additional safety: if active_methods is empty or doesn't include crypto, BTC Pay is disabled
     128        if (activeMethods.length === 0) {
     129            return false;
     130        }
     131       
     132        return isEnabled;
    109133    }
    110134
     
    280304        }
    281305
     306        // If BTCPay is disabled in the unified configuration, mount the
     307        // component for card/Apple Pay only and completely skip BTCPay
     308        // session creation. This avoids unnecessary API calls and
     309        // prevents the "Failed to create BTCPay session" error when
     310        // crypto is intentionally turned off.
     311        if (!isBtcpayEnabled()) {
     312            // BTC Pay is disabled - mount component without BTC Pay session
     313            mountConvesioPayComponent();
     314            return;
     315        }
     316
    282317        // Create BTCPay session first, then mount component (following blocks pattern)
    283         createBTCPaySession().then(sessionResult => {
    284             if (sessionResult.success) {
    285                 // After session is created, mount the ConvesioPay component
    286                 setTimeout(() => {
     318        // Only attempt session creation if BTC Pay is enabled
     319        if (isBtcpayEnabled()) {
     320            createBTCPaySession().then(sessionResult => {
     321                if (sessionResult.success) {
     322                    // After session is created, mount the ConvesioPay component
     323                    setTimeout(() => {
     324                        mountConvesioPayComponent();
     325                    }, 100);
     326                } else {
     327                    // BTC Pay session creation failed - mount component anyway so Card and Apple Pay can work
     328                    // Only show a warning (not blocking error) if BTC Pay was supposed to be enabled
     329                    // The component will work with Card and Apple Pay even without BTC Pay session
     330                    if (sessionResult.disabled || sessionResult.message?.toLowerCase().includes('disabled')) {
     331                        // BTC Pay is intentionally disabled - this is expected, don't log as error
     332                        console.log('[ConvesioPay Classic] BTC Pay is disabled, mounting component for Card/Apple Pay only');
     333                    } else if (isBtcpayEnabled() && sessionResult.message && !sessionResult.disabled) {
     334                        // BTC Pay session failed but it should be enabled - log warning but still mount
     335                        console.warn('[ConvesioPay Classic] BTC Pay session creation failed, but mounting component for Card/Apple Pay:', sessionResult.message);
     336                    }
     337                    // Always mount the component so Card and Apple Pay can work
     338                    // BTC Pay will simply not be available if session creation failed
    287339                    mountConvesioPayComponent();
    288                 }, 100);
    289             } else {
    290                 container.innerHTML = '<p style="color: red;">Failed to create payment session: ' + (sessionResult.message || 'Unknown error') + '</p>';
    291             }
    292         }).catch(error => {
    293             container.innerHTML = '<p style="color: red;">Failed to create payment session. Please refresh and try again.</p>';
    294         });
     340                }
     341            }).catch(error => {
     342                // BTC Pay session creation error - mount component anyway so Card and Apple Pay can work
     343                // Log the error but don't block the component from mounting
     344                if (isBtcpayEnabled()) {
     345                    console.warn('[ConvesioPay Classic] BTC Pay session creation error, but mounting component for Card/Apple Pay:', error);
     346                }
     347                // Always mount the component so Card and Apple Pay can work
     348                // BTC Pay will simply not be available if session creation failed
     349                mountConvesioPayComponent();
     350            });
     351        } else {
     352            // Double-check: if somehow we got here but BTC Pay is disabled, just mount
     353            mountConvesioPayComponent();
     354        }
    295355    }
    296356
     
    368428                } else if (event.type === 'btcpay') {
    369429                    // Handle BTCPay payments directly when event.type is btcpay
    370                     handleBTCPayPayment(event);
     430                    // GUARD: Only handle BTC Pay events if BTC Pay is enabled
     431                    if (isBtcpayEnabled()) {
     432                        handleBTCPayPayment(event);
     433                    } else {
     434                        // BTC Pay is disabled - ignore BTC Pay events
     435                        console.warn('[ConvesioPay Classic] Received BTC Pay event but BTC Pay is disabled');
     436                    }
    371437                } else if (event.type === 'applepay') {
    372438                    // Handle ApplePay payments with auto-submit when successful
     
    387453                        handleCardPayment(component, event);
    388454                    } else if (paymentMethod === 'btcpay' && event.isValid === true && event.isSuccessful === true) {
    389                         handleBTCPayPayment(event);
     455                        // GUARD: Only handle BTC Pay payments if BTC Pay is enabled
     456                        if (isBtcpayEnabled()) {
     457                            handleBTCPayPayment(event);
     458                        } else {
     459                            // BTC Pay is disabled - ignore BTC Pay payment events
     460                            console.warn('[ConvesioPay Classic] Received BTC Pay payment but BTC Pay is disabled');
     461                        }
    390462                    } else if (paymentMethod === 'applepay' && event.isValid === true && event.isSuccessful === true) {
    391463                        handleApplePayPayment(component, event);
     
    432504            }, 2500);
    433505
    434             // Create BTCPay intent using the mounted component (following blocks pattern)
    435             // const orderData = getOrderData();
    436             const btcPayIntentData = {
    437                 session: btcPaySession
    438             };
    439 
    440506            // Get order data
    441507            const orderData = getOrderData();
     
    446512                return;
    447513            }
     514           
     515            // Create Apple Pay session (always available when component is mounted)
    448516            const applePaySession = await component.createApplePaySession({
    449517                integration: integrationName,
     
    456524            });
    457525
    458             // Create BTCPay intent
    459             convesioPayComponent.createBTCPayIntent(btcPayIntentData);
    460 
    461             // Set up postMessage listener for iframe communication
    462             setupBTCPayMessageListener();
     526            // Only create BTCPay intent if BTC Pay is enabled and we have a session
     527            // GUARD: Check if BTC Pay is enabled before attempting to create intent
     528            if (isBtcpayEnabled() && btcPaySession) {
     529                try {
     530                    const btcPayIntentData = {
     531                        session: btcPaySession
     532                    };
     533                    // Create BTCPay intent using the mounted component (following blocks pattern)
     534                    convesioPayComponent.createBTCPayIntent(btcPayIntentData);
     535                   
     536                    // Set up postMessage listener for iframe communication
     537                    setupBTCPayMessageListener();
     538                } catch (error) {
     539                    // Silently fail if BTC Pay intent creation fails when BTC Pay is disabled
     540                    // Only log error if BTC Pay should be enabled
     541                    if (isBtcpayEnabled()) {
     542                        console.error('[ConvesioPay Classic] BTCPay intent creation failed:', error);
     543                    }
     544                }
     545            } else {
     546                // BTC Pay is disabled - do not create intent or set up listeners
     547                // Component will work with Card and Apple Pay only
     548            }
    463549           
    464550            // Check again after BTCPay intent is created
     
    12091295            btcPaySession = null;
    12101296
    1211             // Step 3: Create new BTCPay session with updated amount
    1212             const sessionResult = await createBTCPaySession();
    1213 
    1214             if (!sessionResult.success) {
    1215                 return;
    1216             }
    1217 
    1218             btcPaySession = sessionResult.session;
     1297            // Step 3: Create new BTCPay session with updated amount (only if BTC Pay is enabled)
     1298            // GUARD: Only create BTC Pay session if BTC Pay is enabled
     1299            if (isBtcpayEnabled()) {
     1300                const sessionResult = await createBTCPaySession();
     1301
     1302                // Only proceed if session creation was successful
     1303                // If disabled or failed, continue without BTC Pay session
     1304                if (sessionResult.success && !sessionResult.disabled) {
     1305                    btcPaySession = sessionResult.session;
     1306                } else if (sessionResult.disabled) {
     1307                    // BTC Pay is disabled - continue without BTC Pay session
     1308                    // Component will work with Card and Apple Pay only
     1309                } else {
     1310                    // Session creation failed but BTC Pay should be enabled
     1311                    // Log error but continue - component will work without BTC Pay
     1312                    console.warn('[ConvesioPay Classic] BTCPay session creation failed during amount update:', sessionResult.message);
     1313                }
     1314            } else {
     1315                // BTC Pay is disabled - skip session creation
     1316            }
    12191317
    12201318            // Step 4: Create and mount new component
     
    12491347            }
    12501348
    1251             // Step 7: Create BTCPay intent with new session
    1252             try {
    1253 
    1254                 // Prepare BTCPay intent data
    1255                 const btcPayIntentData = {
    1256                     session: btcPaySession
    1257                 };
    1258 
    1259                 // Create the BTCPay intent with the new session
    1260                 await convesioPayComponent.createBTCPayIntent(btcPayIntentData);
    1261 
    1262                 // Re-setup the message listener
    1263                 setupBTCPayMessageListener();
    1264             } catch (btcPayError) {
    1265                 // BTCPay intent creation failed
     1349            // Step 7: Create BTCPay intent with new session (only if BTC Pay is enabled and session exists)
     1350            // GUARD: Only create BTC Pay intent if BTC Pay is enabled and we have a session
     1351            if (isBtcpayEnabled() && btcPaySession) {
     1352                try {
     1353                    // Prepare BTCPay intent data
     1354                    const btcPayIntentData = {
     1355                        session: btcPaySession
     1356                    };
     1357
     1358                    // Create the BTCPay intent with the new session
     1359                    await convesioPayComponent.createBTCPayIntent(btcPayIntentData);
     1360
     1361                    // Re-setup the message listener
     1362                    setupBTCPayMessageListener();
     1363                } catch (btcPayError) {
     1364                    // Silently fail if BTC Pay intent creation fails when BTC Pay is disabled
     1365                    // Only log error if BTC Pay should be enabled
     1366                    if (isBtcpayEnabled()) {
     1367                        console.warn('[ConvesioPay Classic] BTCPay intent creation failed during amount update:', btcPayError);
     1368                    }
     1369                }
     1370            } else {
     1371                // BTC Pay is disabled or no session - skip intent creation
    12661372            }
    12671373
     
    14321538    /**
    14331539     * Create BTCPay session via AJAX call (following blocks pattern)
     1540     *
     1541     * STRICT GUARD: Returns early with success:false (not an error) when disabled
     1542     * to prevent any error messages from being shown.
    14341543     */
    14351544    function createBTCPaySession() {
     1545        // STRICT CHECK: Do not create BTCPay sessions when the method is disabled in
     1546        // PeachPay/WooCommerce settings. This prevents unnecessary
     1547        // ConvesioPay API calls and avoids BTCPay behaviour on sites
     1548        // that have explicitly disabled crypto.
     1549        if (!isBtcpayEnabled()) {
     1550            // Return success:false with a message indicating it's disabled
     1551            // This is NOT an error - it's expected behavior when disabled
     1552            return Promise.resolve({ success: false, message: 'BTCPay payment method is disabled', disabled: true });
     1553        }
     1554
     1555        // If session already created and exists, return it
    14361556        if (isSessionCreated && btcPaySession) {
    14371557            return Promise.resolve({ success: true, session: btcPaySession });
     
    14721592                            resolve({ success: true, session: btcPaySession });
    14731593                        } else {
    1474                             resolve({ success: false, message: sessionResponse.message || 'Failed to create BTCPay session' });
     1594                            // Extract message from WordPress AJAX response structure
     1595                            // WordPress error responses have message in data.message or directly in message
     1596                            const errorMessage = sessionResponse.data?.message || sessionResponse.message || 'Failed to create BTCPay session';
     1597                           
     1598                            // Check if the error is because BTC Pay is disabled
     1599                            const isDisabled = errorMessage.toLowerCase().includes('disabled') ||
     1600                                             errorMessage.toLowerCase().includes('btcpay payment method is disabled');
     1601                           
     1602                            // If disabled, mark it as such so the error won't be shown
     1603                            resolve({
     1604                                success: false,
     1605                                message: errorMessage,
     1606                                disabled: isDisabled
     1607                            });
    14751608                        }
    14761609                    },
    14771610                    error: function(xhr, status, error) {
    1478                         resolve({ success: false, message: 'AJAX request failed: ' + error });
     1611                        // On AJAX error, check if BTC Pay is still enabled before reporting error
     1612                        // If disabled, this is expected behavior
     1613                        const isDisabled = !isBtcpayEnabled();
     1614                        resolve({
     1615                            success: false,
     1616                            message: 'AJAX request failed: ' + error,
     1617                            disabled: isDisabled
     1618                        });
    14791619                    }
    14801620                });
     
    14901630     */
    14911631    function setupBTCPayMessageListener() {
     1632        // If BTCPay is disabled, do not attach any listeners.
     1633        if (!isBtcpayEnabled()) {
     1634            return;
     1635        }
     1636
    14921637        window.addEventListener('message', (event) => {
    14931638            // Verify the origin is from BTCPay
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/class-peachpay-convesiopay-integration.php

    r3385397 r3399128  
    251251
    252252        $capabilities = array(
    253             'card' => true,
     253            'card'     => true,
    254254            'applepay' => true,
    255             'btcpay' => true,
     255            'btcpay'   => true,
    256256        );
    257257
    258258        return isset( $capabilities[ $payment_key ] ) && $capabilities[ $payment_key ];
     259    }
     260
     261    /**
     262     * Check if a specific ConvesioPay WooCommerce gateway is enabled.
     263     *
     264     * This is used as the server-side source of truth for whether a
     265     * payment method such as BTCPay should be allowed to process orders
     266     * or create sessions/intents.
     267     *
     268     * @param string $gateway_id WooCommerce gateway ID.
     269     * @return boolean
     270     */
     271    public static function is_gateway_enabled( $gateway_id ) {
     272        if ( ! function_exists( 'WC' ) || ! WC()->payment_gateways ) {
     273            return false;
     274        }
     275
     276        $gateways       = WC()->payment_gateways->payment_gateways();
     277        $target_gateway = $gateways[ $gateway_id ] ?? null;
     278
     279        if ( ! $target_gateway ) {
     280            return false;
     281        }
     282
     283        $enabled_option   = method_exists( $target_gateway, 'get_option' ) ? $target_gateway->get_option( 'enabled', 'no' ) : 'no';
     284        $enabled_property = isset( $target_gateway->enabled ) ? $target_gateway->enabled : 'no';
     285
     286        return ( 'yes' === $enabled_option || 'yes' === $enabled_property );
     287    }
     288
     289    /**
     290     * Convenience wrapper: is BTCPay gateway enabled in WooCommerce.
     291     *
     292     * @return boolean
     293     */
     294    public static function is_btcpay_enabled() {
     295        return self::is_gateway_enabled( 'peachpay_convesiopay_btcpay' );
    259296    }
    260297
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/gateways/class-peachpay-convesiopay-btcpay-gateway.php

    r3394603 r3399128  
    132132     */
    133133    public function is_available( $skip_cart_check = false ) {
    134         return false;
     134        // Keep this gateway hidden in the standard WooCommerce list (the
     135        // unified gateway is the public entry point), but still provide a
     136        // reliable enabled check for server-side guards.
     137        if ( ! PeachPay_ConvesioPay_Integration::is_btcpay_enabled() ) {
     138            return false;
     139        }
     140
    135141        // Check if gateway is properly initialized
    136142        if ( ! $this->initialized ) {
     
    172178     */
    173179    public function process_payment( $order_id ) {
     180        // SERVER-SIDE SAFETY CHECK: never process BTCPay payments when the
     181        // method is disabled in WooCommerce/PeachPay settings.
     182        if ( ! PeachPay_ConvesioPay_Integration::is_btcpay_enabled() ) {
     183            return array(
     184                'result'  => 'failure',
     185                'message' => __( 'BTCPay payment method is disabled.', 'peachpay-for-woocommerce' ),
     186            );
     187        }
     188
    174189        $transaction_id = null;
    175190        $payment_token = null;
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/gateways/class-peachpay-convesiopay-unified-gateway.php

    r3395317 r3399128  
    544544
    545545        $btcpay_gateway = $gateways['peachpay_convesiopay_btcpay'];
     546
     547        // SERVER-SIDE SAFETY CHECK: if BTCPay is disabled in WooCommerce /
     548        // PeachPay settings, abort before any processing. This ensures that
     549        // even if the frontend sends BTCPay data, no BTCPay order can be
     550        // created when the method is disabled.
     551        if ( ! PeachPay_ConvesioPay_Integration::is_btcpay_enabled() ) {
     552            throw new Exception( 'ConvesioPay BTCPay payment method is disabled' );
     553        }
    546554
    547555        // Store original payment method before redirecting
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/hooks.php

    r3385397 r3399128  
    341341    if (empty($integration) || empty($order_number) || $amount <= 0) {
    342342        wp_send_json_error(array('message' => 'Missing required parameters'));
     343        return;
     344    }
     345
     346    // SERVER-SIDE SAFETY CHECK: if BTCPay is disabled in WooCommerce /
     347    // PeachPay settings, do not create sessions at all. This prevents
     348    // rogue or crafted requests from enabling BTCPay.
     349    if ( ! PeachPay_ConvesioPay_Integration::is_btcpay_enabled() ) {
     350        wp_send_json_error( array( 'message' => 'BTCPay payment method is disabled' ) );
    343351        return;
    344352    }
     
    452460    if (empty($session_id)) {
    453461        wp_send_json_error(array('message' => 'Session ID is required'));
     462        return;
     463    }
     464
     465    // SERVER-SIDE SAFETY CHECK: if BTCPay is disabled, do not attempt to
     466    // create new intents.
     467    if ( ! PeachPay_ConvesioPay_Integration::is_btcpay_enabled() ) {
     468        wp_send_json_error( array( 'message' => 'BTCPay payment method is disabled' ) );
    454469        return;
    455470    }
  • peachpay-for-woocommerce/trunk/peachpay.php

    r3395317 r3399128  
    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.118.4
     6 * Version: 1.118.5
    77 * Text Domain: peachpay-for-woocommerce
    88 * Domain Path: /languages
  • peachpay-for-woocommerce/trunk/readme.txt

    r3395317 r3399128  
    44Requires at least: 5.8
    55Tested up to: 6.8.1
    6 Stable tag: 1.118.4
     6Stable tag: 1.118.5
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    262262
    263263== Changelog ==
     264
     265= 1.118.5 =
     266* CPay/BTCPay payment initialization fix
    264267
    265268= 1.118.4 =
Note: See TracChangeset for help on using the changeset viewer.