PageSourceSearch

https://unitvnetwork.org/wp-content/plugins/gestorpay/assets/js/checkout.js?ver=1.0.0

js unitvnetwork.org collected 2026-09-27 02:01:47 UTC 5,681 bytes, 164 lines download raw bytes

1/**
2 * WooCommerce GestorPay Gateway - Checkout JavaScript
3 *
4 * @package WooCommerce_GestorPay
5 * @author Jonas Souza
6 * @since 1.0.0
7 */
8
9(function($) {
10    'use strict';
11
12    /**
13     * GestorPay Checkout Object
14     */
15    const GestorPayCheckout = {
16        
17        /**
18         * Initialize checkout functionality
19         */
20        init: function() {
21            this.bindEvents();
22        },
23
24        /**
25         * Bind event handlers
26         */
27        bindEvents: function() {
28            // Handle payment method selection
29            $(document.body).on('change', 'input[name="payment_method"]', this.handlePaymentMethodChange);
30            
31            // Enhanced form validation
32            $(document.body).on('checkout_place_order_gestorpay', this.validateGestorPayCheckout);
33        },
34
35        /**
36         * Handle payment method selection change
37         */
38        handlePaymentMethodChange: function() {
39            const selectedMethod = $('input[name="payment_method"]:checked').val();
40            
41            if (selectedMethod === 'gestorpay') {
42                GestorPayCheckout.activateGestorPayMethod();
43            }
44        },
45
46        /**
47         * Activate GestorPay payment method
48         */
49        activateGestorPayMethod: function() {
50            // Add visual feedback
51            $('.payment_method_gestorpay').addClass('selected');
52            
53            // Scroll to payment method if needed
54            this.scrollToPaymentMethod();
55        },
56
57        /**
58         * Scroll to payment method
59         */
60        scrollToPaymentMethod: function() {
61            const $paymentMethod = $('.payment_method_gestorpay');
62            if ($paymentMethod.length && !this.isElementInViewport($paymentMethod[0])) {
63                $('html, body').animate({
64                    scrollTop: $paymentMethod.offset().top - 100
65                }, 500);
66            }
67        },
68
69        /**
70         * Check if element is in viewport
71         */
72        isElementInViewport: function(el) {
73            const rect = el.getBoundingClientRect();
74            return (
75                rect.top >= 0 &&
76                rect.left >= 0 &&
77                rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
78                rect.right <= (window.innerWidth || document.documentElement.clientWidth)
79            );
80        },
81
82        /**
83         * Validate GestorPay checkout
84         */
85        validateGestorPayCheckout: function() {
86            // Additional validation specific to GestorPay
87            return true; // Allow checkout to proceed
88        },
89
90        /**
91         * Check for payment confirmation and redirect
92         */
93        checkPaymentStatus: function(orderId) {
94            if (!orderId) return;
95            
96            const checkInterval = setInterval(() => {
97                $.ajax({
98                    url: gestorpay_checkout_params.ajax_url,
99                    type: 'POST',
100                    data: {
101                        action: 'gestorpay_check_payment_status',
102                        order_id: orderId,
103                        nonce: gestorpay_checkout_params.nonce
104                    },
105                    success: function(response) {
106                        if (response.success && response.data.redirect_url) {
107                            clearInterval(checkInterval);
108                            window.location.href = response.data.redirect_url;
109                        } else if (response.data && response.data.status === 'completed') {
110                            clearInterval(checkInterval);
111                            // Payment confirmed but no redirect URL, reload page
112                            location.reload();
113                        }
114                    },
115                    error: function() {
116                        // Continue checking on error
117                    }
118                });
119            }, 3000); // Check every 3 seconds
120            
121            // Stop checking after 10 minutes
122            setTimeout(() => {
123                clearInterval(checkInterval);
124            }, 600000);
125        }
126    };
127
128    /**
129     * Initialize when document is ready
130     */
131    $(document).ready(function() {
132        GestorPayCheckout.init();
133        
134        // Auto-start payment status check on thank you page
135        if ($('.woocommerce-order-pix-payment').length > 0 || $('.gestorpay-pix-instructions').length > 0) {
136            // Extract order ID from URL or page
137            const urlParams = new URLSearchParams(window.location.search);
138            let orderId = urlParams.get('order-received') || urlParams.get('order_id');
139            
140            // Try to get from hidden field or data attribute
141            if (!orderId) {
142                orderId = $('[data-order-id]').data('order-id') || 
143                          $('input[name="order_id"]').val() ||
144                          $('.woocommerce-order').data('order-id');
145            }
146            
147            // Try to extract from URL path (e.g., /order-received/123/)
148            if (!orderId) {
149                const pathMatch = window.location.pathname.match(/order-received\/(\d+)/);
150                if (pathMatch) {
151                    orderId = pathMatch[1];
152                }
153            }
154            
155            if (orderId) {
156                GestorPayCheckout.checkPaymentStatus(orderId);
157            }
158        }
159    });
160
161    // Expose to global scope
162    window.GestorPayCheckout = GestorPayCheckout;
163
164})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.