title: How to update order status in OpenCart
body: <p>I'm currently building an OpenCart payment extension for a new payment gateway. Right now, I can successfully make payments and redirect back to the merchant site but I don't know how to write the code so that it updates the order status as well.</p>
  
  <p>All my order are now showing under missing orders and I feel it's because of that. I don't have a callback function and I don't know     how to go about it. I want to update the code so that it can update my order status as completed if payment is successful or redirect     back to checkout if payment fails but still updates the order status. </p>
  
  <p>This is my code below:</p>
  
  <pre><code>&lt;?php
  class ControllerExtensionPaymentSCPAY extends Controller {
      public function index() {
          $this-&gt;load-&gt;language('extension/payment/sc_pay');
  
          $data['button_confirm'] = $this-&gt;language-&gt;get('button_confirm');
  
          $data['testmode'] = $this-&gt;config-&gt;get('sc_pay_test');
  
          $order_info = $this-&gt;model_checkout_order-&gt;getOrder($this-&gt;session-&gt;data['order_id']);
          $total = $order_info['total'];
  
          $newbutton = str_replace("50", $total, $this-&gt;config-&gt;get('sc_pay_button_link'));
  
          $newbutton = $newbutton .  "&amp;redirect_url=" .$this-&gt;url-&gt;link('checkout/success');
  
  
          if (!$this-&gt;config-&gt;get('sc_pay_test')) {
              $data['action'] = $newbutton;
          } 
  else {
              $data['action'] = '';
          }
  
          $this-&gt;load-&gt;model('checkout/order');
  
          $order_info = $this-&gt;model_checkout_order-&gt;getOrder($this-&gt;session-&gt;data['order_id']);
  
          if ($order_info) {
              $data['business'] = $this-&gt;config-&gt;get('sc_pay_email');
              $data['item_name'] = html_entity_decode($this-&gt;config-&gt;get('config_name'), ENT_QUOTES, 'UTF-8');
  
              $data['products'] = array();
  
              foreach ($this-&gt;cart-&gt;getProducts() as $product) {
                  $option_data = array();
  
                  foreach ($product['option'] as $option) {
                      if ($option['type'] != 'file') {
                          $value = $option['value'];
                      } 
  else {
                          $upload_info = $this-&gt;model_tool_upload-&gt;getUploadByCode($option['value']);
  
                          if ($upload_info) {
                              $value = $upload_info['name'];
                          }
   else {
                              $value = '';
                          }
                      }
  
                      $option_data[] = array(
                          'name'  =&gt; $option['name'],
                          'value' =&gt; (utf8_strlen($value) &gt; 20 ? utf8_substr($value, 0, 20) . '..' : $value)
                      );
                  }
  
                  $data['products'][] = array(
                      'name'     =&gt; htmlspecialchars($product['name']),
                      'model'    =&gt; htmlspecialchars($product['model']),
                      'price'    =&gt; $this-&gt;currency-&gt;format($product['price'], $order_info['currency_code'], false, false),
                      'quantity' =&gt; $product['quantity'],
                      'option'   =&gt; $option_data,
                      'weight'   =&gt; $product['weight']
                  );
              }
  
              $data['discount_amount_cart'] = 0;
  
              $total = $this-&gt;currency-&gt;format($order_info['total'] - $this-&gt;cart-&gt;getSubTotal(), $order_info['currency_code'], false, false);
  
              if ($total &gt; 0) {
                  $data['products'][] = array(
                      'name'     =&gt; $this-&gt;language-&gt;get('text_total'),
                      'model'    =&gt; '',
                      'price'    =&gt; $total,
                      'quantity' =&gt; 1,
                      'option'   =&gt; array(),
                      'weight'   =&gt; 0
                  );
              }
   else {
                  $data['discount_amount_cart'] -= $total;
              }
  
              $data['currency_code'] = $order_info['currency_code'];
              $data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
              $data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
              $data['address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
              $data['address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
              $data['city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
              $data['zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
              $data['country'] = $order_info['payment_iso_code_2'];
              $data['email'] = $order_info['email'];
              $data['invoice'] = $this-&gt;session-&gt;data['order_id'] . ' - ' . html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
              $data['lc'] = $this-&gt;session-&gt;data['language'];
              $data['return'] = $this-&gt;url-&gt;link('checkout/success');
              $data['notify_url'] = $this-&gt;url-&gt;link('extension/payment/sc_pay/callback', '', true);
              $data['cancel_return'] = $this-&gt;url-&gt;link('checkout/checkout', '', true);
  
              $data['custom'] = $this-&gt;session-&gt;data['order_id'];
  
              return $this-&gt;load-&gt;view('extension/payment/sc_pay', $data);
          }
      }
  
  enter code here
  </code></pre>