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 @@ + +
"; + // 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 }