diff --git a/commerce_ccavenue.module b/commerce_ccavenue.module
index 7e49d88..33b4ea2 100644
--- a/commerce_ccavenue.module
+++ b/commerce_ccavenue.module
@@ -1,4 +1,3 @@
-
 <?php
 /**
  * @file
@@ -89,23 +88,27 @@ function ccavenue_redirect_form($form, &$form_state, $order, $payment_method) {
 function ccavenue_redirect_form_validate($order, $payment_method) {
   $authdesc = $_REQUEST['AuthDesc'];
   $checksum = _commerce_ccavenue_verify($payment_method);
+  $payment_method['request'] = $_REQUEST;
   $message = t('Security error ip Address was: @ip', array('@ip' => ip_address()));
+
   if ($checksum == 'true' && $authdesc == 'Y') {
-    return drupal_set_message(t('Thank you for shopping with us. Your account has been charged and your transaction is successful.'));
     commerce_ccavenue_transaction($order, $payment_method);
+    return drupal_set_message(t('Thank you for shopping with us. Your account has been charged and your transaction is successful.'));
     // Here you need to put in the routines for a successful.
     // Transaction such as sending an email to customer.
     // Setting database status, informing logistics etc etc.
   }
   elseif ($checksum == 'true' && $authdesc == 'B') {
-    return drupal_set_message(('Thank you for shopping with us.We will keep you posted regarding the status of your order through e-mail'));
     commerce_ccavenue_transaction($order, $payment_method);
+    commerce_order_status_update($order, 'pending', FALSE, NULL, $payment_method['request']['bankRespMsg']);
+    return drupal_set_message(('Thank you for shopping with us.We will keep you posted regarding the status of your order through e-mail'));
     // This is for payment American Express Card payment only.
     // American Express authorisation status is available only after 5-6.
   }
   elseif ($checksum == 'true' && $authdesc == 'N') {
-    return drupal_set_message(t('Thank you for shopping with us.However,the transaction has been declined.'));
     commerce_ccavenue_transaction($order, $payment_method);
+    commerce_order_status_update($order, 'canceled', FALSE, NULL, $payment_method['request']['bankRespMsg']);
+    return drupal_set_message(t('Thank you for shopping with us.However,the transaction has been declined.'));
     // Here you need to put in the routines for a failed.
     // Transaction such as sending an email to customer.
     // Setting database status etc etc.
@@ -123,15 +126,42 @@ function commerce_ccavenue_transaction($order, $payment_method) {
   if (_commerce_ccavenue_verify($payment_method) == 'false') {
     return;
   }
+
+  // Create payment transaction for current order
+  $transaction = commerce_payment_transaction_new('ccavenue', $order->order_id);
+  
   $wrapper = entity_metadata_wrapper('commerce_order', $order);
   $currency = $wrapper->commerce_order_total->currency_code->value();
   $amount = $wrapper->commerce_order_total->amount->value();
+
+  // Set some required data of order.
+  if ($payment_method['request']['bankRespCode'] == 'Y') {
+    $message = t('Payment received at @date', array('@date' => date("d-m-Y H:i:s", REQUEST_TIME)));
+    $status = COMMERCE_PAYMENT_STATUS_SUCCESS;
+  }
+  else {
+    $message = $payment_method['request']['bankRespMsg'];
+    if ($payment_method['request']['bankRespCode'] == 'B') {
+      $status = COMMERCE_PAYMENT_STATUS_PENDING;
+    }
+    else {
+      $status = COMMERCE_PAYMENT_STATUS_FAILURE;
+    }
+  }
+
+  $instance = explode('|', $payment_method['instance_id']);
+  $transaction->payment_method = !empty($instance[0]) ? $instance[0] : 'ccavenue';
   $transaction->instance_id = $payment_method['instance_id'];
   $transaction->amount = $amount;
   $transaction->currency_code = $currency;
-  $transaction->remote_status = t('Success');
-  $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
-  $transaction->message = t('Payment received at') . ' ' . date("d-m-Y H:i:s", REQUEST_TIME);
+  $transaction->remote_status = $status;
+  $transaction->remote_id = $order->order_id;
+  $transaction->status = $status;
+  $transaction->message = $message;
+  $transaction->message_variables = array();
+  $transaction->payload = $payment_method['request'];
+
+  // Save the payment transaction
   commerce_payment_transaction_save($transaction);
 }
 
