phpgetopencartpayment-gateway

What is the link to redirect after successful payment at payment gateway in opencart?


I've implemented payment module in Opencart based on BankTransfer module. Requirement for payment gateway is to submit with get request a successurl and errorurl. Those URL are for successful order and canceled order.

Algorithm:

  1. Customer gets to the order checkout.
  2. Click confirm order
  3. Gets redirected to localhost/opencart/testkzm.php, where values are printed out and there's a link with to which i should redirect in case of success.

QUESTION: What is the link to redirect after successful payment at payment gateway?

Approach: I've naively thought that http://example.com/opencart/index.php?route=checkout/success is the success link. It's only shows confirmation message, but order is not placed in the system. I understand that there's no way to give external link that will automatically know which order to confirm, so should i pass encrypted unique values in successurl, so on return i can decrypt them and confirm order?

Explanation of files:

testkzm.php is simple file that i wrote to test that i get correct values from system.

banktransfer.php in controller/payment

 class ControllerPaymentBankTransfer extends Controller {
  protected function index() {
   $this->language->load('payment/bank_transfer');

   $this->data['text_instruction'] = $this->language->get('text_instruction');
   $this->data['text_description'] = $this->language->get('text_description');
   $this->data['text_payment'] = $this->language->get('text_payment');

   //Modified things for KZM
   $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
   $this->data['orderIdKZM'] = $this->session->data['order_id'];
   $this->data['amountKZM'] = $order_info['total'];

   $this->data['merchantIdKZM'] = $this->language->get('merchantIdKZM');
   $this->data['currencyKZM'] = $this->language->get('currencyKZM');
   $this->data['titleKZM'] = $this->language->get('titleKZM');
   $this->data['successuUlKZM'] = $this->language->get('successUrlKZM');
   $this->data['errorUrlKZM'] = $this->language->get('errorUrlKZM');
   $this->data['dateKZM'] = $this->language->get('dateKZM');
   $this->data['signstrKZM'] = $this->language->get('signstrKZM');
   $this->data['verKZM'] = $this->language->get('verKZM');
   //KZM

   $this->data['button_confirm'] = $this->language->get('button_confirm');

   $this->data['bank'] = nl2br($this->config->get('bank_transfer_bank_' . $this->config->get('config_language_id')));

   $this->data['continue'] = $this->url->link('checkout/success');

   if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/bank_transfer.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/payment/bank_transfer.tpl';
   } else {
    $this->template = 'default/template/payment/bank_transfer.tpl';
   } 

   $this->render(); 
  }

  public function confirm() {
   $this->language->load('payment/bank_transfer');

   $this->load->model('checkout/order');

   $comment  = $this->language->get('text_instruction') . "\n\n";
   $comment .= $this->config->get('bank_transfer_bank_' . $this->config->get('config_language_id')) . "\n\n";
   $comment .= $this->language->get('text_payment');

   $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('bank_transfer_order_status_id'), $comment, true);
  }
 }

banktransfer.tpl

<h2><?php echo $text_instruction; ?></h2>
 <div class="content">
    <p><?php echo $text_description; ?></p>
    <p><?php echo $bank; ?></p>
    <p><?php echo $text_payment; ?></p>
    <p><?php echo $orderIdKZM; ?></p>
    <p>
    <?php 
     $titleKZM = $titleKZM.$orderIdKZM; 
       $merchantIdKZM = '23';
   $currencyKZM = 'KZT';
   $successUrlKZM = '';
   $erroUrlKZM = '';
   $dateKZM = $merchantIdKZM.$orderIdKZM.$amountKZM.$currencyKZM;

    ?></p>
 </div>
 <div class="buttons">
   <div class="right">
 <form action="http://example.com/opencart/testkzm.php" method="get">
 <input type="hidden" name="merchantIdKZM" value="<?php echo $merchantIdKZM; ?>">
 <input type="hidden" name="orderIdKZM" value="<?php echo $orderIdKZM; ?>">
 <input type="hidden" name="amountKZM" value="<?php echo $amountKZM; ?>">
 <input type="hidden" name="currencyKZM" value="<?php echo $currencyKZM; ?>">
 <input type="hidden" name="successUrlKZM" value="<?php echo $successUrlKZM; ?>">
 <input type="hidden" name="errorUrlKZM" value="<?php echo $errorUrlKZM; ?>">
 <input type="hidden" name="signstrKZM" value="<?php echo $signstrKZM; ?>">
 <input type="hidden" name="verKZM"  value="<?php echo $verKZM; ?>">

 <input type="button" value="<?php echo $button_confirm; ?>" id="button-confirm" class="button" />
 </form>
     </div>
 </div>
 <script type="text/javascript"><!--
 $('#button-confirm-s').bind('click', function() {
  $.ajax({ 
   type: 'get',
   url: 'index.php?route=payment/bank_transfer/confirm',
   success: function() {
    location = '<?php echo $continue; ?>';
   }  
  });
 });
 //--></script

testkzm.php

merchantID <?php echo $_GET["merchantIdKZM"]; ?><br>
  orderID <?php echo $_GET["orderIdKZM"]; ?> <br> 
  amount <?php echo $_GET["amountKZM"]; ?><br>
  currency <?php echo $_GET["currencyKZM"]; ?> <br> 
  successURL <?php echo $_GET["successUrlKZM"]; ?><br>
  errorURL <?php echo $_GET["errorUrlKZM"]; ?> <br> 
  signstr <?php echo $_GET["signstrKZM"]; ?><br>
  ver <?php echo $_GET["verKZM"]; ?> <br> 

  <div class="buttons">
            <div class="right">
          <a href="http://example.com/opencart/index.php?route=checkout/success">asdfas</a>
         </div>
      </div>

Solution

  • The return URL from the payment gateway is completely up to yourself and the payment gateway's methodology. In general, if you can pass a url to the payment gateway to return for true and/or false for the success of the transaction, you would get it to use a method of your payment gateways controller, such as http://yourstore.com/index.php?route=payment/payment_gateway/success where you can then process the payment, and update the order status accordingly

    If you want to then go to the checkout success page, you would use $this->redirect($this->url->link('checkout/success', '', 'SSL')). If it fails, you should redirect back to the checkout pages where the customer can quickly skip through the various pages which should already have their details filled in, and they can then try again