PageSourceSearch

https://plantimax.pl/wp-content/plugins/woo-payu-payment-gateway/assets/js/payu-gateway.js?ver=2.11.0

js plantimax.pl collected 2026-10-08 09:35:11 UTC 9,997 bytes, 342 lines download raw bytes

1( function ( $ ) {
2  var $form = $( 'form.checkout' );
3
4  $( 'body' ).on(
5    'click',
6    '.payu-list-banks li.payu-active label',
7    function () {
8      $( '.payu-list-banks label' ).removeClass( 'active' );
9      $( this ).addClass( 'active' );
10    }
11  );
12
13  $( 'body' ).on( 'click', '.payu-list-banks .payu-active', function () {
14    $( '.pbl-error' ).slideUp( 250 );
15  } );
16
17  $( 'body' ).on(
18    'click',
19    '.payu-conditions-description .payu-read-more',
20    function () {
21      $( this ).next( '.payu-more-hidden' ).show();
22      $( this ).remove();
23    }
24  );
25
26  $( 'form#order_review' ).on( 'submit', function ( e ) {
27    var paymentMethod = $( this )
28      .find( 'input[name="payment_method"]:checked' )
29      .val();
30    var validateResult = true;
31
32    if ( paymentMethod === 'payusecureform' ) {
33      validateResult = validate_payu_secure_form( this );
34    } else if ( paymentMethod === 'payulistbanks' ) {
35      validateResult = validate_payu_list_banks();
36    } else if ( paymentMethod === 'payugooglepay' ) {
37      validateResult = validate_payu_google_pay( this );
38    } else if ( paymentMethod === 'payuapplepay' ) {
39      validateResult = validate_payu_apple_pay( this );
40    }
41
42    if ( ! validateResult ) {
43      setTimeout( function () {
44        $( e.target ).unblock();
45      }, 500 );
46    }
47
48    return validateResult;
49  } );
50
51  $form.on( 'checkout_place_order_payusecureform', function () {
52    return validate_payu_secure_form( this );
53  } );
54
55  $form.on( 'checkout_place_order_payulistbanks', function () {
56    return validate_payu_list_banks();
57  } );
58
59  $form.on( 'checkout_place_order_payugooglepay', function () {
60    return validate_payu_google_pay( this );
61  } );
62
63  $form.on( 'checkout_place_order_payuapplepay', function () {
64    return validate_payu_apple_pay( this );
65  } );
66
67  function validate_payu_secure_form( form ) {
68    var payuTokenElement = document.getElementsByName( 'payu_sf_token' )[ 0 ];
69
70    if (payuTokenElement.value === '') {
71      try {
72        window.payuSdkForms.tokenize()
73          .then(function (result) {
74            $('.payu-sf-validation-error, .payu-sf-technical-error')
75              .html('').slideUp(250);
76            if (result.status === 'SUCCESS') {
77              payuTokenElement.value = result.body.token;
78              document.getElementsByName('payu_browser[screenWidth]')[0].value = screen.width;
79              document.getElementsByName('payu_browser[javaEnabled]')[0].value = navigator.javaEnabled();
80              document.getElementsByName('payu_browser[timezoneOffset]')[0].value = new Date().getTimezoneOffset();
81              document.getElementsByName('payu_browser[screenHeight]')[0].value = screen.height;
82              document.getElementsByName('payu_browser[userAgent]')[0].value = navigator.userAgent;
83              document.getElementsByName('payu_browser[colorDepth]')[0].value = screen.colorDepth;
84              document.getElementsByName('payu_browser[language]')[0].value = navigator.language;
85              $(form).submit();
86            } else {
87              $(result.error.messages).each(function (i, error) {
88                var source = error.source || 'technical';
89                $('.payu-sf-' + error.type + '-error[data-type="' + source + '"]')
90                  .html(error.message)
91                  .slideDown(250);
92                $('html, body')
93                  .animate({
94                    scrollTop: $('.card-container').offset().top},
95                    300
96                  );
97              });
98            }
99          })
100          .catch(function (e) {
101              console.log(e);
102          });
103      } catch (e) {
104          console.log(e);
105      }
106
107      return false;
108    }
109
110    return true;
111  }
112
113  function hide_error(method) {
114    var errorMessage = document.querySelector( method + ' .payu-pay-error' );
115    if ( errorMessage ) {
116      errorMessage.style.display = 'none';
117    }
118  }
119
120  function show_error(method) {
121    var errorMessage = document.querySelector( method + ' .payu-pay-error' );
122    if ( errorMessage ) {
123      errorMessage.style.display = 'block';
124    }
125    $( 'html, body' ).animate(
126      {
127        scrollTop: $( method ).offset().top,
128      },
129      300
130    );
131  }
132
133  function validate_payu_list_banks() {
134    if ( ! $( '.payu-list-banks' ).find( '.payu-active .active' ).length ) {
135      $( 'html, body' ).animate(
136        {
137          scrollTop: $( '.payu-list-banks' ).offset().top,
138        },
139        300
140      );
141      $( '.pbl-error' ).slideDown( 250 );
142
143      return false;
144    } else {
145      $( '.pbl-error' ).slideUp( 250 );
146
147      return true;
148    }
149  }
150
151  function validate_payu_google_pay( form ) {
152    var methodClass = '.payment_method_payugooglepay';
153    hide_error(methodClass);
154
155    if ( ! window.google?.payments?.api?.PaymentsClient ) {
156      show_error(methodClass);
157      return false;
158    }
159
160    var googleToken = document.getElementById( 'payu-google-token' );
161
162    if ( googleToken.value === '' ) {
163      const paymentsClient = new google.payments.api.PaymentsClient( {
164        environment: payuGooglePayConfig.env,
165      } );
166
167      const isReadyToPayRequest = {
168        apiVersion: 2,
169        apiVersionMinor: 0,
170        allowedPaymentMethods: [
171          {
172            type: 'CARD',
173            parameters: {
174              allowedAuthMethods: [ 'PAN_ONLY', 'CRYPTOGRAM_3DS' ],
175              allowedCardNetworks: [ 'MASTERCARD', 'VISA' ],
176            },
177          },
178        ],
179      };
180
181      const paymentDataRequest = {
182        apiVersion: 2,
183        apiVersionMinor: 0,
184        merchantInfo: {
185          merchantName: payuGooglePayConfig.merchantName,
186          merchantId: payuGooglePayConfig.merchantId,
187        },
188        allowedPaymentMethods: [
189          {
190            type: 'CARD',
191            parameters: {
192              allowedAuthMethods: [ 'PAN_ONLY', 'CRYPTOGRAM_3DS' ],
193              allowedCardNetworks: [ 'MASTERCARD', 'VISA' ],
194              billingAddressRequired: false,
195            },
196            tokenizationSpecification: {
197              type: 'PAYMENT_GATEWAY',
198              parameters: {
199                gateway: 'payu',
200                gatewayMerchantId: payuGooglePayConfig.posId,
201              },
202            },
203          },
204        ],
205        transactionInfo: {
206          totalPriceStatus: 'FINAL',
207          countryCode: 'PL',
208          totalPrice: payuGooglePayConfig.totalPrice,
209          currencyCode: payuGooglePayConfig.currency,
210        },
211      };
212      paymentsClient
213        .isReadyToPay( isReadyToPayRequest )
214        .then( function ( response ) {
215          if ( response.result ) {
216            paymentsClient
217              .loadPaymentData( paymentDataRequest )
218              .then( function ( paymentData ) {
219                paymentToken =
220                  paymentData.paymentMethodData.tokenizationData.token;
221                googleToken.value = btoa( paymentToken );
222                $( form ).submit();
223              } )
224              .catch( function ( err ) {
225                console.error( err );
226              } );
227          }
228        } )
229        .catch( function ( err ) {
230          console.error( err );
231          show_error(methodClass);
232        } );
233      return false;
234    }
235
236    return true;
237  }
238
239  function applePayCanMakePayment() {
240    var applePayAvailable;
241
242    try {
243      applePayAvailable =
244        window.ApplePaySession && ApplePaySession.canMakePayments();
245    } catch ( _e ) {
246      applePayAvailable = false;
247    }
248
249    return applePayAvailable;
250  }
251
252  function getApplePayApiVersion() {
253    var APPLE_PAY_API_MIN_VERSION = 1;
254    var APPLE_PAY_API_MAX_VERSION = 14; // https://developer.apple.com/documentation/applepayontheweb/apple-pay-on-the-web-version-history
255
256    for ( var i = APPLE_PAY_API_MAX_VERSION; i > APPLE_PAY_API_MIN_VERSION; i-- ) {
257      if ( ApplePaySession.supportsVersion( i ) ) {
258        return i;
259      }
260    }
261
262    return APPLE_PAY_API_MIN_VERSION;
263  }
264
265  function validate_payu_apple_pay( form ) {
266    var methodClass = '.payment_method_payuapplepay';
267    var applepayToken = document.getElementById( 'payu-apple-token' );
268
269    hide_error( methodClass );
270
271    if (!applePayCanMakePayment()) {
272      show_error(methodClass);
273      return false;
274    }
275
276    if ( applepayToken.value === '' ) {
277      var applePaySession = new ApplePaySession( getApplePayApiVersion(), {
278        merchantCapabilities: [
279          'supports3DS',
280          'supportsCredit',
281          'supportsDebit',
282        ],
283        supportedNetworks: [ 'masterCard', 'visa' ],
284        countryCode: 'PL',
285        total: {
286          type: 'final',
287          label: payuApplePayConfig.appleDisplayName,
288          amount: payuApplePayConfig.totalPrice,
289        },
290        currencyCode: payuApplePayConfig.currency,
291      } );
292
293      applePaySession.onvalidatemerchant = ( event ) => {
294        var getApplePaySession = async () => {
295          let sessionResponse;
296
297          sessionResponse = await fetch( payuApplePayConfig.createSessionUrl, {
298            method: 'POST',
299            headers: { 'Content-Type': 'application/json' },
300          } );
301
302          if ( ! sessionResponse.ok ) {
303            show_error( methodClass );
304
305            applePaySession.abort();
306            return;
307          }
308
309          var session = await sessionResponse.json();
310
311          try {
312            applePaySession.completeMerchantValidation( session );
313          } catch ( error ) {
314            show_error( methodClass );
315
316            applePaySession.abort();
317          }
318        };
319
320        void getApplePaySession();
321      };
322
323      applePaySession.onpaymentauthorized = ( event ) => {
324        applePaySession.completePayment( ApplePaySession.STATUS_SUCCESS );
325        applepayToken.value = btoa(
326          JSON.stringify( event.payment.token.paymentData )
327        );
328        $( form ).submit();
329      };
330
331      applePaySession.oncancel = () => {
332        // Do nothing
333      };
334
335      applePaySession.begin();
336
337      return false;
338    }
339
340    return true;
341  }
342} )( 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.