From b509bebeb8ad719f3c9acd031f0c963ce9d2b8f5 Mon Sep 17 00:00:00 2001 From: Prabal Mallick Date: Tue, 9 Jun 2020 13:04:32 +0600 Subject: [PATCH] Release update of Opencart V3.0 for API V3.5 --- README.md | 2 +- .../extension/payment/SSLCommerce.php | 27 + .../en-gb/extension/payment/SSLCommerce.php | 1 + .../extension/payment/SSLCommerce.twig | 8 + .../extension/payment/SSLCommerce.php | 640 +++++++++++++----- 5 files changed, 497 insertions(+), 181 deletions(-) diff --git a/README.md b/README.md index 91783c3..30fa30f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This Module Work for Opencart Version 3.x.x ### Feature - - Version 3.0 API + - Version 3.5 API ### Installation Steps: diff --git a/admin/controller/extension/payment/SSLCommerce.php b/admin/controller/extension/payment/SSLCommerce.php index 8d35316..fb123a9 100644 --- a/admin/controller/extension/payment/SSLCommerce.php +++ b/admin/controller/extension/payment/SSLCommerce.php @@ -136,6 +136,23 @@ public function index() { $data['payment_SSLCommerce_sort_order'] = $this->config->get('payment_SSLCommerce_sort_order'); } + $string = $this->url->link('extension/payment/SSLCommerce/sslcommerz_ipn', '', 'SSL'); + $data['payment_SSLCommerce_ipn_url'] = preg_replace('~/admin+~', '', $string, 1); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + /* admin/view/template/extension/payment/SSLCommerce.twig */ + + $string = $this->url->link('extension/payment/SSLCommerce/sslcommerz_ipn', '', 'SSL'); + // $data['payment_SSLCommerce_ipn_url'] = preg_replace('~/admin+~', '', $string, 1); + + $search = '/admin'; + $replace = ''; + $str = $this->str_replace_last( $search , $replace , $string ); + $data['payment_SSLCommerce_ipn_url'] = $str; + $data['header'] = $this->load->controller('common/header'); $data['column_left'] = $this->load->controller('common/column_left'); $data['footer'] = $this->load->controller('common/footer'); @@ -143,8 +160,18 @@ public function index() { /* admin/view/template/extension/payment/SSLCommerce.twig */ $this->response->setOutput($this->load->view('extension/payment/SSLCommerce', $data)); + + $this->response->setOutput($this->load->view('extension/payment/SSLCommerce', $data)); } + + private function str_replace_last( $search , $replace , $str ) { + if( ( $pos = strrpos( $str , $search ) ) !== false ) { + $search_length = strlen( $search ); + $str = substr_replace( $str , $replace , $pos , $search_length ); + } + return $str; + } private function validate() { if (!$this->user->hasPermission('modify', 'extension/payment/SSLCommerce')) { diff --git a/admin/language/en-gb/extension/payment/SSLCommerce.php b/admin/language/en-gb/extension/payment/SSLCommerce.php index 93112a5..11ea137 100644 --- a/admin/language/en-gb/extension/payment/SSLCommerce.php +++ b/admin/language/en-gb/extension/payment/SSLCommerce.php @@ -21,6 +21,7 @@ $_['entry_geo_zone'] = 'Geo Zone:'; $_['entry_status'] = 'Status:'; $_['entry_sort_order'] = 'Sort Order:'; +$_['ipn_url'] = 'IPN URL:'; // Error $_['error_permission'] = 'Warning: You do not have permission to modify payment SSLCommerce! You Must have SSLCommerce Store ID to Active the Account. Please Contact with SSLCommerce for Marchant.Click to Contact'; diff --git a/admin/view/template/extension/payment/SSLCommerce.twig b/admin/view/template/extension/payment/SSLCommerce.twig index 6eed846..855bc02 100644 --- a/admin/view/template/extension/payment/SSLCommerce.twig +++ b/admin/view/template/extension/payment/SSLCommerce.twig @@ -143,6 +143,14 @@ + +
+ +
+ + +
+
diff --git a/catalog/controller/extension/payment/SSLCommerce.php b/catalog/controller/extension/payment/SSLCommerce.php index afdabb5..695e232 100644 --- a/catalog/controller/extension/payment/SSLCommerce.php +++ b/catalog/controller/extension/payment/SSLCommerce.php @@ -1,4 +1,27 @@ config->get('config_currency'); + $data['currency'] = $order_info['currency_code']; $data['success_url'] = $this->url->link('extension/payment/SSLCommerce/callback', '', 'SSL'); - $data['fail_url'] = $this->url->link('checkout/failure', '', 'SSL'); - $data['cancel_url'] = $this->url->link('checkout/cart', '', 'SSL'); + $data['fail_url'] = $this->url->link('extension/payment/SSLCommerce/Failed', '', 'SSL'); + $data['cancel_url'] = $this->url->link('extension/payment/SSLCommerce/Cancelled', '', 'SSL'); ////Hash Key Gernarate For SSL $security_key = $this->sslcommerz_hash_key($this->config->get('payment_SSLCommerce_password'), $data); @@ -66,10 +89,10 @@ public function index() { if($this->config->get('payment_SSLCommerce_test')=='live') { - $data['process_url'] = 'https://securepay.sslcommerz.com/gwprocess/v3/process.php'; + $data['process_url'] = $this->url->link('extension/payment/SSLCommerce/sendrequest', '', 'SSL'); } else { - $data['process_url'] = 'https://sandbox.sslcommerz.com/gwprocess/v3/process.php'; + $data['process_url'] = $this->url->link('extension/payment/SSLCommerce/sendrequest', '', 'SSL'); } @@ -79,141 +102,265 @@ public function index() { return $this->load->view('extension/payment/SSLCommerce', $data); } } + + public function sendrequest() + { + $this->load->model('checkout/order'); + + $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);// update order status as pending + $data['store_id'] = $this->config->get('payment_SSLCommerce_merchant'); + $data['tran_id'] = $this->session->data['order_id']; + $data['total_amount'] = $_POST['total_amount']; + + $data['store_passwd'] = $this->config->get('payment_SSLCommerce_password'); + + $data['cus_name'] = $_POST['cus_name']; + $data['cus_add1'] = $order_info['payment_address_1']; + $data['cus_add2'] = $order_info['payment_address_2']; + $data['cus_city'] = $order_info['payment_city']; + $data['cus_state'] = $order_info['payment_zone']; + $data['cus_postcode'] = $order_info['payment_postcode']; + $data['cus_country'] = $order_info['payment_country']; + $data['cus_phone'] = $order_info['telephone']; + $data['cus_email'] = $_POST['cus_email']; + if ($this->cart->hasShipping()) { + $data['ship_name'] = $order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname']; + $data['ship_add1'] = $order_info['shipping_address_1']; + $data['ship_add2'] = $order_info['shipping_address_2']; + $data['ship_city'] = $order_info['shipping_city']; + $data['ship_state'] = $order_info['shipping_zone']; + $data['ship_postcode'] = $order_info['shipping_postcode']; + $data['ship_country'] = $order_info['shipping_country']; + } else { + $data['ship_name'] = ''; + $data['ship_add1'] = ''; + $data['ship_add2'] = ''; + $data['ship_city'] = ''; + $data['ship_state'] = ''; + $data['ship_postcode'] = ''; + $data['ship_country'] = ''; + } + $data['currency'] = $_POST['currency']; + $data['success_url'] = $this->url->link('extension/payment/SSLCommerce/callback', '', 'SSL'); + $data['fail_url'] = $this->url->link('extension/payment/SSLCommerce/Failed', '', 'SSL'); + $data['cancel_url'] = $this->url->link('extension/payment/SSLCommerce/Cancelled', '', 'SSL'); + + // $data['fail_url'] = $this->url->link('checkout/failure', '', 'SSL'); + // $data['cancel_url'] = $this->url->link('checkout/cart', '', 'SSL'); + + $data['verify_sign'] = $_POST['verify_sign']; + $data['verify_key'] = $_POST['verify_key']; + + if($this->config->get('payment_SSLCommerce_test')=='live') + { + $redirect_url = 'https://securepay.sslcommerz.com/gwprocess/v3/api.php'; + } + else + { + $redirect_url = 'https://sandbox.sslcommerz.com/gwprocess/v3/api.php'; + } + + $handle = curl_init(); + curl_setopt($handle, CURLOPT_URL, $redirect_url); + curl_setopt($handle, CURLOPT_TIMEOUT, 10); + curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($handle, CURLOPT_POST, 1 ); + curl_setopt($handle, CURLOPT_POSTFIELDS, $data); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + $content = curl_exec($handle ); + $code = curl_getinfo($handle, CURLINFO_HTTP_CODE); + + if($code == 200 && !( curl_errno($handle))) + { + curl_close( $handle); + $sslcommerzResponse = $content; + // print_r($sslcommerzResponse);exit; + # PARSE THE JSON RESPONSE + $sslcz = json_decode($sslcommerzResponse, true ); + if($sslcz['status']=='SUCCESS') + { + // update order status to 1 from 0. + $this->model_checkout_order->addOrderHistory($_POST['tran_id'], $this->config->get('config_order_status_id'), 'Order Initiated'); + if(isset($sslcz['GatewayPageURL']) && $sslcz['GatewayPageURL'] != '') + { + //header("Location: " . $this->sslc_data['GatewayPageURL']); + echo " + + "; + exit; + } + else + { + $this->error = "No redirect URL found!"; + return $this->error; + } + } + else if($sslcz['status']=='FAILED') + { + echo "FAILED TO CONNECT WITH SSLCOMMERZ API"; + echo "
Status: ".$sslcz['status']; + echo "
Failed Reason: ".$sslcz['failedreason']; + exit; + } + } + else + { + echo "CURL not activate!"; + } + } + + public function Failed() + { + $this->load->model('checkout/order'); + if (isset($_POST['tran_id'])) + { + $order_id = $_POST['tran_id']; + } + if(isset($_POST['status']) && $_POST['status'] == 'FAILED') + { + $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_fail_id'), "Order Failed By User", false); + echo " + + "; + exit; + } + } + public function Cancelled() + { + $this->load->model('checkout/order'); + if (isset($_POST['tran_id'])) + { + $order_id = $_POST['tran_id']; + } + if(isset($_POST['status']) && $_POST['status'] == 'CANCELLED') + { + $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_risk_id'), "Order Cancelled By User", false); + echo " + + "; + exit; + } + } - public function callback() { - - $SSLCommerce_test = $this->config->get('payment_SSLCommerce_test'); - $store_id = urldecode($this->config->get('payment_SSLCommerce_merchant')); - $store_passwd = urldecode($this->config->get('payment_SSLCommerce_password')); - if (isset($_POST['tran_id'])) { - $order_id = $_POST['tran_id']; - - } else { - $order_id = 0; - } - if (isset($_POST['amount'])) { - $total=$_POST['amount']; - - }else - { - $total=''; - - } - if(isset($_POST['val_id'])){ - $val_id = urldecode($_POST['val_id']); - } - else { - $val_id = ''; - } - - + + public function callback() + { + $SSLCommerce_test = $this->config->get('payment_SSLCommerce_test'); + $store_id = urldecode($this->config->get('payment_SSLCommerce_merchant')); + $store_passwd = urldecode($this->config->get('payment_SSLCommerce_password')); + if (isset($_POST['tran_id'])) + { + $order_id = $_POST['tran_id']; + } + else + { + $order_id = 0; + } + if (isset($_POST['amount'])) + { + $total=$_POST['amount']; + } + else + { + $total=''; + } + if(isset($_POST['val_id'])) + { + $val_id = urldecode($_POST['val_id']); + } + else + { + $val_id = ''; + } + if(!isset($_POST['tran_id']) || !isset($_POST['val_id']) || !isset($_POST['amount'])) + { + echo "Invalid Information"; + exit; + } + $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($order_id); $amount = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); - - -if(empty($val_id)){ - if($this->config->get('payment_SSLCommerce_test')=='live') { - $valid_url_own = ("https://securepay.sslcommerz.com/validator/api/merchantTransIDvalidationAPI.php?tran_id=".$order_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json"); - - } else{ - $valid_url_own = ("https://sandbox.sslcommerz.com/validator/api/merchantTransIDvalidationAPI.php?tran_id=".$order_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json"); - } - - $ownvalid = curl_init(); - curl_setopt($ownvalid, CURLOPT_URL, $valid_url_own); - curl_setopt($ownvalid, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ownvalid, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ownvalid, CURLOPT_SSL_VERIFYPEER, false); - - $ownvalid_result = curl_exec($ownvalid); - - $ownvalid_code = curl_getinfo($ownvalid, CURLINFO_HTTP_CODE); - if($ownvalid_code == 200 && !( curl_errno($ownvalid))) - { - $result_own = json_decode($ownvalid_result, true); - $lastupdate_no = $result_own['no_of_trans_found']-1; - $own_data = $result_own['element']; - $val_id = $own_data[$lastupdate_no]['val_id']; - //echo $own_data[0]['val_id']; - } - - - -} - - - - if($this->config->get('payment_SSLCommerce_test')=='live') { - $requested_url = ("https://securepay.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json"); - } else{ - $requested_url = ("https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json"); - } + if($this->config->get('payment_SSLCommerce_test')=='live') + { + $requested_url = ("https://securepay.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json"); + } + else + { + $requested_url = ("https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json"); + } - $amount = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); - $handle = curl_init(); -curl_setopt($handle, CURLOPT_URL, $requested_url); -curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); -curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false); -curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); - -$result = curl_exec($handle); - -$code = curl_getinfo($handle, CURLINFO_HTTP_CODE); + $amount = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); + $handle = curl_init(); + curl_setopt($handle, CURLOPT_URL, $requested_url); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); + + $result = curl_exec($handle); -if($code == 200 && !( curl_errno($handle))) -{ + // echo "
";
+        // print_r($result);exit;
 
-	# TO CONVERT AS ARRAY
-	# $result = json_decode($result, true);
-	# $status = $result['status'];	
-	
-	# TO CONVERT AS OBJECT
-	$result = json_decode($result);
-		//print_r($result);
-	# TRANSACTION INFO
-	$status = $result->status;	
-	$tran_date = $result->tran_date;
-	$tran_id = $result->tran_id;
-	$val_id = $result->val_id;
-	$amount = $result->amount;
-	$store_amount = $result->store_amount;
-	$bank_tran_id = $result->bank_tran_id;
-	$card_type = $result->card_type;
-	
-	# ISSUER INFO
-	$card_no = $result->card_no;
-	$card_issuer = $result->card_issuer;
-	$card_brand = $result->card_brand;
-	$card_issuer_country = $result->card_issuer_country;
-	$card_issuer_country_code = $result->card_issuer_country_code;   
-	
-	//Payment Risk Status
-	$risk_level = $result->risk_level;
-	$risk_title = $result->risk_title;
-	
+        $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
 
-                    if($status=='VALID')
-                    {
-                        if($risk_level==0){ $status = 'success';}
-                        if($risk_level==1){ $status = 'risk';} 
-                    }
-                    elseif($status=='VALIDATED'){
-                        if($risk_level==0){ $status = 'success';}
-                        if($risk_level==1){ $status = 'risk';} 
-                     }
-                    else
-                    {
-                         $status = 'failed';
-                    }
-                }
-//print_r($result);
-//exit;
+        if($code == 200 && !( curl_errno($handle)))
+        {	
+        	# TO CONVERT AS ARRAY
+        	# $result = json_decode($result, true);
+        	# $status = $result['status'];	
+        	
+        	# TO CONVERT AS OBJECT
+        	$result = json_decode($result);
+        		//print_r($result);
+        	# TRANSACTION INFO
+        	$status = $result->status;	
+        	$tran_date = $result->tran_date;
+        	$tran_id = $result->tran_id;
+        	$val_id = $result->val_id;
+        	$amount = $result->amount;
+        	$store_amount = $result->store_amount;
+        	$bank_tran_id = $result->bank_tran_id;
+        	$card_type = $result->card_type;
+        	
+        	# ISSUER INFO
+        	$card_no = $result->card_no;
+        	$card_issuer = $result->card_issuer;
+        	$card_brand = $result->card_brand;
+        	$card_issuer_country = $result->card_issuer_country;
+        	$card_issuer_country_code = $result->card_issuer_country_code;   
+        	
+        	//Payment Risk Status
+        	$risk_level = $result->risk_level;
+        	$risk_title = $result->risk_title;
+        
+            if($status=='VALID')
+            {
+                if($risk_level==0){ $status = 'success';}
+                if($risk_level==1){ $status = 'risk';} 
+            }
+            elseif($status=='VALIDATED'){
+                if($risk_level==0){ $status = 'success';}
+                if($risk_level==1){ $status = 'risk';} 
+            }
+            else
+            {
+                 $status = 'failed';
+            }
+        }
+        //print_r($result);
+        //exit;
 
- $data['breadcrumbs'] = array();
+        $data['breadcrumbs'] = array();
 
 			$data['breadcrumbs'][] = array(
 				'text' => $this->language->get('text_home'),
@@ -240,7 +387,7 @@ public function callback() {
 			
 			$data['button_continue'] = $this->language->get('button_continue');
 						
-		if ($order_info && $status) {
+		    if ($order_info && $status) {
 			$this->language->load('extension/payment/SSLCommerce');
 	
 			$data['title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));
@@ -262,54 +409,87 @@ public function callback() {
 			$data['text_failure'] = $this->language->get('text_failure');
 			$data['text_failure_wait'] = sprintf($this->language->get('text_failure_wait'), $this->url->link('checkout/cart'));
 	
+	        $msg='';
 	
-	
-			if (isset($status) && $status == 'success') {
-				$this->load->model('checkout/order');
-	
-				 $this->model_checkout_order->addOrderHistory($_POST['tran_id'], $this->config->get('config_order_status_id'));
-	
-				$message = '';
-	
-				
-					$message .= 'Payment Status = ' . $status . "\n";
-				    
-					$message .= 'Bank txnid = ' . $bank_tran_id . "\n";
-				   
-					$message .= 'Your Oder id = ' . $tran_id . "\n";
+			if (isset($status) && $status == 'success') 
+			{
+				    $this->load->model('checkout/order');
+                    $order_status = $order_info['order_status'];
+		    	    $amount_rat = $_POST['amount'];
+		    	    if($order_status == 'Pending')
+					{
+					    $message = '';
+    					$message .= 'Payment Status = ' . $status . "\n";
+    					$message .= 'Bank txnid = ' . $bank_tran_id . "\n";
+    					$message .= 'Your Oder id = ' . $tran_id . "\n";
+    					$message .= 'Payment Date = ' . $tran_date . "\n";  
+    					$message .= 'Card Number = ' .$card_no . "\n"; 
+    					$message .= 'Card Type = ' .$card_brand .'-'. $card_type . "\n"; 
+    					$message .= 'Transaction Risk Level = ' .$risk_level . "\n"; 
+    					$message .= 'Transaction Risk Description = ' .$risk_title . "\n";
+    				    if ($_POST['currency_amount'] == $result->currency_amount) 
+    					{
+							if($_POST['card_type'] != "")
+							{
+				                $this->model_checkout_order->addOrderHistory($_POST['tran_id'], $this->config->get('config_order_status_id'));
+							}
+							else
+        					{
+        						$msg= "Invalid Card Type!";
+        					}
+						}
+						else
+    					{
+    						$msg= "Your Paid Amount is Mismatched!";
+    					}
+					}
+					elseif($order_status == 'Processing' || $order_status == 'Complete' || $order_status == 'Processed')
+					{
+					    $message = '';
+					    $message .= 'Transaction Done By IPN: '. $order_status. "\n";
+					    $message .= 'Payment Status = ' . $status . "\n";
+    					$message .= 'Bank txnid = ' . $bank_tran_id . "\n";
+    					$message .= 'Your Oder id = ' . $tran_id . "\n";
+    					$message .= 'Payment Date = ' . $tran_date . "\n";  
+    					$message .= 'Card Number = ' .$card_no . "\n"; 
+    					$message .= 'Card Type = ' .$card_brand .'-'. $card_type . "\n"; 
+    					$message .= 'Transaction Risk Level = ' .$risk_level . "\n"; 
+    					$message .= 'Transaction Risk Description = ' .$risk_title . "\n";
+					}
+					else
+					{
+						$msg= "Order Status Not Pending!";
+					}
+
 					
-					$message .= 'Payment Date = ' . $tran_date . "\n";  
-				   
-					$message .= 'Card Number = ' .$card_no . "\n"; 
-				   
-					$message .= 'Card Type = ' .$card_brand .'-'. $card_type . "\n"; 
-				    
-					$message .= 'Transaction Risk Level = ' .$risk_level . "\n"; 
-				   
-					$message .= 'Transaction Risk Description = ' .$risk_title . "\n"; 
 	
-                   $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_status_id'), $message, false);
-	$error='';
+                    $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_status_id'), $message, false);
+	                $error='';
                     $data['text_message'] = sprintf('your payment was successfully received', $error, $this->url->link('information/contact'));
-			$data['continue'] = $this->url->link('checkout/success');
-            $data['column_left'] = $this->load->controller('common/column_left');
-			$data['column_right'] = $this->load->controller('common/column_right');
-			$data['content_top'] = $this->load->controller('common/content_top');
-			$data['content_bottom'] = $this->load->controller('common/content_bottom');
-			$data['footer'] = $this->load->controller('common/footer');
-			$data['header'] = $this->load->controller('common/header');
-             
-			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/payment/success')) {
-				$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/extension/payment/success', $data));
-			} else {
-				$this->response->setOutput($this->load->view('extension/payment/success', $data));
-			}
+        			$data['continue'] = $this->url->link('checkout/success');
+                    $data['column_left'] = $this->load->controller('common/column_left');
+        			$data['column_right'] = $this->load->controller('common/column_right');
+        			$data['content_top'] = $this->load->controller('common/content_top');
+        			$data['content_bottom'] = $this->load->controller('common/content_bottom');
+        			$data['footer'] = $this->load->controller('common/footer');
+        			$data['header'] = $this->load->controller('common/header');
+                    //echo $msg;
+        			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/payment/success')) 
+        			{
+        				$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/extension/payment/success', $data));
+        			} 
+        			else 
+        			{
+        				$this->response->setOutput($this->load->view('extension/payment/success', $data));
+        			}
 
 			}
-			else if (isset($status) && $status == 'risk') {
+			else if (isset($status) && $status == 'risk') 
+			{
+			    $msg = '';
 				$this->load->model('checkout/order');
-	
 				$this->model_checkout_order->addOrderHistory($_POST['tran_id'], $this->config->get('config_order_status_id'));
+				
 	
 				$message = '';
 	
@@ -331,15 +511,15 @@ public function callback() {
 					$message .= 'Transaction Risk Description = ' .$risk_title . "\n"; 
 					
 	            $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_risk_id'), $message, false);
-				$this->model_checkout_order->update($order_id, $this->config->get('payment_SSLCommerce_order_risk_id'), $message, false);
+				//$this->model_checkout_order->update($order_id, $this->config->get('payment_SSLCommerce_order_risk_id'), $message, false);
 	
 				$data['continue'] = $this->url->link('checkout/checkout');
-            $data['column_left'] = $this->load->controller('common/column_left');
-			$data['column_right'] = $this->load->controller('common/column_right');
-			$data['content_top'] = $this->load->controller('common/content_top');
-			$data['content_bottom'] = $this->load->controller('common/content_bottom');
-			$data['footer'] = $this->load->controller('common/footer');
-			$data['header'] = $this->load->controller('common/header');
+                $data['column_left'] = $this->load->controller('common/column_left');
+    			$data['column_right'] = $this->load->controller('common/column_right');
+    			$data['content_top'] = $this->load->controller('common/content_top');
+    			$data['content_bottom'] = $this->load->controller('common/content_bottom');
+    			$data['footer'] = $this->load->controller('common/footer');
+    			$data['header'] = $this->load->controller('common/header');
 
 				if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/payment/Commerce_risk')) {
 					$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/extension/payment/Commerce_risk', $data));
@@ -349,10 +529,6 @@ public function callback() {
 
 			} else {
 				
-				
-				
-				
-				
 			$data['continue'] = $this->url->link('checkout/cart');
             $data['column_left'] = $this->load->controller('common/column_left');
 			$data['column_right'] = $this->load->controller('common/column_right');
@@ -410,6 +586,110 @@ public function sslcommerz_hash_key($store_passwd="", $parameters=array()) {
 			}
 			return $return_key;
 		}
+		
+		
+		public function sslcommerz_ipn()
+		{
+			$this->load->model('checkout/order');
+			$order_id = $_POST['tran_id'];
+			$val_id = $_POST['val_id'];
+			$status = $_POST['status'];
+			
+			$order_info = $this->model_checkout_order->getOrder($order_id);
+			$store_passwd = $this->config->get('payment_SSLCommerce_password');
+			$store_id = $this->config->get('payment_SSLCommerce_merchant');
+
+			$order_status = $order_info['order_status'];
+			$amount_rat = $_POST['amount'];
+			
+			if($status == 'FAILED')
+			{
+			    $this->load->model('checkout/order');
+                $order_id = $_POST['tran_id'];
+                $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_fail_id'), "Order Failed By IPN", false);
+			    echo "Order ".$status." By IPN";
+			}
+			elseif($status == 'CANCELLED')
+			{
+			    $this->load->model('checkout/order');
+                $order_id = $_POST['tran_id'];
+                $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_risk_id'), "Order Cancelled By IPN", false);
+			    echo "Order ".$status." By IPN";
+			}
+			elseif($status == 'VALID' || $status == 'VALIDATED')
+			{
+			    if($this->config->get('payment_SSLCommerce_test')=='live') 
+    			{
+    				$valid_url_own = ("https://securepay.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json"); 	 
+    			} 
+    			else
+    			{
+    				$valid_url_own = ("https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json");  
+    			}
+    
+    			$handle = curl_init();
+    			curl_setopt($handle, CURLOPT_URL, $valid_url_own);
+    			curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+    			curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
+    			curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
+    				
+    			$result = curl_exec($handle);
+    			  	
+    			
+    			$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
+    				
+    			if($code == 200 && !( curl_errno($handle)))
+    			{	
+    				$result = json_decode($result);
+    
+    				if($this->sslcommerz_hash_key($store_passwd, $_POST))
+    				{
+    					if ($_POST['currency_amount'] == $result->currency_amount) 
+    					{
+    						if($result->status=='VALIDATED' || $result->status=='VALID') 
+    						{
+    							if($order_status == 'Pending')
+    							//if($order_status == '')
+    							{
+    								if($_POST['card_type'] != "")
+    								{
+    									//$this->load->model('checkout/order');
+    									$this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_SSLCommerce_order_status_id'), 'IPN Triggerd', false);
+    									$msg =  "Hash validation success.";
+    								}
+    								else
+    								{
+    								    $msg=  "Card Type Empty or Mismatched";
+    								}
+    							}
+    							else
+    							{
+    								$msg=  "Order already in processing Status";
+    							}
+    						}
+    						else
+    						{
+    							$msg=  "Your Validation id could not be Verified";
+    						}
+    					}
+    					else
+    					{
+    						$msg= "Your Paid Amount is Mismatched";
+    					}	
+    				}
+    				else
+    				{
+    					$msg =  "Hash validation failed.";              		
+    				}
+    				echo $msg;
+    			}
+			}
+			
+			else
+			{
+			    echo "Invalid Status!";
+			}
+		}
 		/// END
 
 }