S
S
Serge Tkach2017-03-06 19:07:42
opencart
Serge Tkach, 2017-03-06 19:07:42

Why is there no redirect after order confirmation in OpenCart 2.3 in the PrivatBank payment module?

The described module is https://www.opencart.com/index.php?route=marketpla...
I adapted it for 2.3, but I see that people also have problems with 2.1.
Logging in the controller showed that when accessing the payment server, the response was success. But here the redirect from the view file does not occur

error: function (xhr, ajaxOptions, thrownError) { // в случae нeудaчнoгo зaвeршeния зaпрoсa к сeрвeру

Reports that the response is 200
+ SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Here is the full code:
<?php //if ($testmode) { ?>
<!--  <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $text_testmode; ?></div>-->
<?php //} ?>

<div class="pull-right">
    <div class="row" style="margin-right: 1px;">
    <form id="privatbank_paymentparts_pp_checkout" role="form" class="form-inline">  
      <div class="form-group">
        <label for="partsCount_pp" style="float:left;padding: 6px 12px 2px 12px;"><?php echo $text_label_partsCount; ?></label>
        <select id="partsCount_pp" name="partsCount_pp" style="width:auto;" class="form-control selectWidth">
          <?php foreach ($partsCounts as $partsCount) { ?>
             <option><?php echo $partsCount; ?></option>
          <?php } ?>
        </select>
      </div>
      <div class="btn-group">
        <input type="submit" value="<?php echo $button_confirm; ?>" class="btn btn-primary" />
      </div>
      </form>
    </div>
</div> 

<script type="text/javascript">

$(document).ready(function(){
    $("#privatbank_paymentparts_pp_checkout").submit(function(){
        var error = false;
        partsCounArr = {partsCount: $('#partsCount_pp').val()};        
        
        $.ajax({
            type: 'POST',
            url: '<?php echo $action; ?>',
            dataType: 'json',
            data: partsCounArr,
               success: function(data){ // сoбытиe пoслe удaчнoгo oбрaщeния к сeрвeру и пoлучeния oтвeтa
               console.log(data['state']);
                    switch(data['state']){
                        case 'SUCCESS':
                            window.location = 'https://payparts2.privatbank.ua/ipp/v2/payment?token='+data['token'];
                            break;
                        case 'FAIL':
                            $('#collapse-checkout-confirm .panel-body').prepend('<div class="alert alert-warning">' + data['message'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                          break;
                        case 'sys_error':
                            $('#collapse-checkout-confirm .panel-body').prepend('<div class="alert alert-warning">' + data['message'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');                                          
                          break;
                    }                               
//                       if (data['error']) { // eсли oбрaбoтчик вeрнул oшибку
//                           alert(data['error']); // пoкaжeм eё тeкст
//                       } else { // eсли всe прoшлo oк
//                           alert('Письмo oтврaвлeнo! Чeкaйтe пoчту! =)'); // пишeм чтo всe oк
//                       }
                 },
               error: function (xhr, ajaxOptions, thrownError) { // в случae нeудaчнoгo зaвeршeния зaпрoсa к сeрвeру
//                    alert(xhr.status); // пoкaжeм oтвeт сeрвeрa
//                    alert(thrownError); // и тeкст oшибки
                 }
//               complete: function(data) { // сoбытиe пoслe любoгo исхoдa
//                    form.find('input[type="submit"]').prop('disabled', false); // в любoм случae включим кнoпку oбрaтнo
//                 }            
        });
        
        return false;    
    });    
});    

</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Serge Tkach, 2017-03-07
@SergeTkach

At first, everything rested on the fact that the cost of delivery should cost money without fail. And it seems to be logical for postal services. But what about self-pickup?
There is an option to remove from the scripts of the PrivatBank module the block in which it counts the delivery as a product. True, then you need to pay for the delivery in a separate way according to some personal agreement or something:

//add shipped in products
if(!empty($this->session->data['shipping_method']) && count($this->session->data['shipping_method'])>0){
    $data_deal['products'][] = array(
        'name'     => htmlspecialchars($this->session->data['shipping_method']['title']),
        'count' => 1,
        'price'    => $this->currency->format($this->session->data['shipping_method']['cost'], $order_info['currency_code'], false, false)
    );                
}
//End add shipped in products

If you do not remove the code and use the multi-delivery module, then it is important to know that there is a problem in the forum.opencart-russia.ru/threads/multi-dostavka-il... module: the module incorrectly calculates the shipping cost if you do not fill in the "Cost of change" field prices" (pay attention to the estimate of the basket, and not to the delivery unit)
2f92853637cd4395bd92b8a82b7e9309.pngf7f097d8c26741118a8c96529eb3b5b3.png

V
Vyacheslav, 2017-03-06
@Firik67

It is possible that the response does not come with json, which is indicated by the error, and therefore falls into error. To get into success, you need to bring the datatype in line with the response from the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question