From 81f0adab96770aa22d8f30b10c2c53ebf38fb56a Mon Sep 17 00:00:00 2001 From: Bruce Atkinson Date: Mon, 2 Aug 2021 05:01:47 +0200 Subject: [PATCH] 2021-07-20: v3.0.6 * Bug fixes and code quality improvements. * Fix logo issue on email and admin order detail page. * Improve display of payment redirect page. * Remove unused files and code. * Fix order declined not updating order status. --- README.md | 4 +- changelog.txt | 6 + .../controller/extension/payment/paygate.php | 230 ++--- .../controller/extension/payment/paygate.php | 963 ++++++++++-------- .../en-gb/extension/payment/paygate.php | 2 +- .../model/extension/payment/paygate.php | 2 +- .../template/extension/payment/paygate.twig | 27 - .../extension/payment/paygate_redirect.twig | 36 - .../theme/paygate/stylesheet/stylesheet.css | 65 -- 9 files changed, 614 insertions(+), 721 deletions(-) delete mode 100755 upload/catalog/view/theme/default/template/extension/payment/paygate.twig delete mode 100755 upload/catalog/view/theme/default/template/extension/payment/paygate_redirect.twig delete mode 100755 upload/catalog/view/theme/paygate/stylesheet/stylesheet.css diff --git a/README.md b/README.md index 147c0a3..9cf733d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # PayWeb_OpenCart -## PayGate OpenCart plugin v3.0.5 for OpenCart v3.0.3.7 +## PayGate OpenCart plugin v3.0.6 for OpenCart v3.0.3.7 This is the PayGate PayWeb3 plugin for OpenCart. Please feel free to contact the PayGate support team at support@paygate.co.za should you require any assistance. ## Installation [![How To Setup PayGate PayWeb for OpenCart](https://appinlet.com/wp-content/uploads/2021/01/How-To-Setup-PayGate-PayWeb-for-OpenCart.jpg)](https://www.youtube.com/watch?v=vP457DVuhGc "How To Setup PayGate PayWeb for OpenCart") -Please navigate to the [releases page](https://github.com/PayGate/PayWeb_OpenCart/releases), download the latest release (v3.0.5) and unzip. You will them be able to follow the integration guide PDF which is included in the zip. +Please navigate to the [releases page](https://github.com/PayGate/PayWeb_OpenCart/releases), download the latest release (v3.0.6) and unzip. You will them be able to follow the integration guide PDF which is included in the zip. ## Collaboration diff --git a/changelog.txt b/changelog.txt index 2d21209..dbc7b46 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,12 @@ ===================================== Date : Version: Description ===================================== +2021-07-20: v3.0.6 : Bug fixes and code quality improvements. + Fix logo issue on email and admin order detail page. + Improve display of payment redirect page. + Remove unused files and code. + Fix order declined not updating order status. + 2021-05-16: v3.0.5 : Tested on 3.0.3.7. Improve clear or restore cart handling. Remove iFrame option. diff --git a/upload/admin/controller/extension/payment/paygate.php b/upload/admin/controller/extension/payment/paygate.php index 1fbc624..70257bc 100755 --- a/upload/admin/controller/extension/payment/paygate.php +++ b/upload/admin/controller/extension/payment/paygate.php @@ -12,32 +12,52 @@ class ControllerExtensionPaymentPaygate extends Controller { private $error = array(); + + const PAYMENT_URL = "marketplace/extension"; + const PAYGATE_LANGUAGE = "extension/payment/paygate"; + + public function getToken(){ + return $this->session->data['user_token']; + } + + public function formatPaymentUrl($path){ + $token = $this->getToken(); + return $this->url->link( + $path, + 'user_token=' . $token . '&type=payment', + true + ); + } + + public function formatUrl($path){ + $token = $this->getToken(); + return $this->url->link( + $path, + "user_token=$token", + true + ); + } public function index() { - $this->load->language( 'extension/payment/paygate' ); + $this->load->language( self::PAYGATE_LANGUAGE ); $this->document->setTitle( $this->language->get( 'heading_title' ) ); $this->load->model( 'setting/setting' ); + $this->load->model( 'localisation/order_status' ); + $this->load->model( 'localisation/geo_zone' ); if ( ( $this->request->server['REQUEST_METHOD'] == 'POST' ) && $this->validate() ) { $this->model_setting_setting->editSetting( 'payment_paygate', $this->request->post ); $this->session->data['success'] = $this->language->get( 'text_success' ); - $this->response->redirect( - $this->url->link( - 'marketplace/extension', - 'user_token=' . $this->session->data['user_token'] . '&type=payment', - true - ) - ); + $url = $this->formatPaymentUrl(self::PAYMENT_URL); + $this->response->redirect($url); } $data['heading_title'] = $this->language->get( 'heading_title' ); - $data['text_edit'] = $this->language->get( 'text_edit' ); $data['text_enabled'] = $this->language->get( 'text_enabled' ); $data['text_disabled'] = $this->language->get( 'text_disabled' ); $data['text_all_zones'] = $this->language->get( 'text_all_zones' ); - $data['entry_order_status'] = $this->language->get( 'entry_order_status' ); $data['entry_success_status'] = $this->language->get( 'entry_success_status' ); $data['entry_failed_status'] = $this->language->get( 'entry_failed_status' ); @@ -47,191 +67,67 @@ public function index() $data['entry_status'] = $this->language->get( 'entry_status' ); $data['entry_sort_order'] = $this->language->get( 'entry_sort_order' ); $data['entry_notify_redirect'] = $this->language->get( 'entry_notify_redirect' ); - $data['tab_general'] = $this->language->get( 'tab_general' ); $data['tab_order_status'] = $this->language->get( 'tab_order_status' ); - $data['entry_merchant_id'] = $this->language->get( 'entry_merchant_id' ); $data['entry_merchant_key'] = $this->language->get( 'entry_merchant_key' ); - $data['help_total'] = $this->language->get( 'help_total' ); - $data['button_save'] = $this->language->get( 'button_save' ); $data['button_cancel'] = $this->language->get( 'button_cancel' ); - - if ( isset( $this->error['warning'] ) ) { - $data['error_warning'] = $this->error['warning']; - } else { - $data['error_warning'] = ''; - } - + $data['error_warning'] = isset($this->error['warning'])?$data['error_warning']:''; $data['breadcrumbs'] = array(); - + $data['breadcrumbs'][] = array( 'text' => $this->language->get( 'text_home' ), - 'href' => $this->url->link( 'common/dashboard', 'user_token=' . $this->session->data['user_token'], true ), + 'href' => $this->formatUrl('common/dashboard'), ); $data['breadcrumbs'][] = array( 'text' => $this->language->get( 'text_extension' ), - 'href' => $this->url->link( - 'marketplace/extension', - 'user_token=' . $this->session->data['user_token'] . '&type=payment', - true - ), + 'href' => $this->formatPaymentUrl(self::PAYMENT_URL), ); $data['breadcrumbs'][] = array( 'text' => $this->language->get( 'heading_title' ), - 'href' => $this->url->link( - 'extension/payment/paygate', - 'user_token=' . $this->session->data['user_token'], - true - ), - ); - - $data['action'] = $this->url->link( - 'extension/payment/paygate', - 'user_token=' . $this->session->data['user_token'], - true - ); - $data['cancel'] = $this->url->link( - 'marketplace/extension', - 'user_token=' . $this->session->data['user_token'] . '&type=payment', - true - ); - - if ( isset( $this->request->post['payment_paygate_total'] ) ) { - $data['payment_paygate_total'] = $this->request->post['payment_paygate_total']; - } else { - $data['payment_paygate_total'] = $this->config->get( 'payment_paygate_total' ); - } - - if ( isset( $this->request->post['payment_paygate_order_status_id'] ) ) { - $data['payment_paygate_order_status_id'] = $this->request->post['payment_paygate_order_status_id']; - } else { - $data['payment_paygate_order_status_id'] = $this->config->get( 'payment_paygate_order_status_id' ); - } - - if ( isset( $this->request->post['payment_paygate_success_order_status_id'] ) ) { - $data['payment_paygate_success_order_status_id'] = $this->request->post['payment_paygate_success_order_status_id']; - } else { - $data['payment_paygate_success_order_status_id'] = $this->config->get( - 'payment_paygate_success_order_status_id' - ); - } - - if ( isset( $this->request->post['payment_paygate_failed_order_status_id'] ) ) { - $data['payment_paygate_failed_order_status_id'] = $this->request->post['payment_paygate_failed_order_status_id']; - } else { - $data['payment_paygate_failed_order_status_id'] = $this->config->get( - 'payment_paygate_failed_order_status_id' - ); - } - - if ( isset( $this->request->post['payment_paygate_cancelled_order_status_id'] ) ) { - $data['payment_paygate_cancelled_order_status_id'] = $this->request->post['payment_paygate_cancelled_order_status_id']; - } else { - $data['payment_paygate_cancelled_order_status_id'] = $this->config->get( - 'payment_paygate_cancelled_order_status_id' - ); - } - - $this->load->model( 'localisation/order_status' ); - + 'href' => $this->formatUrl(self::PAYGATE_LANGUAGE), + ); + + $data['action'] = $this->formatUrl(self::PAYGATE_LANGUAGE); + $data['cancel'] = $this->formatPaymentUrl(self::PAYMENT_URL); + $data['payment_paygate_total'] = $this->checkPostValue("payment_paygate_total"); + $data['payment_paygate_order_status_id'] = $this->checkPostValue("payment_paygate_order_status_id"); + $data['payment_paygate_success_order_status_id'] = $this->checkPostValue("payment_paygate_success_order_status_id"); + $data['payment_paygate_failed_order_status_id'] = $this->checkPostValue("payment_paygate_failed_order_status_id"); + $data['payment_paygate_cancelled_order_status_id'] = $this->checkPostValue("payment_paygate_cancelled_order_status_id"); $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); - - if ( isset( $this->request->post['payment_paygate_geo_zone_id'] ) ) { - $data['payment_paygate_geo_zone_id'] = $this->request->post['payment_paygate_geo_zone_id']; - } else { - $data['payment_paygate_geo_zone_id'] = $this->config->get( 'payment_paygate_geo_zone_id' ); - } - - $this->load->model( 'localisation/geo_zone' ); - $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); - - if ( isset( $this->request->post['payment_paygate_status'] ) ) { - $data['payment_paygate_status'] = $this->request->post['payment_paygate_status']; - } else { - $data['payment_paygate_status'] = $this->config->get( 'payment_paygate_status' ); - } - - if ( isset( $this->request->post['payment_paygate_sort_order'] ) ) { - $data['payment_paygate_sort_order'] = $this->request->post['payment_paygate_sort_order']; - } else { - $data['payment_paygate_sort_order'] = $this->config->get( 'payment_paygate_sort_order' ); - } - - if ( isset( $this->request->post['payment_paygate_merchant_id'] ) ) { - $data['payment_paygate_merchant_id'] = $this->request->post['payment_paygate_merchant_id']; - } else { - $data['payment_paygate_merchant_id'] = $this->config->get( 'payment_paygate_merchant_id' ); - } - - if ( isset( $this->request->post['payment_paygate_merchant_key'] ) ) { - $data['payment_paygate_merchant_key'] = $this->request->post['payment_paygate_merchant_key']; - } else { - $data['payment_paygate_merchant_key'] = $this->config->get( 'payment_paygate_merchant_key' ); - } - - if ( isset( $this->request->post['payment_paygate_notifyredirect'] ) ) { - $data['payment_paygate_notifyredirect'] = $this->request->post['payment_paygate_notifyredirect']; - } else { - $data['payment_paygate_notifyredirect'] = $this->config->get( 'payment_paygate_notifyredirect' ); - } - - if ( isset( $this->request->post['payment_paygate_creditcardmethod'] ) ) { - $data['payment_paygate_creditcardmethod'] = $this->request->post['payment_paygate_creditcardmethod']; - } else { - $data['payment_paygate_creditcardmethod'] = $this->config->get( 'payment_paygate_creditcardmethod' ); - } - - if ( isset( $this->request->post['payment_paygate_banktransfermethod'] ) ) { - $data['payment_paygate_banktransfermethod'] = $this->request->post['payment_paygate_banktransfermethod']; - } else { - $data['payment_paygate_banktransfermethod'] = $this->config->get( 'payment_paygate_banktransfermethod' ); - } - - if ( isset( $this->request->post['payment_paygate_zappermethod'] ) ) { - $data['payment_paygate_zappermethod'] = $this->request->post['payment_paygate_zappermethod']; - } else { - $data['payment_paygate_zappermethod'] = $this->config->get( 'payment_paygate_zappermethod' ); - } - if ( isset( $this->request->post['payment_paygate_snapscanmethod'] ) ) { - $data['payment_paygate_snapscanmethod'] = $this->request->post['payment_paygate_snapscanmethod']; - } else { - $data['payment_paygate_snapscanmethod'] = $this->config->get( 'payment_paygate_snapscanmethod' ); - } - - if ( isset( $this->request->post['payment_paygate_mobicredmethod'] ) ) { - $data['payment_paygate_mobicredmethod'] = $this->request->post['payment_paygate_mobicredmethod']; - } else { - $data['payment_paygate_mobicredmethod'] = $this->config->get( 'payment_paygate_mobicredmethod' ); - } - - if ( isset( $this->request->post['payment_paygate_momopaymethod'] ) ) { - $data['payment_paygate_momopaymethod'] = $this->request->post['payment_paygate_momopaymethod']; - } else { - $data['payment_paygate_momopaymethod'] = $this->config->get( 'payment_paygate_momopaymethod' ); - } - - if ( isset( $this->request->post['payment_paygate_masterpassmethod'] ) ) { - $data['payment_paygate_masterpassmethod'] = $this->request->post['payment_paygate_masterpassmethod']; - } else { - $data['payment_paygate_masterpassmethod'] = $this->config->get( 'payment_paygate_masterpassmethod' ); - } - + $data['payment_paygate_status'] = $this->checkPostValue("payment_paygate_status"); + $data['payment_paygate_sort_order'] = $this->checkPostValue("payment_paygate_sort_order"); + $data['payment_paygate_merchant_id'] = $this->checkPostValue("payment_paygate_merchant_id"); + $data['payment_paygate_merchant_key'] = $this->checkPostValue("payment_paygate_merchant_key"); + $data['payment_paygate_notifyredirect'] = $this->checkPostValue("payment_paygate_notifyredirect"); + $data['payment_paygate_creditcardmethod'] = $this->checkPostValue("payment_paygate_creditcardmethod"); + $data['payment_paygate_banktransfermethod'] = $this->checkPostValue("payment_paygate_banktransfermethod"); + $data['payment_paygate_zappermethod'] = $this->checkPostValue("payment_paygate_zappermethod"); + $data['payment_paygate_snapscanmethod'] = $this->checkPostValue("payment_paygate_snapscanmethod"); + $data['payment_paygate_mobicredmethod'] = $this->checkPostValue("payment_paygate_mobicredmethod"); + $data['payment_paygate_momopaymethod'] = $this->checkPostValue("payment_paygate_momopaymethod"); + $data['payment_paygate_geo_zone_id'] = $this->checkPostValue("payment_paygate_geo_zone_id"); + $data['payment_paygate_masterpassmethod'] = $this->checkPostValue("payment_paygate_masterpassmethod"); $data['header'] = $this->load->controller( 'common/header' ); $data['column_left'] = $this->load->controller( 'common/column_left' ); $data['footer'] = $this->load->controller( 'common/footer' ); - $this->response->setOutput( $this->load->view( 'extension/payment/paygate', $data ) ); + $this->response->setOutput( $this->load->view( self::PAYGATE_LANGUAGE, $data ) ); } + + public function checkPostValue($var){ + return isset($this->request->post["$var"])?$this->request->post["$var"]:$this->config->get( "$var" ); + } protected function validate() { - if ( !$this->user->hasPermission( 'modify', 'extension/payment/paygate' ) ) { + if ( !$this->user->hasPermission( 'modify', self::PAYGATE_LANGUAGE ) ) { $this->error['warning'] = $this->language->get( 'error_permission' ); } diff --git a/upload/catalog/controller/extension/payment/paygate.php b/upload/catalog/controller/extension/payment/paygate.php index 8aad02b..790ae25 100755 --- a/upload/catalog/controller/extension/payment/paygate.php +++ b/upload/catalog/controller/extension/payment/paygate.php @@ -10,213 +10,265 @@ class ControllerExtensionPaymentPaygate extends Controller { protected $testmode; - + + const CHECKOUT_MODEL = "checkout/order"; + const INFORMATION_CONTACT = "information/contact"; + + public function getPaymentMethods(){ + + // Add enabled payment methods as checkout options + $imgs = 'catalog/view/theme/default/image/'; + $paymethods = [ + 'creditcardmethod' => [ + 'title' => 'Card', + 'img' => $imgs . 'mastercard-visa.svg', + ], + 'banktransfermethod' => [ + 'title' => 'SiD Secure EFT', + 'img' => $imgs . 'sid.svg', + ], + 'zappermethod' => [ + 'title' => 'Zapper', + 'img' => $imgs . 'zapper.svg', + ], + 'snapscanmethod' => [ + 'title' => 'SnapScan', + 'img' => $imgs . 'snapscan.svg', + ], + 'mobicredmethod' => [ + 'title' => 'Mobicred', + 'img' => $imgs . 'mobicred.svg', + ], + 'momopaymethod' => [ + 'title' => 'MoMoPay', + 'img' => $imgs . 'momopay.svg', + ], + 'masterpassmethod' => [ + 'title' => 'MasterPass', + 'img' => $imgs . 'masterpass.svg', + ], + ]; + $pms = []; + foreach ( $paymethods as $key => $paymethod ) { + $setting = 'payment_paygate_' . $key; + if ( $this->config->get( $setting ) === 'yes' ) { + $pms[] = ['method' => $key, 'title' => $paymethod['title'], 'img' => $paymethod['img']]; + } + } + + return $pms; + } + + public function getPayMethodDetails(){ + $data = array(); + $PAY_METHOD = 'EW'; + switch ( $_POST['paygate_pay_method'] ) { + case 'creditcardmethod'; + $PAY_METHOD = 'CC'; + $PAY_METHOD_DETAIL = ''; + break; + case 'banktransfermethod': + $PAY_METHOD = 'BT'; + $PAY_METHOD_DETAIL = 'SID'; + break; + case 'zappermethod': + $PAY_METHOD_DETAIL = 'Zapper'; + break; + case 'snapscanmethod': + $PAY_METHOD_DETAIL = 'SnapScan'; + break; + case 'mobicredmethod': + $PAY_METHOD_DETAIL = 'Mobicred'; + break; + case 'momopaymethod': + $PAY_METHOD_DETAIL = 'Momopay'; + break; + case 'masterpassmethod': + $PAY_METHOD_DETAIL = 'MasterPass'; + break; + default: + $PAY_METHOD_DETAIL = $_POST['paygate_pay_method']; + break; + + } + $data['PAY_METHOD'] = $PAY_METHOD; + $data['PAY_METHOD_DETAIL'] = $PAY_METHOD_DETAIL; + return $data; + } + + public function getCurrency(){ + if ( $this->config->get( 'config_currency' ) != '' ) { + $currency = filter_var( $this->config->get( 'config_currency' ), FILTER_SANITIZE_STRING ); + } else { + $currency = filter_var( $this->currency->getCode(), FILTER_SANITIZE_STRING ); + } + + return $currency; + } + + public function getNotifyUrl(){ + $notifyUrl = ""; + if ( $this->config->get( 'payment_paygate_notifyredirect' ) === 'notify' ) { + $notifyUrl = filter_var( + $this->url->link( 'extension/payment/paygate/notify_handler', '', true ), + FILTER_SANITIZE_URL + ); + } + return $notifyUrl; + } + + public function initiate_data($order_info,$pay_method_data){ + $doVault = ''; + $vaultID = ''; + $paygateID = $this->getPaygateId(); + $encryption_key = $this->getEncryptionkey(); + + if(isset($pay_method_data['PAY_METHOD'])){ + $PAY_METHOD = $pay_method_data['PAY_METHOD']; + $PAY_METHOD_DETAIL = $pay_method_data['PAY_METHOD_DETAIL']; + } + + /* getting order info ********/ + + $preAmount = number_format( $order_info['total'], 2, '', '' ); + $reference = filter_var( $order_info['order_id'], FILTER_SANITIZE_STRING ); + $amount = filter_var( $preAmount, FILTER_SANITIZE_NUMBER_INT ); + $currency = $this->getCurrency(); + + $returnUrl = filter_var( + $this->url->link( 'extension/payment/paygate/paygate_return', '', true ), + FILTER_SANITIZE_URL + ); + $returnUrl .= '/' . $reference; + $transDate = filter_var( date( 'Y-m-d H:i:s' ), FILTER_SANITIZE_STRING ); + $locale = filter_var( 'en', FILTER_SANITIZE_STRING ); + $country = filter_var( $order_info['payment_iso_code_3'], FILTER_SANITIZE_STRING ); + $email = filter_var( $order_info['email'], FILTER_SANITIZE_EMAIL ); + + // Check if email empty due to some custom themes displaying this on the same page + $email = empty( $email ) ? $this->config->get( 'config_email' ) : $email; + $payMethod = isset( $PAY_METHOD ) ? $PAY_METHOD : ''; + $payMethodDetail = isset( $PAY_METHOD_DETAIL ) ? $PAY_METHOD_DETAIL : ''; + + // Add notify if enabled + $notifyUrl = $this->getNotifyUrl(); + $userField1 = $order_info['order_id']; + $userField2 = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']; + $userField3 = 'opencart-v3.0.4'; + + /* getting order info ********/ + + $checksum_source = $paygateID . $reference . $amount . $currency . $returnUrl . $transDate; + + $checksum_source .= $locale; + $checksum_source .= $country; + $checksum_source .= $email; + + if ( $payMethod ) { + $checksum_source .= $payMethod; + } + if ( $payMethodDetail ) { + $checksum_source .= $payMethodDetail; + } + if ( $notifyUrl ) { + $checksum_source .= $notifyUrl; + } + + $checksum_source .= $userField1; + $checksum_source .= $userField2; + $checksum_source .= $userField3; + + if ( $doVault != '' ) { + $checksum_source .= $doVault; + } + if ( $vaultID != '' ) { + $checksum_source .= $vaultID; + } + + $checksum_source .= $encryption_key; + $checksum = md5( $checksum_source ); + + $initiateData = array( + 'PAYGATE_ID' => $paygateID, + 'REFERENCE' => $reference, + 'AMOUNT' => $amount, + 'CURRENCY' => $currency, + 'RETURN_URL' => $returnUrl, + 'TRANSACTION_DATE' => $transDate, + 'LOCALE' => $locale, + 'COUNTRY' => $country, + 'EMAIL' => $email, + 'PAY_METHOD' => $payMethod, + 'PAY_METHOD_DETAIL' => $payMethodDetail, + ); + if ( $this->config->get( 'payment_paygate_notifyredirect' ) === 'notify' ) { + $initiateData['NOTIFY_URL'] = $notifyUrl; + } + $initiateData['USER1'] = $userField1; + $initiateData['USER2'] = $userField2; + $initiateData['USER3'] = $userField3; + $initiateData['VAULT'] = $doVault; + $initiateData['VAULT_ID'] = $vaultID; + $initiateData['CHECKSUM'] = $checksum; + + return $initiateData; + } + + public function getPaygateId(){ + $this->testmode = $this->config->get( 'payment_paygate_testmode' ) === 'test'; + return $this->testmode ? '10011072130' : filter_var( + $this->config->get( 'payment_paygate_merchant_id' ), + FILTER_SANITIZE_STRING + ); + } + + public function getEncryptionkey(){ + $this->testmode = $this->config->get( 'payment_paygate_testmode' ) === 'test'; + return $this->testmode ? 'secret' : $this->config->get( 'payment_paygate_merchant_key' ); + } + public function index() { unset( $this->session->data['REFERENCE'] ); + + $dateTime = new DateTime(); + $time = $dateTime->format( 'YmdHis' ); $data['text_loading'] = $this->language->get( 'text_loading' ); $data['button_confirm'] = $this->language->get( 'button_confirm' ); - $data['text_loading'] = $this->language->get( 'text_loading' ); $data['continue'] = $this->language->get( 'payment_url' ); + + $pay_method_data = array(); - $this->load->model( 'checkout/order' ); + $this->load->model( self::CHECKOUT_MODEL ); $order_info = $this->model_checkout_order->getOrder( $this->session->data['order_id'] ); if ( empty( $_POST ) && $order_info['payment_code'] === 'paygate' ) { - // Add enabled payment methods as checkout options - $imgs = 'catalog/view/theme/default/image/'; - $paymethods = [ - 'creditcardmethod' => [ - 'title' => 'Card', - 'img' => $imgs . 'mastercard-visa.svg', - ], - 'banktransfermethod' => [ - 'title' => 'SiD Secure EFT', - 'img' => $imgs . 'sid.svg', - ], - 'zappermethod' => [ - 'title' => 'Zapper', - 'img' => $imgs . 'zapper.svg', - ], - 'snapscanmethod' => [ - 'title' => 'SnapScan', - 'img' => $imgs . 'snapscan.svg', - ], - 'mobicredmethod' => [ - 'title' => 'Mobicred', - 'img' => $imgs . 'mobicred.svg', - ], - 'momopaymethod' => [ - 'title' => 'MoMoPay', - 'img' => $imgs . 'momopay.svg', - ], - 'masterpassmethod' => [ - 'title' => 'MasterPass', - 'img' => $imgs . 'masterpass.svg', - ], - ]; - $pms = []; - foreach ( $paymethods as $key => $paymethod ) { - $setting = 'payment_paygate_' . $key; - if ( $this->config->get( $setting ) === 'yes' ) { - $pms[] = ['method' => $key, 'title' => $paymethod['title'], 'img' => $paymethod['img']]; - } - } - if ( !empty( $pms ) ) { - return $this->load->view( - 'extension/payment/paygate_payment_method', - [ - 'pay_methods' => $pms, - 'action' => $this->url->link( - 'extension/payment/paygate/index', - '', - true - ), - ] - ); - } + /* Get Payment Methods list */ + $pms = $this->getPaymentMethods(); + + if ( !empty( $pms ) ) { + return $this->load->view( + 'extension/payment/paygate_payment_method', + [ + 'pay_methods' => $pms, + 'action' => $this->url->link( + 'extension/payment/paygate/index', + '', + true + ), + ] + ); + } } elseif ( isset( $_POST['paygate_pay_method'] ) ) { - $PAY_METHOD = 'EW'; - $PAY_METHOD_DETAIL = $_POST['paygate_pay_method']; - switch ( $_POST['paygate_pay_method'] ) { - case 'creditcardmethod'; - $PAY_METHOD = 'CC'; - $PAY_METHOD_DETAIL = ''; - break; - case 'banktransfermethod': - $PAY_METHOD = 'BT'; - $PAY_METHOD_DETAIL = 'SID'; - break; - case 'zappermethod': - $PAY_METHOD_DETAIL = 'Zapper'; - break; - case 'snapscanmethod': - $PAY_METHOD_DETAIL = 'SnapScan'; - break; - case 'mobicredmethod': - $PAY_METHOD_DETAIL = 'Mobicred'; - break; - case 'momopaymethod': - $PAY_METHOD_DETAIL = 'Momopay'; - break; - case 'masterpassmethod': - $PAY_METHOD_DETAIL = 'MasterPass'; - break; - } + $pay_method_data = $this->getPayMethodDetails(); } if ( $order_info ) { - // Test mode or live credentials - $this->testmode = $this->config->get( 'payment_paygate_testmode' ) === 'test'; - $paygateID = $this->testmode ? '10011072130' : filter_var( - $this->config->get( 'payment_paygate_merchant_id' ), - FILTER_SANITIZE_STRING - ); - $encryption_key = $this->testmode ? 'secret' : $this->config->get( 'payment_paygate_merchant_key' ); - - $preAmount = number_format( $order_info['total'], 2, '', '' ); - $dateTime = new DateTime(); - $time = $dateTime->format( 'YmdHis' ); - $reference = filter_var( $order_info['order_id'], FILTER_SANITIZE_STRING ); - $amount = filter_var( $preAmount, FILTER_SANITIZE_NUMBER_INT ); - $currency = ''; - - if ( $this->config->get( 'config_currency' ) != '' ) { - $currency = filter_var( $this->config->get( 'config_currency' ), FILTER_SANITIZE_STRING ); - } else { - $currency = filter_var( $this->currency->getCode(), FILTER_SANITIZE_STRING ); - } - - $returnUrl = filter_var( - $this->url->link( 'extension/payment/paygate/paygate_return', '', true ), - FILTER_SANITIZE_URL - ); - $returnUrl .= '/' . $reference; - $transDate = filter_var( date( 'Y-m-d H:i:s' ), FILTER_SANITIZE_STRING ); - $locale = filter_var( 'en', FILTER_SANITIZE_STRING ); - $country = filter_var( $order_info['payment_iso_code_3'], FILTER_SANITIZE_STRING ); - $email = filter_var( $order_info['email'], FILTER_SANITIZE_EMAIL ); - // Check if email empty due to some custom themes displaying this on the same page - $email = empty( $email ) ? $this->config->get( 'config_email' ) : $email; - $payMethod = isset( $PAY_METHOD ) ? $PAY_METHOD : ''; - $payMethodDetail = isset( $PAY_METHOD_DETAIL ) ? $PAY_METHOD_DETAIL : ''; - - // Add notify if enabled - if ( $this->config->get( 'payment_paygate_notifyredirect' ) === 'notify' ) { - $notifyUrl = filter_var( - $this->url->link( 'extension/payment/paygate/notify_handler', '', true ), - FILTER_SANITIZE_URL - ); - } - $userField1 = $order_info['order_id']; - $userField2 = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']; - $userField3 = 'opencart-v3.0.4'; - $doVault = ''; - $vaultID = ''; - $checksum_source = $paygateID . $reference . $amount . $currency . $returnUrl . $transDate; - - if ( $locale ) { - $checksum_source .= $locale; - } - if ( $country ) { - $checksum_source .= $country; - } - if ( $email ) { - $checksum_source .= $email; - } - if ( $payMethod ) { - $checksum_source .= $payMethod; - } - if ( $payMethodDetail ) { - $checksum_source .= $payMethodDetail; - } - if ( isset( $notifyUrl ) ) { - $checksum_source .= $notifyUrl; - } - if ( $userField1 ) { - $checksum_source .= $userField1; - } - if ( $userField2 ) { - $checksum_source .= $userField2; - } - if ( $userField3 ) { - $checksum_source .= $userField3; - } - if ( $doVault != '' ) { - $checksum_source .= $doVault; - } - if ( $vaultID != '' ) { - $checksum_source .= $vaultID; - } - - $checksum_source .= $encryption_key; - $checksum = md5( $checksum_source ); - $initiateData = array( - 'PAYGATE_ID' => $paygateID, - 'REFERENCE' => $reference, - 'AMOUNT' => $amount, - 'CURRENCY' => $currency, - 'RETURN_URL' => $returnUrl, - 'TRANSACTION_DATE' => $transDate, - 'LOCALE' => $locale, - 'COUNTRY' => $country, - 'EMAIL' => $email, - 'PAY_METHOD' => $payMethod, - 'PAY_METHOD_DETAIL' => $payMethodDetail, - ); - if ( $this->config->get( 'payment_paygate_notifyredirect' ) === 'notify' ) { - $initiateData['NOTIFY_URL'] = $notifyUrl; - } - $initiateData['USER1'] = $userField1; - $initiateData['USER2'] = $userField2; - $initiateData['USER3'] = $userField3; - $initiateData['VAULT'] = $doVault; - $initiateData['VAULT_ID'] = $vaultID; - $initiateData['CHECKSUM'] = $checksum; - $CHECKSUM = null; - $PAY_REQUEST_ID = null; + + $initiateData = $this->initiate_data($order_info,$pay_method_data); + $fields_string = ''; // Url-ify the data for the POST @@ -224,7 +276,7 @@ public function index() $fields_string .= $key . '=' . $value . '&'; } - rtrim( $fields_string, '&' ); + $fields_string = rtrim( $fields_string, '&' ); // Open connection $ch = curl_init(); @@ -232,7 +284,7 @@ public function index() // Set the url, number of POST vars, POST data curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 ); curl_setopt( $ch, CURLOPT_URL, 'https://secure.paygate.co.za/payweb3/initiate.trans' ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_POST, count( $initiateData ) ); @@ -250,7 +302,7 @@ public function index() if ( isset( $result['ERROR'] ) ) { print_r( 'Error trying to initiate a transaction, paygate error code: ' . $result['ERROR'] . '. Log support ticket to shop owner' ); @@ -264,7 +316,7 @@ public function index() } else { print_r( 'Order could not be found, order_id: ' . $this->session->data['order_id'] . '. Log support ticket to shop owner' ); die(); @@ -278,20 +330,92 @@ public function index()
-
+

Redirecting you to PayGate...

HTML; - return; } else { return $this->load->view( 'extension/payment/paygate_redirect', $data ); } } + + public function getOrderIdFromSession(){ + // Get order Id from query string as backup if session fails + $m = []; + $orderId = 0; + preg_match( '/^.*\/(\d+)$/', $_GET['route'], $m ); + if ( count( $m ) > 1 ) { + $orderId = (int) $m[1]; + } elseif ( isset( $this->session->data['order_id'] ) ) { + $orderId = (int) $this->session->data['order_id']; + } + + return $orderId; + } + + public function setActivityData($order,$orderId){ + if ( $this->customer->isLogged() ) { + $activity_data = array( + 'customer_id' => $this->customer->getId(), + 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(), + 'order_id' => $orderId, + ); + $this->model_account_activity->addActivity( 'order_account', $activity_data ); + } else { + $activity_data = array( + 'name' => $order['firstname'] . ' ' . $order['lastname'], + 'order_id' => $orderId, + ); + $this->model_account_activity->addActivity( 'order_guest', $activity_data ); + } + } + + public function mapPGData($result,$useRedirect,$pay_method_desc){ + $pgData = array(); + $orderStatusId = '7'; + $resultsComment = ""; + if ( isset( $result['TRANSACTION_STATUS'] ) ) { + $status = 'ok'; + + if ( $result['TRANSACTION_STATUS'] == 0 ) { + $orderStatusId = 1; + $statusDesc = 'pending'; + $resultsComment = "Transaction status verification failed. No transaction status. Please contact the shop owner to confirm transaction status."; + } elseif ( $result['TRANSACTION_STATUS'] == 1 ) { + $orderStatusId = $this->config->get( 'payment_paygate_success_order_status_id' ); + $statusDesc = 'approved'; + $resultsComment = "Transaction Approved."; + } elseif ( $result['TRANSACTION_STATUS'] == 2 ) { + $orderStatusId = $this->config->get( 'payment_paygate_failed_order_status_id' ); + $statusDesc = 'declined'; + $resultsComment = "Transaction Declined by PayWeb."; + } elseif ( $result['TRANSACTION_STATUS'] == 4 ) { + $orderStatusId = $this->config->get( 'payment_paygate_cancelled_order_status_id' ); + $statusDesc = 'cancelled'; + $resultsComment = "Transaction Cancelled by User."; + } + if ( $useRedirect ) { + $resultsComment = "Redirect response from PayGate with a status of " . $statusDesc . $pay_method_desc; + } + } else { + $orderStatusId = 1; + $statusDesc = 'pending'; + $resultsComment = 'Transaction status verification failed. No transaction status. Please contact the shop owner to confirm transaction status.'; + } + + $pgData['orderStatusId'] = $orderStatusId; + $pgData['statusDesc'] = $statusDesc; + $pgData['resultsComment'] = $resultsComment; + $pgData['status'] = $status; + + return $pgData; + } /** * Handles redirect response from PayGate @@ -307,168 +431,146 @@ public function paygate_return() $statusDesc = ''; $status = ''; - // Check for test / live modes - $this->testmode = $this->config->get( 'payment_paygate_testmode' ) === 'test'; - $paygateID = $this->testmode ? '10011072130' : filter_var( - $this->config->get( 'payment_paygate_merchant_id' ), - FILTER_SANITIZE_STRING - ); - $encryption_key = $this->testmode ? 'secret' : $this->config->get( 'payment_paygate_merchant_key' ); - $useRedirect = $this->config->get( 'payment_paygate_notifyredirect' ) === 'redirect'; - - // Get order Id from query string as backup if session fails - $m = []; - preg_match( '/^.*\/(\d+)$/', $_GET['route'], $m ); - $orderId = 0; - if ( count( $m ) > 1 ) { - $orderId = (int) $m[1]; - } elseif ( isset( $this->session->data['order_id'] ) ) { - $orderId = (int) $this->session->data['order_id']; - } - + + $orderId = $this->getOrderIdFromSession(); + $sessionOrderId = isset( $this->session->data['order_id'] ) ? $this->session->data['order_id'] : 'Session data not set'; if ( $orderId !== 0 ) { // Add to activity log $this->load->model( 'account/activity' ); - $this->load->model( 'checkout/order' ); + $this->load->model( self::CHECKOUT_MODEL ); $order = $this->model_checkout_order->getOrder( $orderId ); $products = $this->model_checkout_order->getOrderProducts( $orderId ); - if ( $this->customer->isLogged() ) { - $activity_data = array( - 'customer_id' => $this->customer->getId(), - 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(), - 'order_id' => $orderId, - ); - $this->model_account_activity->addActivity( 'order_account', $activity_data ); - } else { - $activity_data = array( - 'name' => $order['firstname'] . ' ' . $order['lastname'], - 'order_id' => $orderId, - ); - $this->model_account_activity->addActivity( 'order_guest', $activity_data ); - } - - if ( $useRedirect ) { - // Query to verify response data - $pay_request_id = filter_var( $_POST['PAY_REQUEST_ID'], FILTER_SANITIZE_STRING ); - $reference = $orderId; - $checksum = md5( $paygateID . $pay_request_id . $reference . $encryption_key ); - $queryData = array( - 'PAYGATE_ID' => $paygateID, - 'PAY_REQUEST_ID' => $pay_request_id, - 'REFERENCE' => $reference, - 'CHECKSUM' => $checksum, - ); - - // Url-ify the data for the POST - $fields_string = ''; - foreach ( $queryData as $key => $value ) { - $fields_string .= $key . '=' . $value . '&'; - } - - rtrim( $fields_string, '&' ); - - // Open connection - $ch = curl_init(); - - // Set the url, number of POST vars, POST data - curl_setopt( $ch, CURLOPT_POST, 1 ); - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true ); - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 ); - curl_setopt( $ch, CURLOPT_URL, 'https://secure.paygate.co.za/payweb3/query.trans' ); - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); - curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields_string ); - - unset( $this->session->data['REFERENCE'] ); - - // Execute post - $r = curl_exec( $ch ); - $error = curl_error( $ch ); - - // Close connection - curl_close( $ch ); - $result = []; - if ( isset( $r ) && $r != '' ) { - parse_str( $r, $result ); - } - $pay_method_desc = ''; - } else { - // Use transaction status for redirecting in browser only - $result = $_POST; - } + $this->setActivityData($order,$orderId); + $pay_method_desc = ''; + $respData = $this->sendCurlRequest(); + $result = $respData['result']; + $r = $respData['r']; + $error = $respData['error']; if ( isset( $result['PAY_METHOD_DETAIL'] ) && $result['PAY_METHOD_DETAIL'] != '' ) { $pay_method_desc = ', using a payment method of ' . $result['PAY_METHOD_DETAIL']; } - $orderStatusId = '7'; - // Mapping pg transactions status with open card statuses - if ( isset( $result['TRANSACTION_STATUS'] ) ) { - $status = 'ok'; - - if ( $result['TRANSACTION_STATUS'] == 0 ) { - $orderStatusId = 1; - $statusDesc = 'pending'; - } elseif ( $result['TRANSACTION_STATUS'] == 1 ) { - $orderStatusId = $this->config->get( 'payment_paygate_success_order_status_id' ); - $statusDesc = 'approved'; - } elseif ( $result['TRANSACTION_STATUS'] == 2 ) { - $orderStatusId = $this->config->get( 'payment_paygate_failed_order_status_id' ); - $statusDesc = 'declined'; - } elseif ( $result['TRANSACTION_STATUS'] == 4 ) { - $orderStatusId = $this->config->get( 'payment_paygate_cancelled_order_status_id' ); - $statusDesc = 'cancelled'; - } - if ( $useRedirect ) { - $resultsComment = "Redirect response from PayGate with a status of " . $statusDesc . $pay_method_desc; - } - } else { - $orderStatusId = 1; - $statusDesc = 'pending'; - $resultsComment = 'Transaction status verification failed. No transaction status. Please contact the shop owner to confirm transaction status.'; - } - - if ( $statusDesc !== 'approved' ) { - // Restore the cart which has already been cleared - if(is_array($products)){ - foreach ($products as $product){ - $options = $this->model_checkout_order->getOrderOptions($orderId, $product['order_product_id']); - $option = []; - if(is_array($options) && count($options) > 0){ - $option = $options; - } - $this->cart->add($product['product_id'], $product['quantity'], $option); - } - } - } - - if ( $useRedirect ) { - $this->model_checkout_order->addOrderHistory( - $orderId, - $orderStatusId, - $resultsComment, - true - ); - unset( $this->session->data['shipping_method'] ); - unset( $this->session->data['shipping_methods'] ); - unset( $this->session->data['payment_method'] ); - unset( $this->session->data['payment_methods'] ); - unset( $this->session->data['guest'] ); - unset( $this->session->data['comment'] ); - unset( $this->session->data['order_id'] ); - unset( $this->session->data['coupon'] ); - unset( $this->session->data['reward'] ); - unset( $this->session->data['voucher'] ); - unset( $this->session->data['vouchers'] ); - unset( $this->session->data['totals'] ); - } - } else { - $sessionOrderId = isset( $this->session->data['order_id'] ) ? $this->session->data['order_id'] : 'Session data not set'; - } - - if ( $status == 'ok' ) { + $pgData = $this->mapPGData($result,$useRedirect,$pay_method_desc); + $orderStatusId = $pgData['orderStatusId']; + $statusDesc = $pgData['statusDesc']; + $resultsComment = $pgData['resultsComment']; + $status = $pgData['status']; + + $this->restoreCart($products,$statusDesc,$orderId); + + $this->model_checkout_order->addOrderHistory( + $orderId, + $orderStatusId, + $resultsComment, + true + ); + + if ( $useRedirect ) { + unset( $this->session->data['shipping_method'] ); + unset( $this->session->data['shipping_methods'] ); + unset( $this->session->data['payment_method'] ); + unset( $this->session->data['payment_methods'] ); + unset( $this->session->data['guest'] ); + unset( $this->session->data['comment'] ); + unset( $this->session->data['order_id'] ); + unset( $this->session->data['coupon'] ); + unset( $this->session->data['reward'] ); + unset( $this->session->data['voucher'] ); + unset( $this->session->data['vouchers'] ); + unset( $this->session->data['totals'] ); + } + } else { + $sessionOrderId = isset( $this->session->data['order_id'] ) ? $this->session->data['order_id'] : 'Session data not set'; + } + + $this->setHeadingValues($result,$status,$error,$r,$sessionOrderId,$statusDesc); + } + + public function restoreCart($products,$statusDesc,$orderId){ + + if ( $statusDesc !== 'approved' && is_array($products)) { + // Restore the cart which has already been cleared + foreach ($products as $product){ + $options = $this->model_checkout_order->getOrderOptions($orderId, $product['order_product_id']); + $option = []; + if(is_array($options) && count($options) > 0){ + $option = $options; + } + $this->cart->add($product['product_id'], $product['quantity'], $option); + } + } + } + + public function sendCurlRequest(){ + + $paygateID = $this->getPaygateId(); + $encryption_key = $this->getEncryptionkey(); + $useRedirect = $this->config->get( 'payment_paygate_notifyredirect' ) === 'redirect'; + $respData = array(); + $orderId = $this->getOrderIdFromSession(); + $r = ""; + $error = false; + if ( $useRedirect ) { + // Query to verify response data + $pay_request_id = filter_var( $_POST['PAY_REQUEST_ID'], FILTER_SANITIZE_STRING ); + $reference = $orderId; + $checksum = md5( $paygateID . $pay_request_id . $reference . $encryption_key ); + $queryData = array( + 'PAYGATE_ID' => $paygateID, + 'PAY_REQUEST_ID' => $pay_request_id, + 'REFERENCE' => $reference, + 'CHECKSUM' => $checksum, + ); + + // Url-ify the data for the POST + $fields_string = ''; + foreach ( $queryData as $key => $value ) { + $fields_string .= $key . '=' . $value . '&'; + } + + $fields_string = rtrim( $fields_string, '&' ); + + // Open connection + $ch = curl_init(); + + // Set the url, number of POST vars, POST data + curl_setopt( $ch, CURLOPT_POST, 1 ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 ); + curl_setopt( $ch, CURLOPT_URL, 'https://secure.paygate.co.za/payweb3/query.trans' ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields_string ); + + unset( $this->session->data['REFERENCE'] ); + + // Execute post + $r = curl_exec( $ch ); + $error = curl_error( $ch ); + + // Close connection + curl_close( $ch ); + $result = []; + if ( isset( $r ) && $r != '' ) { + parse_str( $r, $result ); + } + + } else { + // Use transaction status for redirecting in browser only + $result = $_POST; + } + $respData['result'] = $result; + $respData['r'] = $r; + $respData['error'] = $error; + return $respData; + } + + public function setHeadingValues($result,$status,$error,$r,$sessionOrderId,$statusDesc){ + + if ( $status == 'ok' ) { $data['heading_title'] = sprintf( $this->language->get( 'heading_title' ), $statusDesc ); $this->document->setTitle( $data['heading_title'] ); } else { @@ -510,12 +612,12 @@ public function paygate_return() $this->url->link( 'account/account', '', 'SSL' ), $this->url->link( 'account/order', '', 'SSL' ), $this->url->link( 'account/download', '', 'SSL' ), - $this->url->link( 'information/contact' ) + $this->url->link( self::INFORMATION_CONTACT ) ); } else { $data['text_message'] = sprintf( $this->language->get( 'text_guest' ), - $this->url->link( 'information/contact' ) + $this->url->link( self::INFORMATION_CONTACT ) ); } @@ -529,7 +631,8 @@ public function paygate_return() $data['header'] = $this->load->controller( 'common/header' ); $this->response->setOutput( $this->load->view( 'common/paygate_success', $data ) ); - } + + } /** * Handles notify response from PayGate @@ -541,80 +644,28 @@ public function notify_handler() if ( $this->config->get( 'payment_paygate_notifyredirect' ) === 'notify' ) { // Notify PayGate that information has been received echo 'OK'; - - // Check for test / live modes - $this->testmode = $this->config->get( 'payment_paygate_testmode' ) === 'test'; - $paygateID = $this->testmode ? '10011072130' : filter_var( - $this->config->get( 'payment_paygate_merchant_id' ), - FILTER_SANITIZE_STRING - ); - $encryption_key = $this->testmode ? 'secret' : $this->config->get( 'payment_paygate_merchant_key' ); - - $errors = false; - if ( isset( $ERROR ) ) { - $errors = true; - } - - $transaction_status = ''; - $order_id = ''; - $pay_method_detail = ''; - $pay_method_desc = ''; - $checkSumParams = ''; - $notify_checksum = ''; - $post_data = ''; + + $errors = isset($EERROR)?true:false; if ( !$errors ) { - foreach ( $_POST as $key => $val ) { - if ( $key == 'PAYGATE_ID' ) { - $checkSumParams .= $paygateID; - } - - if ( $key != 'CHECKSUM' && $key != 'PAYGATE_ID' ) { - $checkSumParams .= $val; - } - - if ( $key == 'CHECKSUM' ) { - $notify_checksum = $val; - } - - if ( $key == 'TRANSACTION_STATUS' ) { - $transaction_status = $val; - } - - if ( $key == 'USER1' ) { - $order_id = $val; - } - - if ( $key == 'PAY_METHOD_DETAIL' ) { - $pay_method_desc = ', using a payment method of ' . $val; - } - } - - $checkSumParams .= $encryption_key; - $checkSumParams = md5( $checkSumParams ); - if ( $checkSumParams != $notify_checksum ) { - $errors = true; - } - - $orderStatusId = 7; - + $postData = $this->prepareCheckSumParams(); + $checkSumParams = $postData['checkSumParams']; + $notify_checksum = $postData['notify_checksum']; + $transaction_status = $postData['transaction_status']; + $order_id = $postData['order_id']; + $pay_method_desc = $postData['pay_method_desc']; + + if ( $checkSumParams != $notify_checksum ) { + $errors = true; + } + if ( !$errors ) { - if ( $transaction_status == 0 ) { - $orderStatusId = 1; - $statusDesc = 'pending'; - } elseif ( $transaction_status == 1 ) { - $orderStatusId = $this->config->get( 'payment_paygate_success_order_status_id' ); - $statusDesc = 'approved'; - } elseif ( $transaction_status == 2 ) { - $orderStatusId = $this->config->get( 'payment_paygate_failed_order_status_id' ); - $statusDesc = 'declined'; - } elseif ( $transaction_status == 4 ) { - $orderStatusId = $this->config->get( 'payment_paygate_cancelled_order_status_id' ); - $statusDesc = 'cancelled'; - } - + $txn_data = $this->getOrderStatusDesc($transaction_status); + $orderStatusId = $txn_data['orderStatusId']; + $statusDesc = $txn_data['statusDesc']; + $resultsComment = "Notify response from PayGate with a status of " . $statusDesc . $pay_method_desc; - $this->load->model( 'checkout/order' ); + $this->load->model( self::CHECKOUT_MODEL ); if ( $statusDesc == 'approved' ) { $this->cart->clear(); } @@ -623,11 +674,79 @@ public function notify_handler() } } } + + public function prepareCheckSumParams(){ + + // Check for test / live modes + $this->testmode = $this->config->get( 'payment_paygate_testmode' ) === 'test'; + $paygateID = $this->getPaygateId(); + $encryption_key = $this->getEncryptionkey(); + + $checkSumParams = ''; + + $postData = array(); + foreach ( $_POST as $key => $val ) { + if ( $key == 'PAYGATE_ID' ) { + $checkSumParams .= $paygateID; + } + + if ( $key != 'CHECKSUM' && $key != 'PAYGATE_ID' ) { + $checkSumParams .= $val; + } + + if ( $key == 'CHECKSUM' ) { + $notify_checksum = $val; + } + + if ( $key == 'TRANSACTION_STATUS' ) { + $transaction_status = $val; + } + + if ( $key == 'USER1' ) { + $order_id = $val; + } + + if ( $key == 'PAY_METHOD_DETAIL' ) { + $pay_method_desc = ', using a payment method of ' . $val; + } + } + + $checkSumParams .= $encryption_key; + $checkSumParams = md5( $checkSumParams ); + + $postData['checkSumParams'] = $checkSumParams; + $postData['notify_checksum'] = $notify_checksum; + $postData['transaction_status'] = $transaction_status; + $postData['order_id'] = $order_id; + $postData['pay_method_desc'] = $pay_method_desc; + return $postData; + } + + public function getOrderStatusDesc($transaction_status){ + $txn_data = array(); + if ( $transaction_status == 0 ) { + $orderStatusId = 1; + $statusDesc = 'pending'; + } elseif ( $transaction_status == 1 ) { + $orderStatusId = $this->config->get( 'payment_paygate_success_order_status_id' ); + $statusDesc = 'approved'; + } elseif ( $transaction_status == 2 ) { + $orderStatusId = $this->config->get( 'payment_paygate_failed_order_status_id' ); + $statusDesc = 'declined'; + } elseif ( $transaction_status == 4 ) { + $orderStatusId = $this->config->get( 'payment_paygate_cancelled_order_status_id' ); + $statusDesc = 'cancelled'; + } + + $txn_data['orderStatusId'] = $orderStatusId; + $txn_data['statusDesc'] = $statusDesc; + return $txn_data; + } public function confirm() { if ( $this->session->data['payment_method']['code'] == 'paygate' ) { - $this->load->model( 'checkout/order' ); + $this->load->model( self::CHECKOUT_MODEL ); $comment = 'Redirected to PayGate'; $this->model_checkout_order->addOrderHistory( $this->session->data['order_id'], @@ -643,8 +762,8 @@ public function before_redirect() $json = array(); if ( $this->session->data['payment_method']['code'] == 'paygate' ) { - $this->load->model( 'checkout/order' ); - $comment = 'Before Redirected to PayGate'; + $this->load->model( self::CHECKOUT_MODEL ); + /************** $comment = 'Before Redirect to PayGate'; ***********/ $this->model_checkout_order->addOrderHistory( $this->session->data['order_id'], 1 ); $json['answer'] = 'success'; } diff --git a/upload/catalog/language/en-gb/extension/payment/paygate.php b/upload/catalog/language/en-gb/extension/payment/paygate.php index 08a06e7..d267d90 100755 --- a/upload/catalog/language/en-gb/extension/payment/paygate.php +++ b/upload/catalog/language/en-gb/extension/payment/paygate.php @@ -9,4 +9,4 @@ // Text $_['text_title'] = 'PayGate'; -$_['text_paygate_checkout'] = 'Pay now using PayGate'; +$_['text_paygate_checkout'] = 'Pay via PayGate'; \ No newline at end of file diff --git a/upload/catalog/model/extension/payment/paygate.php b/upload/catalog/model/extension/payment/paygate.php index bd6eb79..7a4369b 100755 --- a/upload/catalog/model/extension/payment/paygate.php +++ b/upload/catalog/model/extension/payment/paygate.php @@ -31,7 +31,7 @@ public function getMethod( $address, $total ) if ( $status ) { $method_data = array( 'code' => 'paygate', - 'title' => $this->language->get( 'text_paygate_checkout' ), + 'title' => $this->language->get( 'text_paygate_checkout' ) . ' PayGate', 'terms' => '', 'sort_order' => $this->config->get( 'payment_paygate_sort_order' ), ); diff --git a/upload/catalog/view/theme/default/template/extension/payment/paygate.twig b/upload/catalog/view/theme/default/template/extension/payment/paygate.twig deleted file mode 100755 index 69aa5e8..0000000 --- a/upload/catalog/view/theme/default/template/extension/payment/paygate.twig +++ /dev/null @@ -1,27 +0,0 @@ -{# - # Copyright (c) 2020 PayGate (Pty) Ltd - # - # Author: App Inlet (Pty) Ltd - # - # Released under the GNU General Public License - #} - -
-
-
- - -
-
-
-
-
- - - -
-
diff --git a/upload/catalog/view/theme/default/template/extension/payment/paygate_redirect.twig b/upload/catalog/view/theme/default/template/extension/payment/paygate_redirect.twig deleted file mode 100755 index d188dfc..0000000 --- a/upload/catalog/view/theme/default/template/extension/payment/paygate_redirect.twig +++ /dev/null @@ -1,36 +0,0 @@ -{# - # Copyright (c) 2020 PayGate (Pty) Ltd - # - # Author: App Inlet (Pty) Ltd - # - # Released under the GNU General Public License - #} -
- - -
-
-
-
-
-