From 51c1ccb63e5721bbd062855ac7e14d4860db544f Mon Sep 17 00:00:00 2001 From: NochexDevTeam <36759878+NochexDevTeam@users.noreply.github.com> Date: Fri, 23 Feb 2018 14:29:50 +0000 Subject: [PATCH] Add files via upload --- extensions/nochex/config/index.html | 10 + extensions/nochex/config/nochex.php | 48 +++++ .../nochex/controllers/Admin_nochex.php | 141 ++++++++++++ extensions/nochex/controllers/Nochex.php | 202 ++++++++++++++++++ extensions/nochex/controllers/index.html | 10 + extensions/nochex/index.html | 10 + extensions/nochex/language/english/index.html | 10 + .../nochex/language/english/nochex_lang.php | 29 +++ extensions/nochex/language/index.html | 10 + extensions/nochex/models/Nochex_model.php | 15 ++ extensions/nochex/models/index.html | 10 + extensions/nochex/views/Admin_nochex.php | 108 ++++++++++ extensions/nochex/views/index.html | 10 + extensions/nochex/views/nochex.php | 15 ++ extensions/nochex/views/nochexForm.php | 35 +++ 15 files changed, 663 insertions(+) create mode 100644 extensions/nochex/config/index.html create mode 100644 extensions/nochex/config/nochex.php create mode 100644 extensions/nochex/controllers/Admin_nochex.php create mode 100644 extensions/nochex/controllers/Nochex.php create mode 100644 extensions/nochex/controllers/index.html create mode 100644 extensions/nochex/index.html create mode 100644 extensions/nochex/language/english/index.html create mode 100644 extensions/nochex/language/english/nochex_lang.php create mode 100644 extensions/nochex/language/index.html create mode 100644 extensions/nochex/models/Nochex_model.php create mode 100644 extensions/nochex/models/index.html create mode 100644 extensions/nochex/views/Admin_nochex.php create mode 100644 extensions/nochex/views/index.html create mode 100644 extensions/nochex/views/nochex.php create mode 100644 extensions/nochex/views/nochexForm.php diff --git a/extensions/nochex/config/index.html b/extensions/nochex/config/index.html new file mode 100644 index 0000000..065d2da --- /dev/null +++ b/extensions/nochex/config/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/extensions/nochex/config/nochex.php b/extensions/nochex/config/nochex.php new file mode 100644 index 0000000..0d9cf3b --- /dev/null +++ b/extensions/nochex/config/nochex.php @@ -0,0 +1,48 @@ + The name of your extension +| 'version' => The current version number of the extension, such as 1.0 or 1.0.3. +| 'type' => The type of your extension, could be module, payment or widget +| 'title' => The title of your extension, a readable name +| 'author' => The name of the extension author. More than one author may be listed, separated by comma. +| 'description' => A short description of the extension. Keep this description to fewer than 128 characters. +| 'settings' => Whether to enable/disable extension admin settings page. +| +*/ +$config['extension_meta'] = array( + 'name' => 'nochex', + 'version' => '1.0', + 'type' => 'payment', + 'title' => 'Nochex', + 'author' => 'Nochex Ltd', + 'description' => 'This extension will allow you to accept payments using Nochex.', + 'settings' => TRUE, +); + +/* +|-------------------------------------------------------------------------- +| Extension Permission (Optional) +|-------------------------------------------------------------------------- +| +| The extension permission rule that will be saved then assigned to the current staff group +| installing the extension +| +| 'name' => The name of the permission e.g Module.ModuleName or Payment.ModuleName +| 'action' => The extension permitted action array (access, manage, add, delete) +| 'description' => A short description of the permission. Keep this description +| to fewer than 128 characters. +| +*/ +$config['extension_permission'] = array( + 'name' => 'Payment.Nochex', + 'action' => array('manage'), + 'description' => 'Ability to manage Nochex Payment module', +); \ No newline at end of file diff --git a/extensions/nochex/controllers/Admin_nochex.php b/extensions/nochex/controllers/Admin_nochex.php new file mode 100644 index 0000000..daf8922 --- /dev/null +++ b/extensions/nochex/controllers/Admin_nochex.php @@ -0,0 +1,141 @@ +lang->load('nochex/nochex'); + + $this->user->restrict('Payment.Nochex'); + + $this->load->model('Statuses_model'); + + $title = (isset($module['title'])) ? $module['title'] : $this->lang->line('_text_title'); + + $this->template->setTitle('Payment: ' . $title); + $this->template->setHeading('Payment: ' . $title); + $this->template->setButton($this->lang->line('button_save'), array('class' => 'btn btn-primary', 'onclick' => '$(\'#edit-form\').submit();')); + $this->template->setButton($this->lang->line('button_save_close'), array('class' => 'btn btn-default', 'onclick' => 'saveClose();')); + $this->template->setButton($this->lang->line('button_icon_back'), array('class' => 'btn btn-default', 'href' => site_url('extensions'))); + + $ext_data = array(); + if ( ! empty($module['ext_data']) AND is_array($module['ext_data'])) { + $ext_data = $module['ext_data']; + } + + if (isset($this->input->post['title'])) { + $data['title'] = $this->input->post('title'); + } else if (isset($ext_data['title'])) { + $data['title'] = $ext_data['title']; + } else { + $data['title'] = $title; + } + + if (isset($this->input->post['merchantID'])) { + $data['merchantID'] = $this->input->post('merchantID'); + } else if (isset($ext_data['merchantID'])) { + $data['merchantID'] = $ext_data['merchantID']; + } else { + $data['merchantID'] = ''; + } + + + if (isset($this->input->post['api_mode'])) { + $data['api_mode'] = $this->input->post('api_mode'); + } else if (isset($ext_data['api_mode'])) { + $data['api_mode'] = $ext_data['api_mode']; + } else { + $data['api_mode'] = ''; + } + + if (isset($ext_data['order_total'])) { + $data['order_total'] = $ext_data['order_total']; + } else { + $data['order_total'] = ''; + } + + if (isset($this->input->post['order_status'])) { + $data['order_status'] = $this->input->post('order_status'); + } else if (isset($ext_data['order_status'])) { + $data['order_status'] = $ext_data['order_status']; + } else { + $data['order_status'] = ''; + } + + if (isset($this->input->post['paid_order_status'])) { + $data['paid_order_status'] = $this->input->post('paid_order_status'); + } else if (isset($ext_data['paid_order_status'])) { + $data['paid_order_status'] = $ext_data['paid_order_status']; + } else { + $data['paid_order_status'] = ''; + } + + + if (isset($this->input->post['priority'])) { + $data['priority'] = $this->input->post('priority'); + } else if (isset($ext_data['priority'])) { + $data['priority'] = $ext_data['priority']; + } else { + $data['priority'] = ''; + } + + if (isset($this->input->post['status'])) { + $data['status'] = $this->input->post('status'); + } else if (isset($ext_data['status'])) { + $data['status'] = $ext_data['status']; + } else { + $data['status'] = ''; + } + + $data['statuses'] = array(); + $results = $this->Statuses_model->getStatuses('order'); + foreach ($results as $result) { + $data['statuses'][] = array( + 'status_id' => $result['status_id'], + 'status_name' => $result['status_name'], + ); + } + + if ($this->input->post() AND $this->_updateNochex() === TRUE) { + if ($this->input->post('save_close') === '1') { + redirect('extensions'); + } + + redirect('extensions/edit/payment/nochex'); + } + + return $this->load->view('nochex/Admin_nochex', $data, TRUE); + } + + private function _updateNochex() { + $this->user->restrict('Payment.Nochex.Manage'); + + if ($this->input->post() AND $this->validateForm() === TRUE) { + + if ($this->Extensions_model->updateExtension('payment', 'nochex', $this->input->post())) { + $this->alert->set('success', sprintf($this->lang->line('alert_success'), $this->lang->line('_text_title') . ' payment ' . $this->lang->line('text_updated'))); + } else { + $this->alert->set('warning', sprintf($this->lang->line('alert_error_nothing'), $this->lang->line('text_updated'))); + } + + return TRUE; + } + } + + private function validateForm() { + $this->form_validation->set_rules('title', 'lang:label_title', 'xss_clean|trim|required|min_length[2]|max_length[128]'); + $this->form_validation->set_rules('api_mode', 'lang:label_api_mode', 'xss_clean|trim|required'); + $this->form_validation->set_rules('order_total', 'lang:label_order_total', 'xss_clean|trim|required|numeric'); + $this->form_validation->set_rules('order_status', 'lang:label_order_status', 'xss_clean|trim|required|integer'); + $this->form_validation->set_rules('paid_order_status', 'lang:label_paid_order_status', 'xss_clean|trim|required|integer'); + $this->form_validation->set_rules('status', 'lang:label_status', 'xss_clean|trim|required|integer'); + + if ($this->form_validation->run() === TRUE) { + return TRUE; + } else { + return FALSE; + } + } +} + +/* End of file nochex.php */ +/* Location: ./extensions/nochex/controllers/nochex.php */ \ No newline at end of file diff --git a/extensions/nochex/controllers/Nochex.php b/extensions/nochex/controllers/Nochex.php new file mode 100644 index 0000000..c0de091 --- /dev/null +++ b/extensions/nochex/controllers/Nochex.php @@ -0,0 +1,202 @@ +load->model('Orders_model'); + } + + + public function index() { + //check if file exists in views folder + if ( ! file_exists(EXTPATH .'nochex/views/nochex.php')) { + show_404(); + /* Whoops, show 404 error page!*/ + } + + $payment = $this->extension->getPayment('nochex'); + $order_data = $this->session->userdata('order_data'); + + // START of retrieving lines from language file to pass to view. + $data['code'] = $payment['name']; /* nochex */ + $data['title'] = !empty($payment['ext_data']['title']) ? $payment['ext_data']['title'] : $payment['title']; /* Nochex */ + // END of retrieving lines from language file to send to view. + + // retrieve order details from session userdata + $data['payment'] = !empty($order_data['payment']) ? $order_data['payment'] : ''; + $data['minimum_order_total'] = is_numeric($payment['ext_data']['order_total']) ? $payment['ext_data']['order_total'] : 0; + $data['order_total'] = $this->cart->total(); + + // pass array $data and load view files + return $this->load->view('nochex/nochex', $data); + } + + public function confirm() { + $this->lang->load('nochex/nochex'); + + $order_data = $this->session->userdata('order_data'); // retrieve order details from session userdata + $cart_contents = $this->session->userdata('cart_contents'); // retrieve cart contents + + if (empty($order_data) AND empty($cart_contents)) { + return FALSE; + } + + /* Checks if the order data (Payment data) is not empty */ + if (!empty($order_data['ext_payment']) AND !empty($order_data['payment']) AND $order_data['payment'] == 'nochex') { // else if payment method is cash on delivery + + /* If not empty - collect all order data and send it to the Nochex Payment Form */ + $ext_payment_data = !empty($order_data['ext_payment']['ext_data']) ? $order_data['ext_payment']['ext_data'] : array(); + + if (!empty($ext_payment_data['order_total']) AND $cart_contents['order_total'] < $ext_payment_data['order_total']) { + $this->alert->set('danger', $this->lang->line('alert_min_total')); + return FALSE; + } + + if (isset($ext_payment_data['order_status']) AND is_numeric($ext_payment_data['order_status'])) { + $order_data['status_id'] = $ext_payment_data['order_status']; + } + + $this->load->model('Orders_model'); + + //check if Nochex Payment Form exists in views folder + if ( ! file_exists(EXTPATH .'nochex/views/nochexForm.php')) { + show_404(); + // Whoops, show 404 error page! + } + + $this->load->model('Addresses_model'); + $address = $this->Addresses_model->getAddress($order_data['customer_id'], $order_data['address_id']); + + $itemCollection = ""; + foreach (array_keys($this->cart->contents()) as $key => $rowid) { // loop through cart items to create items name-value pairs data to be sent to paypal + foreach ($this->cart->contents() as $cart_item) { + $itemCollection .= "".$cart_item["name"]."".$cart_item["qty"]."".number_format($cart_item["price"],2).""; + } + } + $itemCollection .= ""; + + if ($order_data["ext_payment"]["ext_data"]["api_mode"] == "sandbox"){ + $testTransaction = "100"; + }else{ + $testTransaction = ""; + } + + if($order_data["order_type"] == "1"){ + $ordType = "Delivery"; + }else{ + $ordType = "Collection"; + } + + $callback_uri = 'nochex/authorize'; + $cancel_uri = 'nochex/cancel'; + $success_uri = 'checkout/success'; + + $fmData['billing_fullname'] = $order_data["first_name"] . ", " . $order_data["last_name"]; + $fmData['billing_address'] = $address['address_1']; + $fmData['billing_city'] = $address['city']; + $fmData['billing_postcode'] = $address['postcode']; + $fmData['email_address'] = $order_data["email"]; + $fmData['customer_telephone_number'] = $order_data["telephone"]; + $fmData['order_id'] = $order_data["order_id"]; + $fmData['order_asap_time'] = $order_data["order_asap_time"]; + $fmData['order_time_type'] = $ordType . " (" . $order_data["order_time_type"] . ")"; + $fmData['order_time'] = $order_data["order_time"]; + $fmData['order_type'] = $order_data["order_type"]; + $fmData['xml_item_collection'] = $itemCollection; + $fmData['merchant_id'] = $order_data["ext_payment"]["ext_data"]["merchantID"]; + $fmData['test_transaction'] = $testTransaction; + $fmData['amount'] = number_format($cart_contents["cart_total"], 2); + $fmData['callback_url'] = site_url($callback_uri); + $fmData['cancel_url'] = site_url($cancel_uri); + $fmData['success_url'] = site_url($success_uri); + $fmData['optional_1'] = $order_data["ext_payment"]["ext_data"]["paid_order_status"]; + $fmData['delivery_fullname'] = $order_data["first_name"] . ", " . $order_data["last_name"]; + $fmData['delivery_address'] = $address['address_1']; + $fmData['delivery_city'] = $address['city']; + $fmData['delivery_postcode'] = $address['postcode']; + + /* Load Payment Form */ + return $this->load->view('nochex/nochexForm', $fmData); + + } + } + + public function authorize() { + /* Nochex APC */ + $order_data = $this->session->userdata('order_data'); + $cart_contents = $this->session->userdata('cart_contents'); + + if($_POST){ + // Get the POST information from Nochex server + $postvars = http_build_query($_POST); + + $url = "https://www.nochex.com/apcnet/apc.aspx"; + $ch = curl_init (); + curl_setopt ($ch, CURLOPT_URL, $url); + curl_setopt ($ch, CURLOPT_POST, true); + curl_setopt ($ch, CURLOPT_POSTFIELDS, $postvars); + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); + $output = curl_exec ($ch); + curl_close ($ch); + + // Put the variables in a printable format for the email + $debug = "IP -> " . $_SERVER['REMOTE_ADDR'] ."\r\n\r\nPOST DATA:\r\n"; + foreach($_POST as $Index => $Value) + $debug .= "".$Index ."->". $Value."\r\n"; + $debug .= "\r\nRESPONSE:\r\n$output"; + + //If statement - checks the response to see if AUTHORISED is present if it isn’t a failure message is displayed + if ($output == "AUTHORISED") { + $msg = "APC was AUTHORISED. "; // if AUTHORISED was found in the response then it was successful + }else { + $msg = "APC was not AUTHORISED. \r\n $debug"; // displays debug message (If APC is not authorised) + } + + $msg .= "This was a " . $_POST['status'] . " transaction, (Transaction ID = " . $_POST['transaction_id'] . ")"; + + /* adds a order history status / comment containing fields received from Nochex */ + $this->load->model('Statuses_model'); + + $order_history = array( + 'object_id' => $_POST['order_id'], + 'status_id' => $_POST['custom'], + 'notify' => '0', + 'comment' => $msg, + 'date_added' => mdate('%Y-%m-%d %H:%i:%s', time()), + ); + + $this->Statuses_model->addStatusHistory('order', $order_history); + + /* Gets and sets data to complete the order */ + $order_status = array( + 'order_status' => $_POST['custom'], + 'notify' => '0', + 'status_comment' => $msg, + ); + + $this->load->model('Orders_model'); + $order_data['status_id'] = $_POST['custom']; + $order_data['comment'] .= $_POST['comment']; + $this->Orders_model->completeOrder($_POST['order_id'], $order_data, $cart_contents); + + }else{ + show_404(); + } + } + + + public function cancel() { + /* Cancelled Order - Clear all cache */ + $this->alert->set('alert', "Your order has been cancelled!"); + + $this->session->unset_userdata('cart_contents'); + $this->session->unset_userdata('order_data'); + + redirect('checkout'); + } +} + +/* End of file nochex.php */ +/* Location: ./extensions/nochex/controllers/nochex.php */ \ No newline at end of file diff --git a/extensions/nochex/controllers/index.html b/extensions/nochex/controllers/index.html new file mode 100644 index 0000000..065d2da --- /dev/null +++ b/extensions/nochex/controllers/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/extensions/nochex/index.html b/extensions/nochex/index.html new file mode 100644 index 0000000..065d2da --- /dev/null +++ b/extensions/nochex/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/extensions/nochex/language/english/index.html b/extensions/nochex/language/english/index.html new file mode 100644 index 0000000..065d2da --- /dev/null +++ b/extensions/nochex/language/english/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/extensions/nochex/language/english/nochex_lang.php b/extensions/nochex/language/english/nochex_lang.php new file mode 100644 index 0000000..72289b7 --- /dev/null +++ b/extensions/nochex/language/english/nochex_lang.php @@ -0,0 +1,29 @@ +'; +$lang['alert_error_server'] = '

Sorry an error occurred, please try again

'; + +/* End of file nochex_lang.php */ +/* Location: ./extensions/nochex/language/english/nochex_lang.php */ + diff --git a/extensions/nochex/language/index.html b/extensions/nochex/language/index.html new file mode 100644 index 0000000..065d2da --- /dev/null +++ b/extensions/nochex/language/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/extensions/nochex/models/Nochex_model.php b/extensions/nochex/models/Nochex_model.php new file mode 100644 index 0000000..8cd66c3 --- /dev/null +++ b/extensions/nochex/models/Nochex_model.php @@ -0,0 +1,15 @@ +load->library('cart'); + $this->load->library('currency'); + } + +} + +/* End of file Nochex.php */ +/* Location: ./extensions/Nochex/models/Nochex.php */ \ No newline at end of file diff --git a/extensions/nochex/models/index.html b/extensions/nochex/models/index.html new file mode 100644 index 0000000..065d2da --- /dev/null +++ b/extensions/nochex/models/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/extensions/nochex/views/Admin_nochex.php b/extensions/nochex/views/Admin_nochex.php new file mode 100644 index 0000000..2d3d3fe --- /dev/null +++ b/extensions/nochex/views/Admin_nochex.php @@ -0,0 +1,108 @@ +
+
+
+ +
+
+
+
+
+ +
+ + ', ''); ?> +
+
+
+ +
+ + ', ''); ?> +
+
+
+ +
+
+ + + + + + + +
+ ', ''); ?> +
+
+
+ +
+ + ', ''); ?> +
+
+
+ +
+ + ', ''); ?> +
+
+
+ +
+ + ', ''); ?> +
+
+
+ +
+ + ', ''); ?> +
+
+
+ +
+
+ + + + + + + +
+ ', ''); ?> +
+
+
+
+
+
+
\ No newline at end of file diff --git a/extensions/nochex/views/index.html b/extensions/nochex/views/index.html new file mode 100644 index 0000000..065d2da --- /dev/null +++ b/extensions/nochex/views/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/extensions/nochex/views/nochex.php b/extensions/nochex/views/nochex.php new file mode 100644 index 0000000..b5b7587 --- /dev/null +++ b/extensions/nochex/views/nochex.php @@ -0,0 +1,15 @@ +
+ + = $order_total) { ?> +
+ +
\ No newline at end of file diff --git a/extensions/nochex/views/nochexForm.php b/extensions/nochex/views/nochexForm.php new file mode 100644 index 0000000..073be9a --- /dev/null +++ b/extensions/nochex/views/nochexForm.php @@ -0,0 +1,35 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + " name="description" /> + +
+ + + + + \ No newline at end of file