Skip to content
Advertisement

JQuery increase wait time before it throws error in my code

I would like to be able to increase the waiting time before an error is displayed in my code of this script… but I don’t have much idea how to do it…

It is assumed that when opening the modal sometimes it opens very quickly and the server shows an error…

This opening modal is from a gateway in Ecuador…

<script>   

$("#content-hook_order_confirmation").addClass("hide");
$("#content-hook_payment_return").addClass("hide");
$('#contenedor').insertBefore('#content');

   var PaymentCheckout = new PaymentCheckout.modal({
            client_app_code: "{$client_app_code}", 
                  client_app_key: "{$client_app_key}", 
            locale: "es", 
            env_mode: "{$ambiente}", 
            onOpen: function() {
                console.log("se abrio modal");
            },
            onClose: function() {
                console.log("cerrĂ³ modal");
            },
            onResponse: function(response) { 
          
               console.log(response);
              announceTransaction(response);
                if (response.transaction["status_detail"] == 3) {
                   
                   showMessageSuccess();

                } else {
                     showMessageError(); 
                }
             
            }
        });


      
        var btnOpenCheckout = document.querySelector(".Rot");
        var btnOpenCheckoutDifCon = document.querySelector(".DifCon");
        var btnOpenCheckoutDifSin = document.querySelector(".DifSin");
      
        btnOpenCheckout.addEventListener("click", function(){
          
        PaymentCheckout.open({
              user_id: "{$uid}",
              user_email: "{$email}",       
              user_phone: "{$telnumber}",
             order_description: "{$descripcion}",
              order_amount: {$order_amount},
             order_reference: "{$dev_reference}",            
            order_vat: {$vat},            
            order_tax_percentage: {$tax_percentage}, 
            order_taxable_amount: {$taxable_amount} 
            
          });
        });


           btnOpenCheckoutDifCon.addEventListener("click", function(){
          
          PaymentCheckout.open({
            user_id: "{$uid}",
            user_email: "{$email}",       
            user_phone: "{$telnumber}",
            order_description: "{$descripcion}",
            order_amount: {$order_amount},
            order_reference: "{$dev_reference}",            
            order_vat: {$vat},            
            order_tax_percentage: {$tax_percentage}, 
            order_taxable_amount: {$taxable_amount}, 
            order_installments_type: 2,
          });
        });


          btnOpenCheckoutDifSin.addEventListener("click", function(){
          
          PaymentCheckout.open({
            user_id: "{$uid}",
            user_email: "{$email}",       
            user_phone: "{$telnumber}",
            order_description: "{$descripcion}",
            order_amount: {$order_amount},
            order_reference: "{$dev_reference}",            
            order_vat: {$vat},            
            order_tax_percentage: {$tax_percentage}, 
            order_taxable_amount: {$taxable_amount},  
            order_installments_type: 3,
          });
        });

         
        
        window.addEventListener("popstate", function() {
          PaymentCheckout.close();
        });



        function showMessageSuccess() {
          $("#message").addClass("hide");
          $("#buttonspay").addClass("hide");
          $("#messagetwo").removeClass("hide");
                   
        }  


         function showMessageError() {
    
          $("#message").addClass("hide");
          $("#buttonspay").addClass("hide");
          $("#messagetres").removeClass("hide");
          
      }

        function announceTransaction(data) {
            fetch("{$paymentez_hook}", {
            method: "POST",
            body: JSON.stringify(data)
            }).then(function(response) {
            console.log(response);
            }).catch(function(myJson) {
            console.log(myJson);
            });
        }

</script>

Advertisement

Answer

use setTimeOut function to wait for. An example of this can be

setTimeout(function(){
//your code 
},5000) 

5000 means 5 seconds

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement