aboutsummaryrefslogtreecommitdiffstats
path: root/public/admin/controller/extension/payment
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-08-18 21:14:58 -0500
committerJesús <heckyel@hyperbola.info>2019-08-18 21:14:58 -0500
commit2eed7b082f83630301e51f57ca8394de228a8605 (patch)
tree1d19962d22d30f99317d9276e4bae7744fc93fc2 /public/admin/controller/extension/payment
downloadlibrecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz
librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz
librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip
first commit
Diffstat (limited to 'public/admin/controller/extension/payment')
-rw-r--r--public/admin/controller/extension/payment/alipay.php153
-rw-r--r--public/admin/controller/extension/payment/alipay_cross.php163
-rw-r--r--public/admin/controller/extension/payment/amazon_login_pay.php590
-rw-r--r--public/admin/controller/extension/payment/authorizenet_aim.php154
-rw-r--r--public/admin/controller/extension/payment/authorizenet_sim.php145
-rw-r--r--public/admin/controller/extension/payment/bank_transfer.php131
-rw-r--r--public/admin/controller/extension/payment/bluepay_hosted.php351
-rw-r--r--public/admin/controller/extension/payment/bluepay_redirect.php331
-rw-r--r--public/admin/controller/extension/payment/cardconnect.php501
-rw-r--r--public/admin/controller/extension/payment/cardinity.php304
-rw-r--r--public/admin/controller/extension/payment/cheque.php115
-rw-r--r--public/admin/controller/extension/payment/cod.php99
-rw-r--r--public/admin/controller/extension/payment/divido.php215
-rw-r--r--public/admin/controller/extension/payment/eway.php371
-rw-r--r--public/admin/controller/extension/payment/firstdata.php352
-rw-r--r--public/admin/controller/extension/payment/firstdata_remote.php482
-rw-r--r--public/admin/controller/extension/payment/free_checkout.php83
-rw-r--r--public/admin/controller/extension/payment/g2apay.php302
-rw-r--r--public/admin/controller/extension/payment/globalpay.php408
-rw-r--r--public/admin/controller/extension/payment/globalpay_remote.php372
-rw-r--r--public/admin/controller/extension/payment/klarna_account.php329
-rw-r--r--public/admin/controller/extension/payment/klarna_checkout.php859
-rw-r--r--public/admin/controller/extension/payment/klarna_invoice.php201
-rw-r--r--public/admin/controller/extension/payment/laybuy.php1121
-rw-r--r--public/admin/controller/extension/payment/liqpay.php143
-rw-r--r--public/admin/controller/extension/payment/nochex.php149
-rw-r--r--public/admin/controller/extension/payment/paymate.php139
-rw-r--r--public/admin/controller/extension/payment/paypoint.php127
-rw-r--r--public/admin/controller/extension/payment/payza.php133
-rw-r--r--public/admin/controller/extension/payment/perpetual_payments.php137
-rw-r--r--public/admin/controller/extension/payment/pilibaba.php343
-rw-r--r--public/admin/controller/extension/payment/pp_braintree.php1132
-rw-r--r--public/admin/controller/extension/payment/pp_express.php1347
-rw-r--r--public/admin/controller/extension/payment/pp_payflow.php177
-rw-r--r--public/admin/controller/extension/payment/pp_payflow_iframe.php483
-rw-r--r--public/admin/controller/extension/payment/pp_pro.php159
-rw-r--r--public/admin/controller/extension/payment/pp_pro_iframe.php771
-rw-r--r--public/admin/controller/extension/payment/pp_standard.php187
-rw-r--r--public/admin/controller/extension/payment/realex.php408
-rw-r--r--public/admin/controller/extension/payment/realex_remote.php371
-rw-r--r--public/admin/controller/extension/payment/sagepay_direct.php327
-rw-r--r--public/admin/controller/extension/payment/sagepay_server.php328
-rw-r--r--public/admin/controller/extension/payment/sagepay_us.php131
-rw-r--r--public/admin/controller/extension/payment/securetrading_pp.php475
-rw-r--r--public/admin/controller/extension/payment/securetrading_ws.php570
-rw-r--r--public/admin/controller/extension/payment/skrill.php157
-rw-r--r--public/admin/controller/extension/payment/squareup.php1079
-rw-r--r--public/admin/controller/extension/payment/twocheckout.php143
-rw-r--r--public/admin/controller/extension/payment/web_payment_software.php142
-rw-r--r--public/admin/controller/extension/payment/wechat_pay.php177
-rw-r--r--public/admin/controller/extension/payment/worldpay.php287
51 files changed, 18154 insertions, 0 deletions
diff --git a/public/admin/controller/extension/payment/alipay.php b/public/admin/controller/extension/payment/alipay.php
new file mode 100644
index 0000000..ce549b1
--- /dev/null
+++ b/public/admin/controller/extension/payment/alipay.php
@@ -0,0 +1,153 @@
+<?php
+class ControllerExtensionPaymentAlipay extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/alipay');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_alipay', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['app_id'])) {
+ $data['error_app_id'] = $this->error['app_id'];
+ } else {
+ $data['error_app_id'] = '';
+ }
+
+ if (isset($this->error['merchant_private_key'])) {
+ $data['error_merchant_private_key'] = $this->error['merchant_private_key'];
+ } else {
+ $data['error_merchant_private_key'] = '';
+ }
+
+ if (isset($this->error['alipay_public_key'])) {
+ $data['error_alipay_public_key'] = $this->error['alipay_public_key'];
+ } else {
+ $data['error_alipay_public_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/alipay', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/alipay', '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_alipay_app_id'])) {
+ $data['payment_alipay_app_id'] = $this->request->post['payment_alipay_app_id'];
+ } else {
+ $data['payment_alipay_app_id'] = $this->config->get('payment_alipay_app_id');
+ }
+
+ if (isset($this->request->post['payment_alipay_merchant_private_key'])) {
+ $data['payment_alipay_merchant_private_key'] = $this->request->post['payment_alipay_merchant_private_key'];
+ } else {
+ $data['payment_alipay_merchant_private_key'] = $this->config->get('payment_alipay_merchant_private_key');
+ }
+
+ if (isset($this->request->post['payment_alipay_alipay_public_key'])) {
+ $data['payment_alipay_alipay_public_key'] = $this->request->post['payment_alipay_alipay_public_key'];
+ } else {
+ $data['payment_alipay_alipay_public_key'] = $this->config->get('payment_alipay_alipay_public_key');
+ }
+
+ if (isset($this->request->post['payment_alipay_total'])) {
+ $data['payment_alipay_total'] = $this->request->post['payment_alipay_total'];
+ } else {
+ $data['payment_alipay_total'] = $this->config->get('payment_alipay_total');
+ }
+
+ if (isset($this->request->post['payment_alipay_order_status_id'])) {
+ $data['payment_alipay_order_status_id'] = $this->request->post['payment_alipay_order_status_id'];
+ } else {
+ $data['payment_alipay_order_status_id'] = $this->config->get('payment_alipay_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_alipay_geo_zone_id'])) {
+ $data['payment_alipay_geo_zone_id'] = $this->request->post['payment_alipay_geo_zone_id'];
+ } else {
+ $data['payment_alipay_geo_zone_id'] = $this->config->get('payment_alipay_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_alipay_test'])) {
+ $data['payment_alipay_test'] = $this->request->post['payment_alipay_test'];
+ } else {
+ $data['payment_alipay_test'] = $this->config->get('payment_alipay_test');
+ }
+
+ if (isset($this->request->post['payment_alipay_status'])) {
+ $data['payment_alipay_status'] = $this->request->post['payment_alipay_status'];
+ } else {
+ $data['payment_alipay_status'] = $this->config->get('payment_alipay_status');
+ }
+
+ if (isset($this->request->post['payment_alipay_sort_order'])) {
+ $data['payment_alipay_sort_order'] = $this->request->post['payment_alipay_sort_order'];
+ } else {
+ $data['payment_alipay_sort_order'] = $this->config->get('payment_alipay_sort_order');
+ }
+
+ $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/alipay', $data));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/alipay')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_alipay_app_id']) {
+ $this->error['app_id'] = $this->language->get('error_app_id');
+ }
+
+ if (!$this->request->post['payment_alipay_merchant_private_key']) {
+ $this->error['merchant_private_key'] = $this->language->get('error_merchant_private_key');
+ }
+
+ if (!$this->request->post['payment_alipay_alipay_public_key']) {
+ $this->error['alipay_public_key'] = $this->language->get('error_alipay_public_key');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/alipay_cross.php b/public/admin/controller/extension/payment/alipay_cross.php
new file mode 100644
index 0000000..2026023
--- /dev/null
+++ b/public/admin/controller/extension/payment/alipay_cross.php
@@ -0,0 +1,163 @@
+<?php
+class ControllerExtensionPaymentAlipayCross extends Controller {
+ private $error = array();
+ private $currencies = array('GBP', 'HKD', 'USD', 'CHF', 'SGD', 'SEK', 'DKK', 'NOK', 'JPY', 'CAD', 'AUD', 'EUR', 'NZD', 'KRW', 'THB');
+
+ public function index() {
+ $this->load->language('extension/payment/alipay_cross');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_alipay_cross', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['app_id'])) {
+ $data['error_app_id'] = $this->error['app_id'];
+ } else {
+ $data['error_app_id'] = '';
+ }
+
+ if (isset($this->error['merchant_private_key'])) {
+ $data['error_merchant_private_key'] = $this->error['merchant_private_key'];
+ } else {
+ $data['error_merchant_private_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/alipay_cross', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/alipay_cross', '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_alipay_cross_app_id'])) {
+ $data['payment_alipay_cross_app_id'] = $this->request->post['payment_alipay_cross_app_id'];
+ } else {
+ $data['payment_alipay_cross_app_id'] = $this->config->get('payment_alipay_cross_app_id');
+ }
+
+ if (isset($this->request->post['payment_alipay_cross_merchant_private_key'])) {
+ $data['payment_alipay_cross_merchant_private_key'] = $this->request->post['payment_alipay_cross_merchant_private_key'];
+ } else {
+ $data['payment_alipay_cross_merchant_private_key'] = $this->config->get('payment_alipay_cross_merchant_private_key');
+ }
+
+ if (isset($this->request->post['payment_alipay_cross_currency'])) {
+ $data['payment_alipay_cross_currency'] = $this->request->post['payment_alipay_cross_currency'];
+ } else {
+ $data['payment_alipay_cross_currency'] = $this->config->get('payment_alipay_cross_currency');
+ }
+
+ $this->load->model('localisation/currency');
+
+ $currencies = $this->model_localisation_currency->getCurrencies();
+ $data['currencies'] = array();
+ foreach ($currencies as $currency) {
+ if (in_array($currency['code'], $this->currencies)) {
+ $data['currencies'][] = array(
+ 'code' => $currency['code'],
+ 'title' => $currency['title']
+ );
+ }
+ }
+
+ if (isset($this->request->post['payment_alipay_cross_test'])) {
+ $data['payment_alipay_cross_test'] = $this->request->post['payment_alipay_cross_test'];
+ } else {
+ $data['payment_alipay_cross_test'] = $this->config->get('payment_alipay_cross_test');
+ }
+
+ if (isset($this->request->post['payment_alipay_cross_total'])) {
+ $data['payment_alipay_cross_total'] = $this->request->post['payment_alipay_cross_total'];
+ } else {
+ $data['payment_alipay_cross_total'] = $this->config->get('payment_alipay_cross_total');
+ }
+
+ if (isset($this->request->post['payment_alipay_cross_order_status_id'])) {
+ $data['payment_alipay_cross_order_status_id'] = $this->request->post['payment_alipay_cross_order_status_id'];
+ } else {
+ $data['payment_alipay_cross_order_status_id'] = $this->config->get('payment_alipay_cross_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_alipay_cross_geo_zone_id'])) {
+ $data['payment_alipay_cross_geo_zone_id'] = $this->request->post['payment_alipay_cross_geo_zone_id'];
+ } else {
+ $data['payment_alipay_cross_geo_zone_id'] = $this->config->get('payment_alipay_cross_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_alipay_cross_test'])) {
+ $data['payment_alipay_cross_test'] = $this->request->post['payment_alipay_cross_test'];
+ } else {
+ $data['payment_alipay_cross_test'] = $this->config->get('payment_alipay_cross_test');
+ }
+
+ if (isset($this->request->post['payment_alipay_cross_status'])) {
+ $data['payment_alipay_cross_status'] = $this->request->post['payment_alipay_cross_status'];
+ } else {
+ $data['payment_alipay_cross_status'] = $this->config->get('payment_alipay_cross_status');
+ }
+
+ if (isset($this->request->post['payment_alipay_cross_sort_order'])) {
+ $data['payment_alipay_cross_sort_order'] = $this->request->post['payment_alipay_cross_sort_order'];
+ } else {
+ $data['payment_alipay_cross_sort_order'] = $this->config->get('payment_alipay_cross_sort_order');
+ }
+
+ $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/alipay_cross', $data));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/alipay_cross')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_alipay_cross_app_id']) {
+ $this->error['app_id'] = $this->language->get('error_app_id');
+ }
+
+ if (!$this->request->post['payment_alipay_cross_merchant_private_key']) {
+ $this->error['merchant_private_key'] = $this->language->get('error_merchant_private_key');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/amazon_login_pay.php b/public/admin/controller/extension/payment/amazon_login_pay.php
new file mode 100644
index 0000000..88abbda
--- /dev/null
+++ b/public/admin/controller/extension/payment/amazon_login_pay.php
@@ -0,0 +1,590 @@
+<?php
+class ControllerExtensionPaymentAmazonLoginPay extends Controller {
+ private $version = '3.1';
+ private $error = array();
+
+ public function index() {
+
+ $this->load->language('extension/payment/amazon_login_pay');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ $this->load->model('extension/payment/amazon_login_pay');
+
+ $this->model_extension_payment_amazon_login_pay->install();
+
+ $this->trimIntegrationDetails();
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_amazon_login_pay', $this->request->post);
+
+ $this->model_extension_payment_amazon_login_pay->deleteEvents();
+ $this->model_extension_payment_amazon_login_pay->addEvents();
+
+ $this->session->data['success'] = $this->language->get('text_success');
+
+ if (isset($this->request->post['language_reload'])) {
+ $this->response->redirect($this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true));
+ } else {
+ $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true));
+ }
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['error_merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['error_merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['error_access_key'])) {
+ $data['error_access_key'] = $this->error['error_access_key'];
+ } else {
+ $data['error_access_key'] = '';
+ }
+
+ if (isset($this->error['error_access_secret'])) {
+ $data['error_access_secret'] = $this->error['error_access_secret'];
+ } else {
+ $data['error_access_secret'] = '';
+ }
+
+ if (isset($this->error['error_client_secret'])) {
+ $data['error_client_secret'] = $this->error['error_client_secret'];
+ } else {
+ $data['error_client_secret'] = '';
+ }
+
+ if (isset($this->error['error_client_id'])) {
+ $data['error_client_id'] = $this->error['error_client_id'];
+ } else {
+ $data['error_client_id'] = '';
+ }
+
+ if (isset($this->error['error_minimum_total'])) {
+ $data['error_minimum_total'] = $this->error['error_minimum_total'];
+ } else {
+ $data['error_minimum_total'] = '';
+ }
+
+ if (isset($this->error['error_curreny'])) {
+ $data['error_curreny'] = $this->error['error_curreny'];
+ } else {
+ $data['error_curreny'] = '';
+ }
+
+ $data['heading_title'] = $this->language->get('heading_title') . ' ' . $this->version;
+
+ $data['https_catalog'] = HTTPS_CATALOG;
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/amazon_login_pay', '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_amazon_login_pay_merchant_id'])) {
+ $data['payment_amazon_login_pay_merchant_id'] = $this->request->post['payment_amazon_login_pay_merchant_id'];
+ } elseif ($this->config->get('payment_amazon_login_pay_merchant_id')) {
+ $data['payment_amazon_login_pay_merchant_id'] = $this->config->get('payment_amazon_login_pay_merchant_id');
+ } else {
+ $data['payment_amazon_login_pay_merchant_id'] = '';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_access_key'])) {
+ $data['payment_amazon_login_pay_access_key'] = $this->request->post['payment_amazon_login_pay_access_key'];
+ } elseif ($this->config->get('payment_amazon_login_pay_access_key')) {
+ $data['payment_amazon_login_pay_access_key'] = $this->config->get('payment_amazon_login_pay_access_key');
+ } else {
+ $data['payment_amazon_login_pay_access_key'] = '';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_access_secret'])) {
+ $data['payment_amazon_login_pay_access_secret'] = $this->request->post['payment_amazon_login_pay_access_secret'];
+ } elseif ($this->config->get('payment_amazon_login_pay_access_secret')) {
+ $data['payment_amazon_login_pay_access_secret'] = $this->config->get('payment_amazon_login_pay_access_secret');
+ } else {
+ $data['payment_amazon_login_pay_access_secret'] = '';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_client_id'])) {
+ $data['payment_amazon_login_pay_client_id'] = $this->request->post['payment_amazon_login_pay_client_id'];
+ } elseif ($this->config->get('payment_amazon_login_pay_client_id')) {
+ $data['payment_amazon_login_pay_client_id'] = $this->config->get('payment_amazon_login_pay_client_id');
+ } else {
+ $data['payment_amazon_login_pay_client_id'] = '';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_client_secret'])) {
+ $data['payment_amazon_login_pay_client_secret'] = $this->request->post['payment_amazon_login_pay_client_secret'];
+ } elseif ($this->config->get('payment_amazon_login_pay_client_secret')) {
+ $data['payment_amazon_login_pay_client_secret'] = $this->config->get('payment_amazon_login_pay_client_secret');
+ } else {
+ $data['payment_amazon_login_pay_client_secret'] = '';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_test'])) {
+ $data['payment_amazon_login_pay_test'] = $this->request->post['payment_amazon_login_pay_test'];
+ } elseif ($this->config->get('payment_amazon_login_pay_test')) {
+ $data['payment_amazon_login_pay_test'] = $this->config->get('payment_amazon_login_pay_test');
+ } else {
+ $data['payment_amazon_login_pay_test'] = 'sandbox';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_mode'])) {
+ $data['payment_amazon_login_pay_mode'] = $this->request->post['payment_amazon_login_pay_mode'];
+ } elseif ($this->config->get('payment_amazon_login_pay_mode')) {
+ $data['payment_amazon_login_pay_mode'] = $this->config->get('payment_amazon_login_pay_mode');
+ } else {
+ $data['payment_amazon_login_pay_mode'] = 'payment';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_checkout'])) {
+ $data['payment_amazon_login_pay_checkout'] = $this->request->post['payment_amazon_login_pay_checkout'];
+ } elseif ($this->config->get('payment_amazon_login_pay_checkout')) {
+ $data['payment_amazon_login_pay_checkout'] = $this->config->get('payment_amazon_login_pay_checkout');
+ } else {
+ $data['payment_amazon_login_pay_checkout'] = 'payment';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_payment_region'])) {
+ $data['payment_amazon_login_pay_payment_region'] = $this->request->post['payment_amazon_login_pay_payment_region'];
+ } elseif ($this->config->get('payment_amazon_login_pay_payment_region')) {
+ $data['payment_amazon_login_pay_payment_region'] = $this->config->get('payment_amazon_login_pay_payment_region');
+ } elseif (in_array($this->config->get('config_currency'), array('EUR', 'GBP', 'USD'))) {
+ $data['payment_amazon_login_pay_payment_region'] = $this->config->get('config_currency');
+ } else {
+ $data['payment_amazon_login_pay_payment_region'] = 'USD';
+ }
+
+ if ($data['payment_amazon_login_pay_payment_region'] == 'EUR') {
+ $data['payment_amazon_login_pay_language'] = 'de-DE';
+ $data['sp_id'] = 'AW93DIZMWSDWS';
+ $data['locale'] = 'EUR';
+ $ld = 'AW93DIZMWSDWS';
+ } elseif ($data['payment_amazon_login_pay_payment_region'] == 'GBP') {
+ $data['payment_amazon_login_pay_language'] = 'en-GB';
+ $data['sp_id'] = 'AW93DIZMWSDWS';
+ $data['locale'] = 'GBP';
+ $ld = 'AW93DIZMWSDWS';
+ } else {
+ $data['payment_amazon_login_pay_language'] = 'en-US';
+ $data['sp_id'] = 'A3GK1RS09H3A7D';
+ $data['locale'] = 'US';
+ $ld = 'A3GK1RS09H3A7D';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_language'])) {
+ $data['payment_amazon_login_pay_language'] = $this->request->post['payment_amazon_login_pay_language'];
+ } elseif ($this->config->get('payment_amazon_login_pay_language')) {
+ $data['payment_amazon_login_pay_language'] = $this->config->get('payment_amazon_login_pay_language');
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_capture_status'])) {
+ $data['payment_amazon_login_pay_capture_status'] = $this->request->post['payment_amazon_login_pay_capture_status'];
+ } elseif ($this->config->get('payment_amazon_login_pay_capture_status')) {
+ $data['payment_amazon_login_pay_capture_status'] = $this->config->get('payment_amazon_login_pay_capture_status');
+ } else {
+ $data['payment_amazon_login_pay_capture_status'] = '';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_pending_status'])) {
+ $data['payment_amazon_login_pay_pending_status'] = $this->request->post['payment_amazon_login_pay_pending_status'];
+ } elseif ($this->config->get('payment_amazon_login_pay_pending_status')) {
+ $data['payment_amazon_login_pay_pending_status'] = $this->config->get('payment_amazon_login_pay_pending_status');
+ } else {
+ $data['payment_amazon_login_pay_pending_status'] = '0';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_ipn_token'])) {
+ $data['payment_amazon_login_pay_ipn_token'] = $this->request->post['payment_amazon_login_pay_ipn_token'];
+ } elseif ($this->config->get('payment_amazon_login_pay_ipn_token')) {
+ $data['payment_amazon_login_pay_ipn_token'] = $this->config->get('payment_amazon_login_pay_ipn_token');
+ } else {
+ $data['payment_amazon_login_pay_ipn_token'] = sha1(uniqid(mt_rand(), 1));
+ }
+
+ $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/amazon_login_pay/ipn&token=' . $data['payment_amazon_login_pay_ipn_token'];
+
+ if (isset($this->request->post['payment_amazon_login_pay_minimum_total'])) {
+ $data['payment_amazon_login_pay_minimum_total'] = $this->request->post['payment_amazon_login_pay_minimum_total'];
+ } elseif ($this->config->get('payment_amazon_login_pay_minimum_total')) {
+ $data['payment_amazon_login_pay_minimum_total'] = $this->config->get('payment_amazon_login_pay_minimum_total');
+ } else {
+ $data['payment_amazon_login_pay_minimum_total'] = '0.01';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_geo_zone'])) {
+ $data['payment_amazon_login_pay_geo_zone'] = $this->request->post['payment_amazon_login_pay_geo_zone'];
+ } elseif ($this->config->get('payment_amazon_login_pay_geo_zone')) {
+ $data['payment_amazon_login_pay_geo_zone'] = $this->config->get('payment_amazon_login_pay_geo_zone');
+ } else {
+ $data['payment_amazon_login_pay_geo_zone'] = '0';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_debug'])) {
+ $data['payment_amazon_login_pay_debug'] = $this->request->post['payment_amazon_login_pay_debug'];
+ } elseif ($this->config->get('payment_amazon_login_pay_debug')) {
+ $data['payment_amazon_login_pay_debug'] = $this->config->get('payment_amazon_login_pay_debug');
+ } else {
+ $data['payment_amazon_login_pay_debug'] = '0';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_sort_order'])) {
+ $data['payment_amazon_login_pay_sort_order'] = $this->request->post['payment_amazon_login_pay_sort_order'];
+ } elseif ($this->config->get('payment_amazon_login_pay_sort_order')) {
+ $data['payment_amazon_login_pay_sort_order'] = $this->config->get('payment_amazon_login_pay_sort_order');
+ } else {
+ $data['payment_amazon_login_pay_sort_order'] = '0';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_status'])) {
+ $data['payment_amazon_login_pay_status'] = $this->request->post['payment_amazon_login_pay_status'];
+ } elseif ($this->config->get('payment_amazon_login_pay_status')) {
+ $data['payment_amazon_login_pay_status'] = $this->config->get('payment_amazon_login_pay_status');
+ } else {
+ $data['payment_amazon_login_pay_status'] = '0';
+ }
+
+ if (isset($this->request->post['payment_amazon_login_pay_declined_code'])) {
+ $data['payment_amazon_login_pay_declined_code'] = $this->request->post['payment_amazon_login_pay_declined_code'];
+ } elseif ($this->config->get('payment_amazon_login_pay_declined_code')) {
+ $data['payment_amazon_login_pay_declined_code'] = $this->config->get('payment_amazon_login_pay_declined_code');
+ } else {
+ $data['payment_amazon_login_pay_declined_code'] = '';
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $data['declined_codes'] = array($this->language->get('text_amazon_invalid'), $this->language->get('text_amazon_rejected'), $this->language->get('text_amazon_timeout'));
+
+ $data['unique_id'] = 'oc-' . str_replace(' ', '-', strtolower($this->config->get('config_name'))) . '_' . mt_rand();
+ $data['allowed_login_domain'] = html_entity_decode(HTTPS_CATALOG);
+ $data['login_redirect_urls'][] = HTTPS_CATALOG . 'index.php?route=payment/amazon_login/login';
+ $data['login_redirect_urls'][] = HTTPS_CATALOG . 'index.php?route=payment/amazon_pay/login';
+ $data['store_name'] = $this->config->get('config_name');
+ $data['simple_path_language'] = str_replace('-', '_', $data['payment_amazon_login_pay_language']);
+
+ if ($data['payment_amazon_login_pay_payment_region'] == 'USD') {
+ $data['registration_url'] = "https://payments.amazon.com/register?registration_source=SPPL&spId=" . $ld;
+
+ $data['languages'] = array(
+ 'en-US' => $this->language->get('text_us')
+ );
+ } else {
+ $data['registration_url'] = "https://payments-eu.amazon.com/register?registration_source=SPPL&spId=" . $ld;
+
+ $data['languages'] = array(
+ 'de-DE' => $this->language->get('text_de'),
+ 'es-ES' => $this->language->get('text_es'),
+ 'fr-FR' => $this->language->get('text_fr'),
+ 'it-IT' => $this->language->get('text_it'),
+ 'en-GB' => $this->language->get('text_uk')
+ );
+ }
+
+ $data['payment_regions'] = array(
+ 'EUR' => $this->language->get('text_eu_region'),
+ 'GBP' => $this->language->get('text_uk_region'),
+ 'USD' => $this->language->get('text_us_region')
+ );
+
+ $data['has_ssl'] = !empty($this->request->server['HTTPS']);
+
+ $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/amazon_login_pay', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/amazon_login_pay');
+ $this->model_extension_payment_amazon_login_pay->install();
+ $this->model_extension_payment_amazon_login_pay->deleteEvents();
+ $this->model_extension_payment_amazon_login_pay->addEvents();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/amazon_login_pay');
+ $this->load->model('setting/event');
+ $this->model_extension_payment_amazon_login_pay->uninstall();
+ $this->model_extension_payment_amazon_login_pay->deleteEvents();
+ }
+
+ public function order() {
+
+ if ($this->config->get('payment_amazon_login_pay_status')) {
+
+ $this->load->model('extension/payment/amazon_login_pay');
+
+ $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->get['order_id']);
+
+ if (!empty($amazon_login_pay_order)) {
+
+ $this->load->language('extension/payment/amazon_login_pay');
+
+ $amazon_login_pay_order['total_captured'] = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']);
+
+ $amazon_login_pay_order['total_formatted'] = $this->currency->format($amazon_login_pay_order['total'], $amazon_login_pay_order['currency_code'], true, true);
+ $amazon_login_pay_order['total_captured_formatted'] = $this->currency->format($amazon_login_pay_order['total_captured'], $amazon_login_pay_order['currency_code'], true, true);
+
+ $data['amazon_login_pay_order'] = $amazon_login_pay_order;
+
+ $data['order_id'] = $this->request->get['order_id'];
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/amazon_login_pay_order', $data);
+ }
+ }
+ }
+
+ public function cancel() {
+ $this->load->language('extension/payment/amazon_login_pay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/amazon_login_pay');
+
+ $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']);
+
+ $cancel_response = $this->model_extension_payment_amazon_login_pay->cancel($amazon_login_pay_order);
+
+ $this->model_extension_payment_amazon_login_pay->logger($cancel_response);
+
+ if ($cancel_response['status'] == 'Completed') {
+ $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'cancel', $cancel_response['status'], 0.00);
+ $this->model_extension_payment_amazon_login_pay->updateCancelStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1);
+ $json['msg'] = $this->language->get('text_cancel_ok');
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['type'] = 'cancel';
+ $json['data']['status'] = $cancel_response['status'];
+ $json['data']['amount'] = $this->currency->format(0.00, $amazon_login_pay_order['currency_code'], true, true);
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($cancel_response['StatuesDetail']) && !empty($cancel_response['StatuesDetail']) ? (string)$cancel_response['StatuesDetail'] : 'Unable to cancel';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/amazon_login_pay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/amazon_login_pay');
+
+ $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']);
+
+ $capture_response = $this->model_extension_payment_amazon_login_pay->capture($amazon_login_pay_order, $this->request->post['amount']);
+ $this->model_extension_payment_amazon_login_pay->logger($capture_response);
+
+ if ($capture_response['status'] == 'Completed' || $capture_response['status'] == 'Pending') {
+ $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'capture', $capture_response['status'], $this->request->post['amount'], $capture_response['AmazonAuthorizationId'], $capture_response['AmazonCaptureId']);
+
+ $this->model_extension_payment_amazon_login_pay->updateAuthorizationStatus($capture_response['AmazonAuthorizationId'], 'Closed');
+
+ $total_captured = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']);
+
+ if ($total_captured > 0) {
+ $order_reference_id = $amazon_login_pay_order['amazon_order_reference_id'];
+
+ if ($this->model_extension_payment_amazon_login_pay->isOrderInState($order_reference_id, array('Open', 'Suspended'))) {
+ $this->model_extension_payment_amazon_login_pay->closeOrderRef($order_reference_id);
+ }
+ }
+
+ if ($total_captured >= (double)$amazon_login_pay_order['total']) {
+ $this->model_extension_payment_amazon_login_pay->updateCaptureStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1);
+ $capture_status = 1;
+ $json['msg'] = $this->language->get('text_capture_ok_order');
+ } else {
+ $capture_status = 0;
+ $json['msg'] = $this->language->get('text_capture_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['type'] = 'capture';
+ $json['data']['status'] = $capture_response['status'];
+ $json['data']['amazon_authorization_id'] = $capture_response['AmazonAuthorizationId'];
+ $json['data']['amazon_capture_id'] = $capture_response['AmazonCaptureId'];
+ $json['data']['amount'] = $this->currency->format($this->request->post['amount'], $amazon_login_pay_order['currency_code'], true, true);
+ $json['data']['capture_status'] = $capture_status;
+ $json['data']['total'] = $this->currency->format($total_captured, $amazon_login_pay_order['currency_code'], true, true);
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($capture_response['status_detail']) && !empty($capture_response['status_detail']) ? (string)$capture_response['status_detail'] : 'Unable to capture';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/amazon_login_pay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/amazon_login_pay');
+
+ $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']);
+
+ $refund_response = $this->model_extension_payment_amazon_login_pay->refund($amazon_login_pay_order, $this->request->post['amount']);
+
+ $this->model_extension_payment_amazon_login_pay->logger($refund_response);
+
+ $refund_status = '';
+ $total_captured = '';
+ $total_refunded = '';
+
+ foreach ($refund_response as $response) {
+ if ($response['status'] == 'Pending') {
+ $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'refund', $response['status'], $response['amount'] * -1, $response['amazon_authorization_id'], $response['amazon_capture_id'], $response['AmazonRefundId']);
+
+ $total_refunded = $this->model_extension_payment_amazon_login_pay->getTotalRefunded($amazon_login_pay_order['amazon_login_pay_order_id']);
+ $total_captured = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']);
+
+ if ($total_captured <= 0 && $amazon_login_pay_order['capture_status'] == 1) {
+ $this->model_extension_payment_amazon_login_pay->updateRefundStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1);
+ $refund_status = 1;
+ $json['msg'][] = $this->language->get('text_refund_ok_order') . '<br />';
+ } else {
+ $refund_status = 0;
+ $json['msg'][] = $this->language->get('text_refund_ok') . '<br />';
+ }
+
+ $data = array();
+ $data['date_added'] = date("Y-m-d H:i:s");
+ $data['type'] = 'refund';
+ $data['status'] = $response['status'];
+ $data['amazon_authorization_id'] = $response['amazon_authorization_id'];
+ $data['amazon_capture_id'] = $response['amazon_capture_id'];
+ $data['amazon_refund_id'] = $response['AmazonRefundId'];
+ $data['amount'] = $this->currency->format(($response['amount'] * -1), $amazon_login_pay_order['currency_code'], true, true);
+ $json['data'][] = $data;
+ } else {
+ $json['error'] = true;
+ $json['error_msg'][] = isset($response['status_detail']) && !empty($response['status_detail']) ? (string)$response['status_detail'] : 'Unable to refund';
+ }
+ }
+ $json['refund_status'] = $refund_status;
+ $json['total_captured'] = $this->currency->format($total_captured, $amazon_login_pay_order['currency_code'], true, true);
+ $json['total_refunded'] = $this->currency->format($total_refunded, $amazon_login_pay_order['currency_code'], true, true);
+ } else {
+ $json['error'] = true;
+ $json['error_msg'][] = $this->language->get('error_data_missing');
+ }
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function trimIntegrationDetails() {
+ $integration_keys = array(
+ 'payment_amazon_login_pay_merchant_id',
+ 'payment_amazon_login_pay_access_key',
+ 'payment_amazon_login_pay_access_secret',
+ 'payment_amazon_login_pay_client_id',
+ 'payment_amazon_login_pay_client_secret'
+ );
+
+ foreach ($this->request->post as $key => $value) {
+ if (in_array($key, $integration_keys)) {
+ $this->request->post[$key] = trim($value);
+ }
+ }
+ }
+
+ protected function validate() {
+ $this->load->model('localisation/currency');
+
+ if (!$this->user->hasPermission('modify', 'extension/payment/amazon_login_pay')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_amazon_login_pay_merchant_id']) {
+ $this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['payment_amazon_login_pay_access_key']) {
+ $this->error['error_access_key'] = $this->language->get('error_access_key');
+ }
+
+ if (empty($this->error)) {
+ $this->load->model('extension/payment/amazon_login_pay');
+ $errors = $this->model_extension_payment_amazon_login_pay->validateDetails($this->request->post);
+ if (isset($errors['error_code']) && $errors['error_code'] == 'InvalidParameterValue') {
+ $this->error['error_merchant_id'] = $errors['status_detail'];
+ } elseif (isset($errors['error_code']) && $errors['error_code'] == 'InvalidAccessKeyId') {
+ $this->error['error_access_key'] = $errors['status_detail'];
+ }
+ }
+
+ if (!$this->request->post['payment_amazon_login_pay_access_secret']) {
+ $this->error['error_access_secret'] = $this->language->get('error_access_secret');
+ }
+
+ if (!$this->request->post['payment_amazon_login_pay_client_id']) {
+ $this->error['error_client_id'] = $this->language->get('error_client_id');
+ }
+
+ if (!$this->request->post['payment_amazon_login_pay_client_secret']) {
+ $this->error['error_client_secret'] = $this->language->get('error_client_secret');
+ }
+
+ if ($this->request->post['payment_amazon_login_pay_minimum_total'] <= 0) {
+ $this->error['error_minimum_total'] = $this->language->get('error_minimum_total');
+ }
+
+ if (isset($this->request->post['amazon_login_pay_region'])) {
+ $currency_code = $this->request->post['amazon_login_pay_region'];
+
+ $currency = $this->model_localisation_currency->getCurrency($this->currency->getId($currency_code));
+
+ if (empty($currency) || $currency['status'] != '1') {
+ $this->error['error_curreny'] = sprintf($this->language->get('error_curreny'), $currency_code);
+ }
+ }
+
+ return !$this->error;
+ }
+
+}
diff --git a/public/admin/controller/extension/payment/authorizenet_aim.php b/public/admin/controller/extension/payment/authorizenet_aim.php
new file mode 100644
index 0000000..517fc4e
--- /dev/null
+++ b/public/admin/controller/extension/payment/authorizenet_aim.php
@@ -0,0 +1,154 @@
+<?php
+class ControllerExtensionPaymentAuthorizenetAim extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/authorizenet_aim');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_authorizenet_aim', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['login'])) {
+ $data['error_login'] = $this->error['login'];
+ } else {
+ $data['error_login'] = '';
+ }
+
+ if (isset($this->error['key'])) {
+ $data['error_key'] = $this->error['key'];
+ } else {
+ $data['error_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/authorizenet_aim', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/authorizenet_aim', '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_authorizenet_aim_login'])) {
+ $data['payment_authorizenet_aim_login'] = $this->request->post['payment_authorizenet_aim_login'];
+ } else {
+ $data['payment_authorizenet_aim_login'] = $this->config->get('payment_authorizenet_aim_login');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_key'])) {
+ $data['payment_authorizenet_aim_key'] = $this->request->post['payment_authorizenet_aim_key'];
+ } else {
+ $data['payment_authorizenet_aim_key'] = $this->config->get('payment_authorizenet_aim_key');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_hash'])) {
+ $data['payment_authorizenet_aim_hash'] = $this->request->post['payment_authorizenet_aim_hash'];
+ } else {
+ $data['payment_authorizenet_aim_hash'] = $this->config->get('payment_authorizenet_aim_hash');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_server'])) {
+ $data['payment_authorizenet_aim_server'] = $this->request->post['payment_authorizenet_aim_server'];
+ } else {
+ $data['payment_authorizenet_aim_server'] = $this->config->get('payment_authorizenet_aim_server');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_mode'])) {
+ $data['payment_authorizenet_aim_mode'] = $this->request->post['payment_authorizenet_aim_mode'];
+ } else {
+ $data['payment_authorizenet_aim_mode'] = $this->config->get('payment_authorizenet_aim_mode');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_method'])) {
+ $data['payment_authorizenet_aim_method'] = $this->request->post['payment_authorizenet_aim_method'];
+ } else {
+ $data['payment_authorizenet_aim_method'] = $this->config->get('payment_authorizenet_aim_method');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_total'])) {
+ $data['payment_authorizenet_aim_total'] = $this->request->post['payment_authorizenet_aim_total'];
+ } else {
+ $data['payment_authorizenet_aim_total'] = $this->config->get('payment_authorizenet_aim_total');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_order_status_id'])) {
+ $data['payment_authorizenet_aim_order_status_id'] = $this->request->post['payment_authorizenet_aim_order_status_id'];
+ } else {
+ $data['payment_authorizenet_aim_order_status_id'] = $this->config->get('payment_authorizenet_aim_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_authorizenet_aim_geo_zone_id'])) {
+ $data['payment_authorizenet_aim_geo_zone_id'] = $this->request->post['payment_authorizenet_aim_geo_zone_id'];
+ } else {
+ $data['payment_authorizenet_aim_geo_zone_id'] = $this->config->get('payment_authorizenet_aim_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_authorizenet_aim_status'])) {
+ $data['payment_authorizenet_aim_status'] = $this->request->post['payment_authorizenet_aim_status'];
+ } else {
+ $data['payment_authorizenet_aim_status'] = $this->config->get('payment_authorizenet_aim_status');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_aim_sort_order'])) {
+ $data['payment_authorizenet_aim_sort_order'] = $this->request->post['payment_authorizenet_aim_sort_order'];
+ } else {
+ $data['payment_authorizenet_aim_sort_order'] = $this->config->get('payment_authorizenet_aim_sort_order');
+ }
+
+ $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/authorizenet_aim', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/authorizenet_aim')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_authorizenet_aim_login']) {
+ $this->error['login'] = $this->language->get('error_login');
+ }
+
+ if (!$this->request->post['payment_authorizenet_aim_key']) {
+ $this->error['key'] = $this->language->get('error_key');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/authorizenet_sim.php b/public/admin/controller/extension/payment/authorizenet_sim.php
new file mode 100644
index 0000000..ceb4dbe
--- /dev/null
+++ b/public/admin/controller/extension/payment/authorizenet_sim.php
@@ -0,0 +1,145 @@
+<?php
+class ControllerExtensionPaymentAuthorizeNetSim extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/authorizenet_sim');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_authorizenet_sim', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['merchant'])) {
+ $data['error_merchant'] = $this->error['merchant'];
+ } else {
+ $data['error_merchant'] = '';
+ }
+
+ if (isset($this->error['key'])) {
+ $data['error_key'] = $this->error['key'];
+ } else {
+ $data['error_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/authorizenet_sim', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/authorizenet_sim', '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_authorizenet_sim_merchant'])) {
+ $data['payment_authorizenet_sim_merchant'] = $this->request->post['payment_authorizenet_sim_merchant'];
+ } else {
+ $data['payment_authorizenet_sim_merchant'] = $this->config->get('payment_authorizenet_sim_merchant');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_sim_key'])) {
+ $data['payment_authorizenet_sim_key'] = $this->request->post['payment_authorizenet_sim_key'];
+ } else {
+ $data['payment_authorizenet_sim_key'] = $this->config->get('payment_authorizenet_sim_key');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_sim_test'])) {
+ $data['payment_authorizenet_sim_test'] = $this->request->post['payment_authorizenet_sim_test'];
+ } else {
+ $data['payment_authorizenet_sim_test'] = $this->config->get('payment_authorizenet_sim_test');
+ }
+
+ $data['callback'] = HTTP_CATALOG . 'index.php?route=extension/payment/authorizenet_sim/callback';
+
+ if (isset($this->request->post['payment_authorizenet_sim_hash'])) {
+ $data['payment_authorizenet_sim_hash'] = $this->request->post['payment_authorizenet_sim_hash'];
+ } else {
+ $data['payment_authorizenet_sim_hash'] = $this->config->get('payment_authorizenet_sim_hash');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_sim_total'])) {
+ $data['payment_authorizenet_sim_total'] = $this->request->post['payment_authorizenet_sim_total'];
+ } else {
+ $data['payment_authorizenet_sim_total'] = $this->config->get('payment_authorizenet_sim_total');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_sim_order_status_id'])) {
+ $data['payment_authorizenet_sim_order_status_id'] = $this->request->post['payment_authorizenet_sim_order_status_id'];
+ } else {
+ $data['payment_authorizenet_sim_order_status_id'] = $this->config->get('payment_authorizenet_sim_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_authorizenet_sim_geo_zone_id'])) {
+ $data['payment_authorizenet_sim_geo_zone_id'] = $this->request->post['payment_authorizenet_sim_geo_zone_id'];
+ } else {
+ $data['payment_authorizenet_sim_geo_zone_id'] = $this->config->get('payment_authorizenet_sim_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_authorizenet_sim_status'])) {
+ $data['payment_authorizenet_sim_status'] = $this->request->post['payment_authorizenet_sim_status'];
+ } else {
+ $data['payment_authorizenet_sim_status'] = $this->config->get('payment_authorizenet_sim_status');
+ }
+
+ if (isset($this->request->post['payment_authorizenet_sim_sort_order'])) {
+ $data['payment_authorizenet_sim_sort_order'] = $this->request->post['payment_authorizenet_sim_sort_order'];
+ } else {
+ $data['payment_authorizenet_sim_sort_order'] = $this->config->get('payment_authorizenet_sim_sort_order');
+ }
+
+ $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/authorizenet_sim', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/authorizenet_sim')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_authorizenet_sim_merchant']) {
+ $this->error['merchant'] = $this->language->get('error_merchant');
+ }
+
+ if (!$this->request->post['payment_authorizenet_sim_key']) {
+ $this->error['key'] = $this->language->get('error_key');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/bank_transfer.php b/public/admin/controller/extension/payment/bank_transfer.php
new file mode 100644
index 0000000..9bb4882
--- /dev/null
+++ b/public/admin/controller/extension/payment/bank_transfer.php
@@ -0,0 +1,131 @@
+<?php
+class ControllerExtensionPaymentBankTransfer extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/bank_transfer');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_bank_transfer', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['bank'])) {
+ $data['error_bank'] = $this->error['bank'];
+ } else {
+ $data['error_bank'] = array();
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/bank_transfer', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/bank_transfer', '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);
+
+ $this->load->model('localisation/language');
+
+ $data['payment_bank_transfer'] = array();
+
+ $languages = $this->model_localisation_language->getLanguages();
+
+ foreach ($languages as $language) {
+ if (isset($this->request->post['payment_bank_transfer_bank' . $language['language_id']])) {
+ $data['payment_bank_transfer_bank'][$language['language_id']] = $this->request->post['payment_bank_transfer_bank' . $language['language_id']];
+ } else {
+ $data['payment_bank_transfer_bank'][$language['language_id']] = $this->config->get('payment_bank_transfer_bank' . $language['language_id']);
+ }
+ }
+
+ $data['languages'] = $languages;
+
+ if (isset($this->request->post['payment_bank_transfer_total'])) {
+ $data['payment_bank_transfer_total'] = $this->request->post['payment_bank_transfer_total'];
+ } else {
+ $data['payment_bank_transfer_total'] = $this->config->get('payment_bank_transfer_total');
+ }
+
+ if (isset($this->request->post['payment_bank_transfer_order_status_id'])) {
+ $data['payment_bank_transfer_order_status_id'] = $this->request->post['payment_bank_transfer_order_status_id'];
+ } else {
+ $data['payment_bank_transfer_order_status_id'] = $this->config->get('payment_bank_transfer_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_bank_transfer_geo_zone_id'])) {
+ $data['payment_bank_transfer_geo_zone_id'] = $this->request->post['payment_bank_transfer_geo_zone_id'];
+ } else {
+ $data['payment_bank_transfer_geo_zone_id'] = $this->config->get('payment_bank_transfer_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_bank_transfer_status'])) {
+ $data['payment_bank_transfer_status'] = $this->request->post['payment_bank_transfer_status'];
+ } else {
+ $data['payment_bank_transfer_status'] = $this->config->get('payment_bank_transfer_status');
+ }
+
+ if (isset($this->request->post['payment_bank_transfer_sort_order'])) {
+ $data['payment_bank_transfer_sort_order'] = $this->request->post['payment_bank_transfer_sort_order'];
+ } else {
+ $data['payment_bank_transfer_sort_order'] = $this->config->get('payment_bank_transfer_sort_order');
+ }
+
+ $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/bank_transfer', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/bank_transfer')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ $this->load->model('localisation/language');
+
+ $languages = $this->model_localisation_language->getLanguages();
+
+ foreach ($languages as $language) {
+ if (empty($this->request->post['payment_bank_transfer_bank' . $language['language_id']])) {
+ $this->error['bank'][$language['language_id']] = $this->language->get('error_bank');
+ }
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/bluepay_hosted.php b/public/admin/controller/extension/payment/bluepay_hosted.php
new file mode 100644
index 0000000..2ce59d6
--- /dev/null
+++ b/public/admin/controller/extension/payment/bluepay_hosted.php
@@ -0,0 +1,351 @@
+<?php
+class ControllerExtensionPaymentBluePayHosted extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/bluepay_hosted');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_bluepay_hosted', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['account_name'])) {
+ $data['error_account_name'] = $this->error['account_name'];
+ } else {
+ $data['error_account_name'] = '';
+ }
+
+ if (isset($this->error['account_id'])) {
+ $data['error_account_id'] = $this->error['account_id'];
+ } else {
+ $data['error_account_id'] = '';
+ }
+
+ if (isset($this->error['secret_key'])) {
+ $data['error_secret_key'] = $this->error['secret_key'];
+ } else {
+ $data['error_secret_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/bluepay_hosted', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/bluepay_hosted', '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_bluepay_hosted_account_name'])) {
+ $data['payment_bluepay_hosted_account_name'] = $this->request->post['payment_bluepay_hosted_account_name'];
+ } else {
+ $data['payment_bluepay_hosted_account_name'] = $this->config->get('payment_bluepay_hosted_account_name');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_account_id'])) {
+ $data['payment_bluepay_hosted_account_id'] = $this->request->post['payment_bluepay_hosted_account_id'];
+ } else {
+ $data['payment_bluepay_hosted_account_id'] = $this->config->get('payment_bluepay_hosted_account_id');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_secret_key'])) {
+ $data['payment_bluepay_hosted_secret_key'] = $this->request->post['payment_bluepay_hosted_secret_key'];
+ } else {
+ $data['payment_bluepay_hosted_secret_key'] = $this->config->get('payment_bluepay_hosted_secret_key');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_test'])) {
+ $data['payment_bluepay_hosted_test'] = $this->request->post['payment_bluepay_hosted_test'];
+ } else {
+ $data['payment_bluepay_hosted_test'] = $this->config->get('payment_bluepay_hosted_test');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_transaction'])) {
+ $data['payment_bluepay_hosted_transaction'] = $this->request->post['payment_bluepay_hosted_transaction'];
+ } else {
+ $data['payment_bluepay_hosted_transaction'] = $this->config->get('payment_bluepay_hosted_transaction');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_amex'])) {
+ $data['payment_bluepay_hosted_amex'] = $this->request->post['payment_bluepay_hosted_amex'];
+ } else {
+ $data['payment_bluepay_hosted_amex'] = $this->config->get('payment_bluepay_hosted_amex');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_discover'])) {
+ $data['payment_bluepay_hosted_discover'] = $this->request->post['payment_bluepay_hosted_discover'];
+ } else {
+ $data['payment_bluepay_hosted_discover'] = $this->config->get('payment_bluepay_hosted_discover');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_total'])) {
+ $data['payment_bluepay_hosted_total'] = $this->request->post['payment_bluepay_hosted_total'];
+ } else {
+ $data['payment_bluepay_hosted_total'] = $this->config->get('payment_bluepay_hosted_total');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_order_status_id'])) {
+ $data['payment_bluepay_hosted_order_status_id'] = $this->request->post['payment_bluepay_hosted_order_status_id'];
+ } elseif ($this->config->get('payment_bluepay_hosted_order_status_id')) {
+ $data['payment_bluepay_hosted_order_status_id'] = $this->config->get('payment_bluepay_hosted_order_status_id');
+ } else {
+ $data['payment_bluepay_hosted_order_status_id'] = 2;
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_bluepay_hosted_geo_zone_id'])) {
+ $data['payment_bluepay_hosted_geo_zone_id'] = $this->request->post['payment_bluepay_hosted_geo_zone_id'];
+ } else {
+ $data['payment_bluepay_hosted_geo_zone_id'] = $this->config->get('payment_bluepay_hosted_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_bluepay_hosted_status'])) {
+ $data['payment_bluepay_hosted_status'] = $this->request->post['payment_bluepay_hosted_status'];
+ } else {
+ $data['payment_bluepay_hosted_status'] = $this->config->get('payment_bluepay_hosted_status');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_debug'])) {
+ $data['payment_bluepay_hosted_debug'] = $this->request->post['payment_bluepay_hosted_debug'];
+ } else {
+ $data['payment_bluepay_hosted_debug'] = $this->config->get('payment_bluepay_hosted_debug');
+ }
+
+ if (isset($this->request->post['payment_bluepay_hosted_sort_order'])) {
+ $data['payment_bluepay_hosted_sort_order'] = $this->request->post['payment_bluepay_hosted_sort_order'];
+ } else {
+ $data['payment_bluepay_hosted_sort_order'] = $this->config->get('payment_bluepay_hosted_sort_order');
+ }
+
+ $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/bluepay_hosted', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/bluepay_hosted');
+
+ $this->model_extension_payment_bluepay_hosted->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/bluepay_hosted');
+
+ $this->model_extension_payment_bluepay_hosted->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_bluepay_hosted_status')) {
+ $this->load->model('extension/payment/bluepay_hosted');
+
+ $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->get['order_id']);
+
+ if (!empty($bluepay_hosted_order)) {
+ $this->load->language('extension/payment/bluepay_hosted');
+
+ $bluepay_hosted_order['total_released'] = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']);
+
+ $bluepay_hosted_order['total_formatted'] = $this->currency->format($bluepay_hosted_order['total'], $bluepay_hosted_order['currency_code'], false, false);
+ $bluepay_hosted_order['total_released_formatted'] = $this->currency->format($bluepay_hosted_order['total_released'], $bluepay_hosted_order['currency_code'], false, false);
+
+ $data['bluepay_hosted_order'] = $bluepay_hosted_order;
+
+ $data['order_id'] = $this->request->get['order_id'];
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/bluepay_hosted_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/bluepay_hosted');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/bluepay_hosted');
+
+ $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_bluepay_hosted->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_bluepay_hosted->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if ($void_response['Result'] == 'APPROVED') {
+ $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'void', $bluepay_hosted_order['total']);
+ $this->model_extension_payment_bluepay_hosted->updateVoidStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['total'] = $bluepay_hosted_order['total'];
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response['MESSAGE']) && !empty($void_response['MESSAGE']) ? (string)$void_response['MESSAGE'] : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function release() {
+ $this->load->language('extension/payment/bluepay_hosted');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/bluepay_hosted');
+
+ $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']);
+
+ $release_response = $this->model_extension_payment_bluepay_hosted->release($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_bluepay_hosted->logger('Release result:\r\n' . print_r($release_response, 1));
+
+ if ($release_response['Result'] == 'APPROVED') {
+ $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'payment', $this->request->post['amount']);
+
+ $this->model_extension_payment_bluepay_hosted->updateTransactionId($bluepay_hosted_order['bluepay_hosted_order_id'], $release_response['RRNO']);
+
+ $total_released = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']);
+
+ if ($total_released >= $bluepay_hosted_order['total']) {
+ $this->model_extension_payment_bluepay_hosted->updateReleaseStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1);
+ $release_status = 1;
+ $json['msg'] = $this->language->get('text_release_ok_order');
+ } else {
+ $release_status = 0;
+ $json['msg'] = $this->language->get('text_release_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'];
+ $json['data']['release_status'] = $release_status;
+ $json['data']['total'] = (float)$total_released;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($release_response['MESSAGE']) && !empty($release_response['MESSAGE']) ? (string)$release_response['MESSAGE'] : 'Unable to release';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/bluepay_hosted');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/bluepay_hosted');
+
+ $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_bluepay_hosted->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_bluepay_hosted->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if ($rebate_response['Result'] == 'APPROVED') {
+ $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'rebate', $this->request->post['amount'] * -1);
+
+ $total_rebated = $this->model_extension_payment_bluepay_hosted->getTotalRebated($bluepay_hosted_order['bluepay_hosted_order_id']);
+ $total_released = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']);
+
+ if ($total_released <= 0 && $bluepay_hosted_order['release_status'] == 1) {
+ $this->model_extension_payment_bluepay_hosted->updateRebateStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'] * -1;
+ $json['data']['total_released'] = (float)$total_released;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response['MESSAGE']) && !empty($rebate_response['MESSAGE']) ? (string)$rebate_response['MESSAGE'] : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/bluepay_hosted')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_bluepay_hosted_account_name']) {
+ $this->error['account_name'] = $this->language->get('error_account_name');
+ }
+
+ if (!$this->request->post['payment_bluepay_hosted_account_id']) {
+ $this->error['account_id'] = $this->language->get('error_account_id');
+ }
+
+ if (!$this->request->post['payment_bluepay_hosted_secret_key']) {
+ $this->error['secret_key'] = $this->language->get('error_secret_key');
+ }
+
+ return !$this->error;
+ }
+
+ public function callback() {
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($this->request->get));
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/bluepay_redirect.php b/public/admin/controller/extension/payment/bluepay_redirect.php
new file mode 100644
index 0000000..a416a54
--- /dev/null
+++ b/public/admin/controller/extension/payment/bluepay_redirect.php
@@ -0,0 +1,331 @@
+<?php
+class ControllerExtensionPaymentBluepayredirect extends Controller {
+ private $error = array();
+
+ public function index() {
+
+ $this->load->language('extension/payment/bluepay_redirect');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_bluepay_redirect', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['account_id'])) {
+ $data['error_account_id'] = $this->error['account_id'];
+ } else {
+ $data['error_account_id'] = '';
+ }
+
+ if (isset($this->error['secret_key'])) {
+ $data['error_secret_key'] = $this->error['secret_key'];
+ } else {
+ $data['error_secret_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/bluepay_redirect', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/bluepay_redirect', '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_bluepay_redirect_account_id'])) {
+ $data['payment_bluepay_redirect_account_id'] = $this->request->post['payment_bluepay_redirect_account_id'];
+ } else {
+ $data['payment_bluepay_redirect_account_id'] = $this->config->get('payment_bluepay_redirect_account_id');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_secret_key'])) {
+ $data['payment_bluepay_redirect_secret_key'] = $this->request->post['payment_bluepay_redirect_secret_key'];
+ } else {
+ $data['payment_bluepay_redirect_secret_key'] = $this->config->get('payment_bluepay_redirect_secret_key');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_test'])) {
+ $data['payment_bluepay_redirect_test'] = $this->request->post['payment_bluepay_redirect_test'];
+ } else {
+ $data['payment_bluepay_redirect_test'] = $this->config->get('payment_bluepay_redirect_test');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_transaction'])) {
+ $data['payment_bluepay_redirect_transaction'] = $this->request->post['payment_bluepay_redirect_transaction'];
+ } else {
+ $data['payment_bluepay_redirect_transaction'] = $this->config->get('payment_bluepay_redirect_transaction');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_total'])) {
+ $data['payment_bluepay_redirect_total'] = $this->request->post['payment_bluepay_redirect_total'];
+ } else {
+ $data['payment_bluepay_redirect_total'] = $this->config->get('payment_bluepay_redirect_total');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_card'])) {
+ $data['payment_bluepay_redirect_card'] = $this->request->post['payment_bluepay_redirect_card'];
+ } else {
+ $data['payment_bluepay_redirect_card'] = $this->config->get('payment_bluepay_redirect_card');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_order_status_id'])) {
+ $data['payment_bluepay_redirect_order_status_id'] = $this->request->post['payment_bluepay_redirect_order_status_id'];
+ } elseif ($this->config->get('payment_bluepay_redirect_order_status_id')) {
+ $data['payment_bluepay_redirect_order_status_id'] = $this->config->get('payment_bluepay_redirect_order_status_id');
+ } else {
+ $data['payment_bluepay_redirect_order_status_id'] = 2;
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_bluepay_redirect_geo_zone_id'])) {
+ $data['payment_bluepay_redirect_geo_zone_id'] = $this->request->post['payment_bluepay_redirect_geo_zone_id'];
+ } else {
+ $data['payment_bluepay_redirect_geo_zone_id'] = $this->config->get('payment_bluepay_redirect_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_bluepay_redirect_status'])) {
+ $data['payment_bluepay_redirect_status'] = $this->request->post['payment_bluepay_redirect_status'];
+ } else {
+ $data['payment_bluepay_redirect_status'] = $this->config->get('payment_bluepay_redirect_status');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_debug'])) {
+ $data['payment_bluepay_redirect_debug'] = $this->request->post['payment_bluepay_redirect_debug'];
+ } else {
+ $data['payment_bluepay_redirect_debug'] = $this->config->get('payment_bluepay_redirect_debug');
+ }
+
+ if (isset($this->request->post['payment_bluepay_redirect_sort_order'])) {
+ $data['payment_bluepay_redirect_sort_order'] = $this->request->post['payment_bluepay_redirect_sort_order'];
+ } else {
+ $data['payment_bluepay_redirect_sort_order'] = $this->config->get('payment_bluepay_redirect_sort_order');
+ }
+
+ $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/bluepay_redirect', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/bluepay_redirect');
+
+ $this->model_extension_payment_bluepay_redirect->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/bluepay_redirect');
+
+ $this->model_extension_payment_bluepay_redirect->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_bluepay_redirect_status')) {
+ $this->load->model('extension/payment/bluepay_redirect');
+
+ $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->get['order_id']);
+
+ if (!empty($bluepay_redirect_order)) {
+ $this->load->language('extension/payment/bluepay_redirect');
+
+ $bluepay_redirect_order['total_released'] = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']);
+
+ $bluepay_redirect_order['total_formatted'] = $this->currency->format($bluepay_redirect_order['total'], $bluepay_redirect_order['currency_code'], false, false);
+ $bluepay_redirect_order['total_released_formatted'] = $this->currency->format($bluepay_redirect_order['total_released'], $bluepay_redirect_order['currency_code'], false, false);
+
+ $data['bluepay_redirect_order'] = $bluepay_redirect_order;
+
+ $data['order_id'] = $this->request->get['order_id'];
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/bluepay_redirect_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/bluepay_redirect');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/bluepay_redirect');
+
+ $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_bluepay_redirect->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_bluepay_redirect->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if ($void_response['Result'] == 'APPROVED') {
+ $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'void', $bluepay_redirect_order['total']);
+ $this->model_extension_payment_bluepay_redirect->updateVoidStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['total'] = $bluepay_redirect_order['total'];
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response['MESSAGE']) && !empty($void_response['MESSAGE']) ? (string)$void_response['MESSAGE'] : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function release() {
+ $this->load->language('extension/payment/bluepay_redirect');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/bluepay_redirect');
+
+ $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']);
+
+ $release_response = $this->model_extension_payment_bluepay_redirect->release($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_bluepay_redirect->logger('Release result:\r\n' . print_r($release_response, 1));
+
+ if ($release_response['Result'] == 'APPROVED') {
+ $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'payment', $this->request->post['amount']);
+
+ $this->model_extension_payment_bluepay_redirect->updateTransactionId($bluepay_redirect_order['bluepay_redirect_order_id'], $release_response['RRNO']);
+
+ $total_released = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']);
+
+ if ($total_released >= $bluepay_redirect_order['total']) {
+ $this->model_extension_payment_bluepay_redirect->updateReleaseStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1);
+ $release_status = 1;
+ $json['msg'] = $this->language->get('text_release_ok_order');
+ } else {
+ $release_status = 0;
+ $json['msg'] = $this->language->get('text_release_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'];
+ $json['data']['release_status'] = $release_status;
+ $json['data']['total'] = (float)$total_released;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($release_response['MESSAGE']) && !empty($release_response['MESSAGE']) ? (string)$release_response['MESSAGE'] : 'Unable to release';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/bluepay_redirect');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/bluepay_redirect');
+
+ $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_bluepay_redirect->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_bluepay_redirect->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if ($rebate_response['Result'] == 'APPROVED') {
+ $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'rebate', $this->request->post['amount'] * -1);
+
+ $total_rebated = $this->model_extension_payment_bluepay_redirect->getTotalRebated($bluepay_redirect_order['bluepay_redirect_order_id']);
+ $total_released = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']);
+
+ if ($total_released <= 0 && $bluepay_redirect_order['release_status'] == 1) {
+ $this->model_extension_payment_bluepay_redirect->updateRebateStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'] * -1;
+ $json['data']['total_released'] = (float)$total_released;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response['MESSAGE']) && !empty($rebate_response['MESSAGE']) ? (string)$rebate_response['MESSAGE'] : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/bluepay_redirect')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_bluepay_redirect_account_id']) {
+ $this->error['account_id'] = $this->language->get('error_account_id');
+ }
+
+ if (!$this->request->post['payment_bluepay_redirect_secret_key']) {
+ $this->error['secret_key'] = $this->language->get('error_secret_key');
+ }
+
+ return !$this->error;
+ }
+
+ public function callback() {
+ $this->response->addHeader('Content-Type: application/json');
+
+ $this->response->setOutput(json_encode($this->request->get));
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/cardconnect.php b/public/admin/controller/extension/payment/cardconnect.php
new file mode 100644
index 0000000..8039cf4
--- /dev/null
+++ b/public/admin/controller/extension/payment/cardconnect.php
@@ -0,0 +1,501 @@
+<?php
+class ControllerExtensionPaymentCardConnect extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->model('setting/setting');
+
+ $this->load->model('extension/payment/cardconnect');
+
+ $this->load->language('extension/payment/cardconnect');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_cardconnect', $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));
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/cardconnect', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/cardconnect', '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_cardconnect_merchant_id'])) {
+ $data['payment_cardconnect_merchant_id'] = $this->request->post['payment_cardconnect_merchant_id'];
+ } else {
+ $data['payment_cardconnect_merchant_id'] = $this->config->get('payment_cardconnect_merchant_id');
+ }
+
+ if (isset($this->request->post['cardconnect_api_username'])) {
+ $data['cardconnect_api_username'] = $this->request->post['cardconnect_api_username'];
+ } else {
+ $data['cardconnect_api_username'] = $this->config->get('cardconnect_api_username');
+ }
+
+ if (isset($this->request->post['cardconnect_api_password'])) {
+ $data['cardconnect_api_password'] = $this->request->post['cardconnect_api_password'];
+ } else {
+ $data['cardconnect_api_password'] = $this->config->get('cardconnect_api_password');
+ }
+
+ if (isset($this->request->post['cardconnect_token'])) {
+ $data['cardconnect_token'] = $this->request->post['cardconnect_token'];
+ } elseif ($this->config->has('cardconnect_token')) {
+ $data['cardconnect_token'] = $this->config->get('cardconnect_token');
+ } else {
+ $data['cardconnect_token'] = md5(time());
+ }
+
+ if (isset($this->request->post['cardconnect_transaction'])) {
+ $data['cardconnect_transaction'] = $this->request->post['cardconnect_transaction'];
+ } else {
+ $data['cardconnect_transaction'] = $this->config->get('cardconnect_transaction');
+ }
+
+ if (isset($this->request->post['cardconnect_site'])) {
+ $data['cardconnect_site'] = $this->request->post['cardconnect_site'];
+ } elseif ($this->config->has('cardconnect_site')) {
+ $data['cardconnect_site'] = $this->config->get('cardconnect_site');
+ } else {
+ $data['cardconnect_site'] = 'fts';
+ }
+
+ if (isset($this->request->post['cardconnect_environment'])) {
+ $data['cardconnect_environment'] = $this->request->post['cardconnect_environment'];
+ } else {
+ $data['cardconnect_environment'] = $this->config->get('cardconnect_environment');
+ }
+
+ if (isset($this->request->post['cardconnect_store_cards'])) {
+ $data['cardconnect_store_cards'] = $this->request->post['cardconnect_store_cards'];
+ } else {
+ $data['cardconnect_store_cards'] = $this->config->get('cardconnect_store_cards');
+ }
+
+ if (isset($this->request->post['cardconnect_echeck'])) {
+ $data['cardconnect_echeck'] = $this->request->post['cardconnect_echeck'];
+ } else {
+ $data['cardconnect_echeck'] = $this->config->get('cardconnect_echeck');
+ }
+
+ if (isset($this->request->post['cardconnect_total'])) {
+ $data['cardconnect_total'] = $this->request->post['cardconnect_total'];
+ } else {
+ $data['cardconnect_total'] = $this->config->get('cardconnect_total');
+ }
+
+ if (isset($this->request->post['cardconnect_geo_zone'])) {
+ $data['cardconnect_geo_zone'] = $this->request->post['cardconnect_geo_zone'];
+ } else {
+ $data['cardconnect_geo_zone'] = $this->config->get('cardconnect_geo_zone');
+ }
+
+ if (isset($this->request->post['cardconnect_status'])) {
+ $data['cardconnect_status'] = $this->request->post['cardconnect_status'];
+ } else {
+ $data['cardconnect_status'] = $this->config->get('cardconnect_status');
+ }
+
+ if (isset($this->request->post['cardconnect_logging'])) {
+ $data['cardconnect_logging'] = $this->request->post['cardconnect_logging'];
+ } else {
+ $data['cardconnect_logging'] = $this->config->get('cardconnect_logging');
+ }
+
+ if (isset($this->request->post['cardconnect_sort_order'])) {
+ $data['cardconnect_sort_order'] = $this->request->post['cardconnect_sort_order'];
+ } else {
+ $data['cardconnect_sort_order'] = $this->config->get('cardconnect_sort_order');
+ }
+
+ $data['cardconnect_cron_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/cardconnect/cron&token=' . $data['cardconnect_token'];
+
+ if ($this->config->get('cardconnect_cron_time')) {
+ $data['cardconnect_cron_time'] = date($this->language->get('datetime_format'), strtotime($this->config->get('cardconnect_cron_time')));
+ } else {
+ $data['cardconnect_cron_time'] = $this->language->get('text_no_cron_time');
+ }
+
+ if (isset($this->request->post['cardconnect_order_status_id_pending'])) {
+ $data['cardconnect_order_status_id_pending'] = $this->request->post['cardconnect_order_status_id_pending'];
+ } elseif ($this->config->has('cardconnect_order_status_id_pending')) {
+ $data['cardconnect_order_status_id_pending'] = $this->config->get('cardconnect_order_status_id_pending');
+ } else {
+ $data['cardconnect_order_status_id_pending'] = '1';
+ }
+
+ if (isset($this->request->post['cardconnect_order_status_id_processing'])) {
+ $data['cardconnect_order_status_id_processing'] = $this->request->post['cardconnect_order_status_id_processing'];
+ } elseif ($this->config->has('cardconnect_order_status_id_processing')) {
+ $data['cardconnect_order_status_id_processing'] = $this->config->get('cardconnect_order_status_id_processing');
+ } else {
+ $data['cardconnect_order_status_id_processing'] = '2';
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->session->data['success'])) {
+ $data['success'] = $this->session->data['success'];
+
+ unset($this->session->data['success']);
+ } else {
+ $data['success'] = '';
+ }
+
+ if (isset($this->error['payment_cardconnect_merchant_id'])) {
+ $data['error_payment_cardconnect_merchant_id'] = $this->error['payment_cardconnect_merchant_id'];
+ } else {
+ $data['error_payment_cardconnect_merchant_id'] = '';
+ }
+
+ if (isset($this->error['cardconnect_api_username'])) {
+ $data['error_cardconnect_api_username'] = $this->error['cardconnect_api_username'];
+ } else {
+ $data['error_cardconnect_api_username'] = '';
+ }
+
+ if (isset($this->error['cardconnect_api_password'])) {
+ $data['error_cardconnect_api_password'] = $this->error['cardconnect_api_password'];
+ } else {
+ $data['error_cardconnect_api_password'] = '';
+ }
+
+ if (isset($this->error['cardconnect_token'])) {
+ $data['error_cardconnect_token'] = $this->error['cardconnect_token'];
+ } else {
+ $data['error_cardconnect_token'] = '';
+ }
+
+ if (isset($this->error['cardconnect_site'])) {
+ $data['error_cardconnect_site'] = $this->error['cardconnect_site'];
+ } else {
+ $data['error_cardconnect_site'] = '';
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $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/cardconnect', $data));
+ }
+
+ public function install() {
+ if ($this->user->hasPermission('modify', 'marketplace/extension')) {
+ $this->load->model('extension/payment/cardconnect');
+
+ $this->model_extension_payment_cardconnect->install();
+ }
+ }
+
+ public function uninstall() {
+ if ($this->user->hasPermission('modify', 'marketplace/extension')) {
+ $this->load->model('extension/payment/cardconnect');
+
+ $this->model_extension_payment_cardconnect->uninstall();
+ }
+ }
+
+ public function order() {
+ if ($this->config->get('cardconnect_status')) {
+ $this->load->model('extension/payment/cardconnect');
+
+ $order_id = $this->request->get['order_id'];
+
+ $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->get['order_id']);
+
+ if ($cardconnect_order) {
+ $this->load->language('extension/payment/cardconnect');
+
+ if ($cardconnect_order['payment_method'] == 'card') {
+ $cardconnect_order['payment_method'] = $this->language->get('text_card');
+ } else {
+ $cardconnect_order['payment_method'] = $this->language->get('text_echeck');
+ }
+
+ $cardconnect_order['total_formatted'] = $this->currency->format($cardconnect_order['total'], $cardconnect_order['currency_code'], false, true);
+
+ $cardconnect_order['total_captured'] = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']);
+
+ $cardconnect_order['total_captured_formatted'] = $this->currency->format($cardconnect_order['total_captured'], $cardconnect_order['currency_code'], false, true);
+
+ foreach($cardconnect_order['transactions'] as &$transaction) {
+ switch ($transaction['type']) {
+ case 'payment':
+ $transaction['type'] = 'Payment';
+ break;
+ case 'auth':
+ $transaction['type'] = 'Authorize';
+ break;
+ case 'refund':
+ $transaction['type'] = 'Refund';
+ break;
+ case 'void':
+ $transaction['type'] = 'Void';
+ break;
+ default:
+ $transaction['type'] = 'Payment';
+ }
+
+ $transaction['amount'] = $this->currency->format($transaction['amount'], $cardconnect_order['currency_code'], false, true);
+
+ if ($transaction['status'] == 'Y') {
+ $transaction['status'] = 'Accepted';
+ } else if ($transaction['status'] == 'N') {
+ $transaction['status'] = 'Rejected';
+ }
+
+ $transaction['date_modified'] = date($this->language->get('datetime_format'), strtotime($transaction['date_modified']));
+
+ $transaction['date_added'] = date($this->language->get('datetime_format'), strtotime($transaction['date_added']));
+ }
+
+ $data['cardconnect_order'] = $cardconnect_order;
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/cardconnect_order', $data);
+ }
+ }
+ }
+
+ public function inquire() {
+ $this->load->language('extension/payment/cardconnect');
+
+ $json = array();
+
+ if ($this->config->get('cardconnect_status')) {
+ if (isset($this->request->post['order_id']) && isset($this->request->post['retref'])) {
+ $this->load->model('extension/payment/cardconnect');
+
+ $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']);
+
+ if ($cardconnect_order) {
+ $inquire_response = $this->model_extension_payment_cardconnect->inquire($cardconnect_order, $this->request->post['retref']);
+
+ if (isset($inquire_response['respstat']) && $inquire_response['respstat'] == 'C') {
+ $json['error'] = $inquire_response['resptext'];
+ } else {
+ $this->model_extension_payment_cardconnect->updateTransactionStatusByRetref($this->request->post['retref'], $inquire_response['setlstat']);
+
+ $json['status'] = $inquire_response['setlstat'];
+
+ $json['date_modified'] = date($this->language->get('datetime_format'));
+
+ $json['success'] = $this->language->get('text_inquire_success');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_no_order');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_data_missing');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_enabled');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/cardconnect');
+
+ $json = array();
+
+ if ($this->config->get('cardconnect_status')) {
+ if (isset($this->request->post['order_id']) && isset($this->request->post['amount'])) {
+ if ($this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/cardconnect');
+
+ $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']);
+
+ if ($cardconnect_order) {
+ $capture_response = $this->model_extension_payment_cardconnect->capture($cardconnect_order, $this->request->post['amount']);
+
+ if (!isset($capture_response['retref'])) {
+ $json['error'] = $this->language->get('error_invalid_response');
+ } else if (isset($capture_response['respstat']) && $capture_response['respstat'] == 'C') {
+ $json['error'] = $capture_response['resptext'];
+ } else {
+ $this->model_extension_payment_cardconnect->addTransaction($cardconnect_order['cardconnect_order_id'], 'payment', $capture_response['retref'], $this->request->post['amount'], $capture_response['setlstat']);
+
+ $total_captured = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']);
+
+ $json['retref'] = $capture_response['retref'];
+ $json['amount'] = $this->currency->format($this->request->post['amount'], $cardconnect_order['currency_code'], false, true);
+ $json['status'] = $capture_response['setlstat'];
+ $json['date_modified'] = date($this->language->get('datetime_format'));
+ $json['date_added'] = date($this->language->get('datetime_format'));
+ $json['total_captured'] = $this->currency->format($total_captured, $cardconnect_order['currency_code'], false, true);
+
+ $json['success'] = $this->language->get('text_capture_success');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_no_order');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_amount_zero');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_data_missing');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_enabled');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/cardconnect');
+
+ $json = array();
+
+ if ($this->config->get('cardconnect_status')) {
+ if (isset($this->request->post['order_id']) && isset($this->request->post['amount'])) {
+ if ($this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/cardconnect');
+
+ $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']);
+
+ if ($cardconnect_order) {
+ $refund_response = $this->model_extension_payment_cardconnect->refund($cardconnect_order, $this->request->post['amount']);
+
+ if (!isset($refund_response['retref'])) {
+ $json['error'] = $this->language->get('error_invalid_response');
+ } else if (isset($refund_response['respstat']) && $refund_response['respstat'] == 'C') {
+ $json['error'] = $refund_response['resptext'];
+ } else {
+ $this->model_extension_payment_cardconnect->addTransaction($cardconnect_order['cardconnect_order_id'], 'refund', $refund_response['retref'], $this->request->post['amount'] * -1, $refund_response['resptext']);
+
+ $total_captured = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']);
+
+ $json['retref'] = $refund_response['retref'];
+ $json['amount'] = $this->currency->format($this->request->post['amount'] * -1, $cardconnect_order['currency_code'], false, true);
+ $json['status'] = $refund_response['resptext'];
+ $json['date_modified'] = date($this->language->get('datetime_format'));
+ $json['date_added'] = date($this->language->get('datetime_format'));
+ $json['total_captured'] = $this->currency->format($total_captured, $cardconnect_order['currency_code'], false, true);
+
+ $json['success'] = $this->language->get('text_refund_success');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_no_order');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_amount_zero');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_data_missing');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_enabled');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/cardconnect');
+
+ $json = array();
+
+ if ($this->config->get('cardconnect_status')) {
+ if (isset($this->request->post['order_id']) && isset($this->request->post['retref'])) {
+ $this->load->model('extension/payment/cardconnect');
+
+ $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']);
+
+ if ($cardconnect_order) {
+ $void_response = $this->model_extension_payment_cardconnect->void($cardconnect_order, $this->request->post['retref']);
+
+ if (!isset($void_response['authcode']) || $void_response['authcode'] != 'REVERS') {
+ $json['error'] = $void_response['resptext'];
+ } else {
+ $json['retref'] = $void_response['retref'];
+ $json['amount'] = $this->currency->format(0.00, $cardconnect_order['currency_code'], false, true);
+ $json['status'] = $void_response['resptext'];
+ $json['date_modified'] = date($this->language->get('datetime_format'));
+ $json['date_added'] = date($this->language->get('datetime_format'));
+ $json['success'] = $this->language->get('text_void_success');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_no_order');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_data_missing');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_enabled');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/cardconnect')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_cardconnect_merchant_id']) {
+ $this->error['payment_cardconnect_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['cardconnect_api_username']) {
+ $this->error['cardconnect_api_username'] = $this->language->get('error_api_username');
+ }
+
+ if (!$this->request->post['cardconnect_api_password']) {
+ $this->error['cardconnect_api_password'] = $this->language->get('error_api_password');
+ }
+
+ if (!$this->request->post['cardconnect_token']) {
+ $this->error['cardconnect_token'] = $this->language->get('error_token');
+ }
+
+ if (!$this->request->post['cardconnect_site']) {
+ $this->error['cardconnect_site'] = $this->language->get('error_site');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/cardinity.php b/public/admin/controller/extension/payment/cardinity.php
new file mode 100644
index 0000000..a6beda6
--- /dev/null
+++ b/public/admin/controller/extension/payment/cardinity.php
@@ -0,0 +1,304 @@
+<?php
+class ControllerExtensionPaymentCardinity extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/cardinity');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_cardinity', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['key'])) {
+ $data['error_key'] = $this->error['key'];
+ } else {
+ $data['error_key'] = '';
+ }
+
+ if (isset($this->error['secret'])) {
+ $data['error_secret'] = $this->error['secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/cardinity', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/cardinity', '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_cardinity_key'])) {
+ $data['payment_cardinity_key'] = $this->request->post['payment_cardinity_key'];
+ } else {
+ $data['payment_cardinity_key'] = $this->config->get('payment_cardinity_key');
+ }
+
+ if (isset($this->request->post['payment_cardinity_secret'])) {
+ $data['payment_cardinity_secret'] = $this->request->post['payment_cardinity_secret'];
+ } else {
+ $data['payment_cardinity_secret'] = $this->config->get('payment_cardinity_secret');
+ }
+
+ if (isset($this->request->post['payment_cardinity_debug'])) {
+ $data['payment_cardinity_debug'] = $this->request->post['payment_cardinity_debug'];
+ } else {
+ $data['payment_cardinity_debug'] = $this->config->get('payment_cardinity_debug');
+ }
+
+ if (isset($this->request->post['payment_cardinity_total'])) {
+ $data['payment_cardinity_total'] = $this->request->post['payment_cardinity_total'];
+ } else {
+ $data['payment_cardinity_total'] = $this->config->get('payment_cardinity_total');
+ }
+
+ if (isset($this->request->post['payment_cardinity_order_status_id'])) {
+ $data['payment_cardinity_order_status_id'] = $this->request->post['payment_cardinity_order_status_id'];
+ } else {
+ $data['payment_cardinity_order_status_id'] = $this->config->get('payment_cardinity_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_cardinity_geo_zone_id'])) {
+ $data['payment_cardinity_geo_zone_id'] = $this->request->post['payment_cardinity_geo_zone_id'];
+ } else {
+ $data['payment_cardinity_geo_zone_id'] = $this->config->get('payment_cardinity_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_cardinity_status'])) {
+ $data['payment_cardinity_status'] = $this->request->post['payment_cardinity_status'];
+ } else {
+ $data['payment_cardinity_status'] = $this->config->get('payment_cardinity_status');
+ }
+
+ if (isset($this->request->post['payment_cardinity_sort_order'])) {
+ $data['payment_cardinity_sort_order'] = $this->request->post['payment_cardinity_sort_order'];
+ } else {
+ $data['payment_cardinity_sort_order'] = $this->config->get('payment_cardinity_sort_order');
+ }
+
+ $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/cardinity', $data));
+ }
+
+ public function order() {
+ $this->load->language('extension/payment/cardinity');
+
+ $data['user_token'] = $this->session->data['user_token'];
+ $data['order_id'] = $this->request->get['order_id'];
+
+ return $this->load->view('extension/payment/cardinity_order', $data);
+ }
+
+ public function getPayment() {
+ $this->load->language('extension/payment/cardinity');
+
+ $this->load->model('extension/payment/cardinity');
+
+ $data['column_refund'] = $this->language->get('column_refund');
+ $data['column_date'] = $this->language->get('column_date');
+ $data['column_refund_history'] = $this->language->get('column_refund_history');
+ $data['column_action'] = $this->language->get('column_action');
+ $data['column_status'] = $this->language->get('column_status');
+ $data['column_amount'] = $this->language->get('column_amount');
+ $data['column_description'] = $this->language->get('column_description');
+
+ $data['button_refund'] = $this->language->get('button_refund');
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $client = $this->model_extension_payment_cardinity->createClient(array(
+ 'key' => $this->config->get('payment_cardinity_key'),
+ 'secret' => $this->config->get('payment_cardinity_secret')
+ ));
+
+ $order = $this->model_extension_payment_cardinity->getOrder($this->request->get['order_id']);
+
+ $data['payment'] = false;
+
+ $data['refunds'] = array();
+
+ if ($order && $order['payment_id']) {
+ $data['payment'] = true;
+
+ $payment = $this->model_extension_payment_cardinity->getPayment($client, $order['payment_id']);
+
+ $data['refund_action'] = false;
+
+ $successful_statuses = array(
+ 'approved'
+ );
+
+ if (in_array($payment->getStatus(), $successful_statuses)) {
+ $data['refund_action'] = true;
+ }
+
+ $max_refund_amount = $payment->getAmount();
+
+ $refunds = $this->model_extension_payment_cardinity->getRefunds($client, $order['payment_id']);
+
+ if ($refunds) {
+ foreach ($refunds as $refund) {
+ $successful_refund_statuses = array(
+ 'approved'
+ );
+
+ if (in_array($refund->getStatus(), $successful_refund_statuses)) {
+ $max_refund_amount -= $refund->getAmount();
+ }
+
+ $data['refunds'][] = array(
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($refund->getCreated())),
+ 'amount' => $this->currency->format($refund->getAmount(), $refund->getCurrency(), '1.00000000', true),
+ 'status' => $refund->getStatus(),
+ 'description' => $refund->getDescription()
+ );
+ }
+ }
+
+ if (!$max_refund_amount) {
+ $data['refund_action'] = false;
+ }
+
+ $data['payment_id'] = $payment->getId();
+ $data['symbol_left'] = $this->currency->getSymbolLeft($payment->getCurrency());
+ $data['symbol_right'] = $this->currency->getSymbolRight($payment->getCurrency());
+
+ $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $payment->getCurrency(), '1.00000000', false);
+ }
+
+ $this->response->setOutput($this->load->view('extension/payment/cardinity_order_ajax', $data));
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/cardinity');
+
+ $this->load->model('extension/payment/cardinity');
+
+ $json = array();
+
+ $success = $error = '';
+
+ $client = $this->model_extension_payment_cardinity->createClient(array(
+ 'key' => $this->config->get('payment_cardinity_key'),
+ 'secret' => $this->config->get('payment_cardinity_secret')
+ ));
+
+ $refund = $this->model_extension_payment_cardinity->refundPayment($client, $this->request->post['payment_id'], (float)number_format($this->request->post['amount'], 2), $this->request->post['description']);
+
+ if ($refund) {
+ $success = $this->language->get('text_success_action');
+ } else {
+ $error = $this->language->get('text_error_generic');
+ }
+
+ $json['success'] = $success;
+ $json['error'] = $error;
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ $this->load->model('extension/payment/cardinity');
+
+ $check_credentials = true;
+
+ if (version_compare(phpversion(), '5.4.0', '<')) {
+ $this->error['warning'] = $this->language->get('error_php_version');
+ }
+
+ if (!$this->user->hasPermission('modify', 'extension/payment/cardinity')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+
+ $check_credentials = false;
+ }
+
+ if (!$this->request->post['payment_cardinity_key']) {
+ $this->error['key'] = $this->language->get('error_key');
+
+ $check_credentials = false;
+ }
+
+ if (!$this->request->post['payment_cardinity_secret']) {
+ $this->error['secret'] = $this->language->get('error_secret');
+
+ $check_credentials = false;
+ }
+
+ if (!class_exists('Cardinity\Client')) {
+ $this->error['warning'] = $this->language->get('error_composer');
+
+ $check_credentials = false;
+ }
+
+ if ($check_credentials) {
+ $client = $this->model_extension_payment_cardinity->createClient(array(
+ 'key' => $this->request->post['payment_cardinity_key'],
+ 'secret' => $this->request->post['payment_cardinity_secret']
+ ));
+
+ $verify_credentials = $this->model_extension_payment_cardinity->verifyCredentials($client);
+
+ if (!$verify_credentials) {
+ $this->error['warning'] = $this->language->get('error_connection');
+ }
+ }
+
+ if ($this->error && !isset($this->error['warning'])) {
+ $this->error['warning'] = $this->language->get('error_warning');
+ }
+
+ return !$this->error;
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/cardinity');
+
+ $this->model_extension_payment_cardinity->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/cardinity');
+
+ $this->model_extension_payment_cardinity->uninstall();
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/cheque.php b/public/admin/controller/extension/payment/cheque.php
new file mode 100644
index 0000000..0b77697
--- /dev/null
+++ b/public/admin/controller/extension/payment/cheque.php
@@ -0,0 +1,115 @@
+<?php
+class ControllerExtensionPaymentCheque extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/cheque');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_cheque', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['payable'])) {
+ $data['error_payable'] = $this->error['payable'];
+ } else {
+ $data['error_payable'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/cheque', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/cheque', '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_cheque_payable'])) {
+ $data['payment_cheque_payable'] = $this->request->post['payment_cheque_payable'];
+ } else {
+ $data['payment_cheque_payable'] = $this->config->get('payment_cheque_payable');
+ }
+
+ if (isset($this->request->post['payment_cheque_total'])) {
+ $data['payment_cheque_total'] = $this->request->post['payment_cheque_total'];
+ } else {
+ $data['payment_cheque_total'] = $this->config->get('payment_cheque_total');
+ }
+
+ if (isset($this->request->post['payment_cheque_order_status_id'])) {
+ $data['payment_cheque_order_status_id'] = $this->request->post['payment_cheque_order_status_id'];
+ } else {
+ $data['payment_cheque_order_status_id'] = $this->config->get('payment_cheque_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_cheque_geo_zone_id'])) {
+ $data['payment_cheque_geo_zone_id'] = $this->request->post['payment_cheque_geo_zone_id'];
+ } else {
+ $data['payment_cheque_geo_zone_id'] = $this->config->get('payment_cheque_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_cheque_status'])) {
+ $data['payment_cheque_status'] = $this->request->post['payment_cheque_status'];
+ } else {
+ $data['payment_cheque_status'] = $this->config->get('payment_cheque_status');
+ }
+
+ if (isset($this->request->post['payment_cheque_sort_order'])) {
+ $data['payment_cheque_sort_order'] = $this->request->post['payment_cheque_sort_order'];
+ } else {
+ $data['payment_cheque_sort_order'] = $this->config->get('payment_cheque_sort_order');
+ }
+
+ $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/cheque', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/cheque')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_cheque_payable']) {
+ $this->error['payable'] = $this->language->get('error_payable');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/cod.php b/public/admin/controller/extension/payment/cod.php
new file mode 100644
index 0000000..46c351d
--- /dev/null
+++ b/public/admin/controller/extension/payment/cod.php
@@ -0,0 +1,99 @@
+<?php
+class ControllerExtensionPaymentCod extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/cod');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_cod', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/cod', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/cod', '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_cod_total'])) {
+ $data['payment_cod_total'] = $this->request->post['payment_cod_total'];
+ } else {
+ $data['payment_cod_total'] = $this->config->get('payment_cod_total');
+ }
+
+ if (isset($this->request->post['payment_cod_order_status_id'])) {
+ $data['payment_cod_order_status_id'] = $this->request->post['payment_cod_order_status_id'];
+ } else {
+ $data['payment_cod_order_status_id'] = $this->config->get('payment_cod_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_cod_geo_zone_id'])) {
+ $data['payment_cod_geo_zone_id'] = $this->request->post['payment_cod_geo_zone_id'];
+ } else {
+ $data['payment_cod_geo_zone_id'] = $this->config->get('payment_cod_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_cod_status'])) {
+ $data['payment_cod_status'] = $this->request->post['payment_cod_status'];
+ } else {
+ $data['payment_cod_status'] = $this->config->get('payment_cod_status');
+ }
+
+ if (isset($this->request->post['payment_cod_sort_order'])) {
+ $data['payment_cod_sort_order'] = $this->request->post['payment_cod_sort_order'];
+ } else {
+ $data['payment_cod_sort_order'] = $this->config->get('payment_cod_sort_order');
+ }
+
+ $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/cod', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/cod')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/divido.php b/public/admin/controller/extension/payment/divido.php
new file mode 100644
index 0000000..d358764
--- /dev/null
+++ b/public/admin/controller/extension/payment/divido.php
@@ -0,0 +1,215 @@
+<?php
+class ControllerExtensionPaymentDivido extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/divido');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+ $this->load->model('extension/payment/divido');
+
+ if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_divido', $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));
+ }
+
+ $data['entry_plans_options'] = array(
+ 'all' => $this->language->get('entry_plans_options_all'),
+ 'selected' => $this->language->get('entry_plans_options_selected'),
+ );
+
+ $data['entry_products_options']= array(
+ 'all' => $this->language->get('entry_products_options_all'),
+ 'selected' => $this->language->get('entry_products_options_selected'),
+ 'threshold' => $this->language->get('entry_products_options_threshold'),
+ );
+
+ $data['button_save'] = $this->language->get('button_save');
+ $data['button_cancel'] = $this->language->get('button_cancel');
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/divido', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/divido', 'user_token=' . $this->session->data['user_token'], 'SSL');
+
+ $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', 'SSL');
+
+ if (isset($this->request->post['payment_divido_api_key'])) {
+ $data['payment_divido_api_key'] = $this->request->post['payment_divido_api_key'];
+ } else {
+ $data['payment_divido_api_key'] = $this->config->get('payment_divido_api_key');
+ }
+
+ if (isset($this->request->post['payment_divido_order_status_id'])) {
+ $data['payment_divido_order_status_id'] = $this->request->post['payment_divido_order_status_id'];
+ } elseif ($this->config->get('payment_divido_order_status_id')) {
+ $data['payment_divido_order_status_id'] = $this->config->get('payment_divido_order_status_id');
+ } else {
+ $data['payment_divido_order_status_id'] = 2;
+ }
+
+ if (isset($this->request->post['payment_divido_status'])) {
+ $data['payment_divido_status'] = $this->request->post['payment_divido_status'];
+ } else {
+ $data['payment_divido_status'] = $this->config->get('payment_divido_status');
+ }
+
+ if (isset($this->request->post['payment_divido_sort_order'])) {
+ $data['payment_divido_sort_order'] = $this->request->post['payment_divido_sort_order'];
+ } else {
+ $data['payment_divido_sort_order'] = $this->config->get('payment_divido_sort_order');
+ }
+
+ if (isset($this->request->post['payment_divido_title'])) {
+ $data['payment_divido_title'] = $this->request->post['payment_divido_title'];
+ } else {
+ $data['payment_divido_title'] = $this->config->get('payment_divido_title');
+ }
+
+ if (isset($this->request->post['payment_divido_productselection'])) {
+ $data['payment_divido_productselection'] = $this->request->post['payment_divido_productselection'];
+ } else {
+ $data['payment_divido_productselection'] = $this->config->get('payment_divido_productselection');
+ }
+
+ if (isset($this->request->post['payment_divido_price_threshold'])) {
+ $data['payment_divido_price_threshold'] = $this->request->post['payment_divido_price_threshold'];
+ } else {
+ $data['payment_divido_price_threshold'] = $this->config->get('payment_divido_price_threshold');
+ }
+
+ if (isset($this->request->post['payment_divido_cart_threshold'])) {
+ $data['payment_divido_cart_threshold'] = $this->request->post['payment_divido_cart_threshold'];
+ } else {
+ $data['payment_divido_cart_threshold'] = $this->config->get('payment_divido_cart_threshold');
+ }
+
+ if (isset($this->request->post['payment_divido_planselection'])) {
+ $data['payment_divido_planselection'] = $this->request->post['payment_divido_planselection'];
+ } else {
+ $data['payment_divido_planselection'] = $this->config->get('payment_divido_planselection');
+ }
+
+ if (isset($this->request->post['payment_divido_plans_selected'])) {
+ $data['payment_divido_plans_selected'] = $this->request->post['payment_divido_plans_selected'];
+ } elseif ($this->config->get('payment_divido_plans_selected')) {
+ $data['payment_divido_plans_selected'] = $this->config->get('payment_divido_plans_selected');
+ } else {
+ $data['payment_divido_plans_selected'] = array();
+ }
+
+ if (isset($this->request->post['payment_divido_categories'])) {
+ $data['payment_divido_categories'] = $this->request->post['payment_divido_categories'];
+ } elseif ($this->config->get('payment_divido_categories')) {
+ $data['payment_divido_categories'] = $this->config->get('payment_divido_categories');
+ } else {
+ $data['payment_divido_categories'] = array();
+ }
+
+ $data['categories'] = array();
+
+ $this->load->model('catalog/category');
+
+ foreach ($data['payment_divido_categories'] as $category_id) {
+ $category_info = $this->model_catalog_category->getCategory($category_id);
+
+ if ($category_info) {
+ $data['categories'][] = array(
+ 'category_id' => $category_info['category_id'],
+ 'name' => ($category_info['path']) ? $category_info['path'] . ' &gt; ' . $category_info['name'] : $category_info['name']
+ );
+ }
+ }
+
+ try {
+ $data['divido_plans'] = $this->model_extension_payment_divido->getAllPlans();
+ } catch (Exception $e) {
+ $this->log->write($e->getMessage());
+ $data['divido_plans'] = array();
+ }
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $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/divido', $data));
+ }
+
+
+ public function order() {
+ if (!$this->config->get('payment_divido_status')) {
+ return null;
+ }
+
+ $this->load->model('extension/payment/divido');
+ $this->load->language('extension/payment/divido');
+
+ $order_id = $this->request->get['order_id'];
+
+ $lookup = $this->model_extension_payment_divido->getLookupByOrderId($order_id);
+ $proposal_id = null;
+ $application_id = null;
+ $deposit_amount = null;
+ if ($lookup->num_rows == 1) {
+ $lookup_data = $lookup->row;
+ $proposal_id = $lookup_data['proposal_id'];
+ $application_id = $lookup_data['application_id'];
+ $deposit_amount = $lookup_data['deposit_amount'];
+ }
+
+ $data['proposal_id'] = $proposal_id;
+ $data['application_id'] = $application_id;
+ $data['deposit_amount'] = $deposit_amount;
+
+ return $this->load->view('extension/payment/divido_order', $data);
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/divido');
+ $this->model_extension_payment_divido->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/divido');
+ $this->model_extension_payment_divido->uninstall();
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/divido')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/eway.php b/public/admin/controller/extension/payment/eway.php
new file mode 100644
index 0000000..26f8c43
--- /dev/null
+++ b/public/admin/controller/extension/payment/eway.php
@@ -0,0 +1,371 @@
+<?php
+class ControllerExtensionPaymentEway extends Controller {
+
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/eway');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
+ $this->model_setting_setting->editSetting('payment_eway', $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'], true));
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['username'])) {
+ $data['error_username'] = $this->error['username'];
+ } else {
+ $data['error_username'] = '';
+ }
+
+ if (isset($this->error['password'])) {
+ $data['error_password'] = $this->error['password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ if (isset($this->error['payment_type'])) {
+ $data['error_payment_type'] = $this->error['payment_type'];
+ } else {
+ $data['error_payment_type'] = '';
+ }
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_extension'),
+ 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/eway', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/eway', 'user_token=' . $this->session->data['user_token'], true);
+ $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true);
+
+ if (isset($this->request->post['payment_eway_payment_gateway'])) {
+ $data['payment_eway_payment_gateway'] = $this->request->post['payment_eway_payment_gateway'];
+ } else {
+ $data['payment_eway_payment_gateway'] = $this->config->get('payment_eway_payment_gateway');
+ }
+
+ if (isset($this->request->post['payment_eway_paymode'])) {
+ $data['payment_eway_paymode'] = $this->request->post['payment_eway_paymode'];
+ } else {
+ $data['payment_eway_paymode'] = $this->config->get('payment_eway_paymode');
+ }
+
+ if (isset($this->request->post['payment_eway_test'])) {
+ $data['payment_eway_test'] = $this->request->post['payment_eway_test'];
+ } else {
+ $data['payment_eway_test'] = $this->config->get('payment_eway_test');
+ }
+
+ if (isset($this->request->post['payment_eway_payment_type'])) {
+ $data['payment_eway_payment_type'] = $this->request->post['payment_eway_payment_type'];
+ } else {
+ $data['payment_eway_payment_type'] = $this->config->get('payment_eway_payment_type');
+ }
+
+ if (isset($this->request->post['payment_eway_transaction'])) {
+ $data['payment_eway_transaction'] = $this->request->post['payment_eway_transaction'];
+ } else {
+ $data['payment_eway_transaction'] = $this->config->get('payment_eway_transaction');
+ }
+
+ if (isset($this->request->post['payment_eway_standard_geo_zone_id'])) {
+ $data['payment_eway_standard_geo_zone_id'] = $this->request->post['payment_eway_standard_geo_zone_id'];
+ } else {
+ $data['payment_eway_standard_geo_zone_id'] = $this->config->get('payment_eway_standard_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_eway_order_status_id'])) {
+ $data['payment_eway_order_status_id'] = $this->request->post['payment_eway_order_status_id'];
+ } else {
+ $data['payment_eway_order_status_id'] = $this->config->get('payment_eway_order_status_id');
+ }
+
+ if (isset($this->request->post['payment_eway_order_status_refunded_id'])) {
+ $data['payment_eway_order_status_refunded_id'] = $this->request->post['payment_eway_order_status_refunded_id'];
+ } else {
+ $data['payment_eway_order_status_refunded_id'] = $this->config->get('payment_eway_order_status_refunded_id');
+ }
+
+ if (isset($this->request->post['payment_eway_order_status_auth_id'])) {
+ $data['payment_eway_order_status_auth_id'] = $this->request->post['payment_eway_order_status_auth_id'];
+ } else {
+ $data['payment_eway_order_status_auth_id'] = $this->config->get('payment_eway_order_status_auth_id');
+ }
+
+ if (isset($this->request->post['payment_eway_order_status_fraud_id'])) {
+ $data['payment_eway_order_status_fraud_id'] = $this->request->post['payment_eway_order_status_fraud_id'];
+ } else {
+ $data['payment_eway_order_status_fraud_id'] = $this->config->get('payment_eway_order_status_fraud_id');
+ }
+
+ if (isset($this->request->post['payment_eway_transaction_method'])) {
+ $data['payment_eway_transaction_method'] = $this->request->post['payment_eway_transaction_method'];
+ } else {
+ $data['payment_eway_transaction_method'] = $this->config->get('payment_eway_transaction_method');
+ }
+
+ if (isset($this->request->post['payment_eway_username'])) {
+ $data['payment_eway_username'] = $this->request->post['payment_eway_username'];
+ } else {
+ $data['payment_eway_username'] = $this->config->get('payment_eway_username');
+ }
+
+ if (isset($this->request->post['payment_eway_password'])) {
+ $data['payment_eway_password'] = $this->request->post['payment_eway_password'];
+ } else {
+ $data['payment_eway_password'] = $this->config->get('payment_eway_password');
+ }
+
+ if (isset($this->request->post['payment_eway_status'])) {
+ $data['payment_eway_status'] = $this->request->post['payment_eway_status'];
+ } else {
+ $data['payment_eway_status'] = $this->config->get('payment_eway_status');
+ }
+
+ if (isset($this->request->post['payment_eway_sort_order'])) {
+ $data['payment_eway_sort_order'] = $this->request->post['payment_eway_sort_order'];
+ } else {
+ $data['payment_eway_sort_order'] = $this->config->get('payment_eway_sort_order');
+ }
+
+ $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/eway', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/eway');
+ $this->model_extension_payment_eway->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/eway');
+ $this->model_extension_payment_eway->uninstall();
+ }
+
+ // Legacy 2.0.0
+ public function orderAction() {
+ return $this->order();
+ }
+
+ // Legacy 2.0.3
+ public function action() {
+ return $this->order();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_eway_status')) {
+ $this->load->model('extension/payment/eway');
+
+ $eway_order = $this->model_extension_payment_eway->getOrder($this->request->get['order_id']);
+
+ if (!empty($eway_order)) {
+ $this->load->language('extension/payment/eway');
+
+ $eway_order['total'] = $eway_order['amount'];
+ $eway_order['total_formatted'] = $this->currency->format($eway_order['amount'], $eway_order['currency_code'], 1, true);
+
+ $eway_order['total_captured'] = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']);
+ $eway_order['total_captured_formatted'] = $this->currency->format($eway_order['total_captured'], $eway_order['currency_code'], 1, true);
+
+ $eway_order['uncaptured'] = $eway_order['total'] - $eway_order['total_captured'];
+
+ $eway_order['total_refunded'] = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']);
+ $eway_order['total_refunded_formatted'] = $this->currency->format($eway_order['total_refunded'], $eway_order['currency_code'], 1, true);
+
+ $eway_order['unrefunded'] = $eway_order['total_captured'] - $eway_order['total_refunded'];
+
+ $data['text_payment_info'] = $this->language->get('text_payment_info');
+ $data['text_order_total'] = $this->language->get('text_order_total');
+ $data['text_void_status'] = $this->language->get('text_void_status');
+ $data['text_transactions'] = $this->language->get('text_transactions');
+ $data['text_column_amount'] = $this->language->get('text_column_amount');
+ $data['text_column_type'] = $this->language->get('text_column_type');
+ $data['text_column_created'] = $this->language->get('text_column_created');
+ $data['text_column_transactionid'] = $this->language->get('text_column_transactionid');
+ $data['btn_refund'] = $this->language->get('btn_refund');
+ $data['btn_capture'] = $this->language->get('btn_capture');
+ $data['text_confirm_refund'] = $this->language->get('text_confirm_refund');
+ $data['text_confirm_capture'] = $this->language->get('text_confirm_capture');
+
+ $data['text_total_captured'] = $this->language->get('text_total_captured');
+ $data['text_total_refunded'] = $this->language->get('text_total_refunded');
+ $data['text_capture_status'] = $this->language->get('text_capture_status');
+ $data['text_refund_status'] = $this->language->get('text_refund_status');
+
+ $data['text_empty_refund'] = $this->language->get('text_empty_refund');
+ $data['text_empty_capture'] = $this->language->get('text_empty_capture');
+
+ $data['eway_order'] = $eway_order;
+ $data['user_token'] = $this->request->get['user_token'];
+ $data['order_id'] = $this->request->get['order_id'];
+
+ return $this->load->view('extension/payment/eway_order', $data);
+ }
+ }
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/eway');
+
+ $order_id = $this->request->post['order_id'];
+ $refund_amount = (double)$this->request->post['refund_amount'];
+
+ if ($order_id && $refund_amount > 0) {
+ $this->load->model('extension/payment/eway');
+ $result = $this->model_extension_payment_eway->refund($order_id, $refund_amount);
+
+ // Check if any error returns
+ if (isset($result->Errors) || $result === false) {
+ $json['error'] = true;
+ $reason = '';
+ if ($result === false) {
+ $reason = $this->language->get('text_unknown_failure');
+ } else {
+ $errors = explode(',', $result->Errors);
+ foreach ($errors as $error) {
+ $reason .= $this->language->get('text_card_message_' . $result->Errors);
+ }
+ }
+ $json['message'] = $this->language->get('text_refund_failed') . $reason;
+ } else {
+ $eway_order = $this->model_extension_payment_eway->getOrder($order_id);
+ $this->model_extension_payment_eway->addTransaction($eway_order['eway_order_id'], $result->Refund->TransactionID, 'refund', $result->Refund->TotalAmount / 100, $eway_order['currency_code']);
+
+ $total_captured = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']);
+ $total_refunded = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']);
+ $refund_status = 0;
+
+ if ($total_captured == $total_refunded) {
+ $refund_status = 1;
+ $this->model_extension_payment_eway->updateRefundStatus($eway_order['eway_order_id'], $refund_status);
+ }
+
+ $json['data'] = array();
+ $json['data']['transactionid'] = $result->TransactionID;
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = number_format($refund_amount, 2, '.', '');
+ $json['data']['total_refunded_formatted'] = $this->currency->format($total_refunded, $eway_order['currency_code'], 1, true);
+ $json['data']['refund_status'] = $refund_status;
+ $json['data']['remaining'] = $total_captured - $total_refunded;
+ $json['message'] = $this->language->get('text_refund_success');
+ $json['error'] = false;
+ }
+ } else {
+ $json['error'] = true;
+ $json['message'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/eway');
+
+ $order_id = $this->request->post['order_id'];
+ $capture_amount = (double)$this->request->post['capture_amount'];
+
+ if ($order_id && $capture_amount > 0) {
+ $this->load->model('extension/payment/eway');
+ $eway_order = $this->model_extension_payment_eway->getOrder($order_id);
+ $result = $this->model_extension_payment_eway->capture($order_id, $capture_amount, $eway_order['currency_code']);
+
+ // Check if any error returns
+ if (isset($result->Errors) || $result === false) {
+ $json['error'] = true;
+ $reason = '';
+ if ($result === false) {
+ $reason = $this->language->get('text_unknown_failure');
+ } else {
+ $errors = explode(',', $result->Errors);
+ foreach ($errors as $error) {
+ $reason .= $this->language->get('text_card_message_' . $result->Errors);
+ }
+ }
+ $json['message'] = $this->language->get('text_capture_failed') . $reason;
+ } else {
+ $this->model_extension_payment_eway->addTransaction($eway_order['eway_order_id'], $result->TransactionID, 'payment', $capture_amount, $eway_order['currency_code']);
+
+ $total_captured = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']);
+ $total_refunded = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']);
+
+ $remaining = $eway_order['amount'] - $capture_amount;
+ if ($remaining <= 0) {
+ $remaining = 0;
+ }
+
+ $this->model_extension_payment_eway->updateCaptureStatus($eway_order['eway_order_id'], 1);
+ $this->model_extension_payment_eway->updateTransactionId($eway_order['eway_order_id'], $result->TransactionID);
+
+ $json['data'] = array();
+ $json['data']['transactionid'] = $result->TransactionID;
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = number_format($capture_amount, 2, '.', '');
+ $json['data']['total_captured_formatted'] = $this->currency->format($total_captured, $eway_order['currency_code'], 1, true);
+ $json['data']['capture_status'] = 1;
+ $json['data']['remaining'] = $remaining;
+ $json['message'] = $this->language->get('text_capture_success');
+ $json['error'] = false;
+ }
+ } else {
+ $json['error'] = true;
+ $json['message'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/eway')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+ if (!$this->request->post['payment_eway_username']) {
+ $this->error['username'] = $this->language->get('error_username');
+ }
+ if (!$this->request->post['payment_eway_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+ if (!isset($this->request->post['payment_eway_payment_type'])) {
+ $this->error['payment_type'] = $this->language->get('error_payment_type');
+ }
+
+ return !$this->error;
+ }
+
+}
diff --git a/public/admin/controller/extension/payment/firstdata.php b/public/admin/controller/extension/payment/firstdata.php
new file mode 100644
index 0000000..66f33f7
--- /dev/null
+++ b/public/admin/controller/extension/payment/firstdata.php
@@ -0,0 +1,352 @@
+<?php
+class ControllerExtensionPaymentFirstdata extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/firstdata');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_firstdata', $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));
+ }
+
+ $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify';
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['error_merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['error_merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['error_secret'])) {
+ $data['error_secret'] = $this->error['error_secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ if (isset($this->error['error_live_url'])) {
+ $data['error_live_url'] = $this->error['error_live_url'];
+ } else {
+ $data['error_live_url'] = '';
+ }
+
+ if (isset($this->error['error_demo_url'])) {
+ $data['error_demo_url'] = $this->error['error_demo_url'];
+ } else {
+ $data['error_demo_url'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/firstdata', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/firstdata', '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_firstdata_merchant_id'])) {
+ $data['payment_firstdata_merchant_id'] = $this->request->post['payment_firstdata_merchant_id'];
+ } else {
+ $data['payment_firstdata_merchant_id'] = $this->config->get('payment_firstdata_merchant_id');
+ }
+
+ if (isset($this->request->post['payment_firstdata_secret'])) {
+ $data['payment_firstdata_secret'] = $this->request->post['payment_firstdata_secret'];
+ } else {
+ $data['payment_firstdata_secret'] = $this->config->get('payment_firstdata_secret');
+ }
+
+ if (isset($this->request->post['payment_firstdata_live_demo'])) {
+ $data['payment_firstdata_live_demo'] = $this->request->post['payment_firstdata_live_demo'];
+ } else {
+ $data['payment_firstdata_live_demo'] = $this->config->get('payment_firstdata_live_demo');
+ }
+
+ if (isset($this->request->post['payment_firstdata_geo_zone_id'])) {
+ $data['payment_firstdata_geo_zone_id'] = $this->request->post['payment_firstdata_geo_zone_id'];
+ } else {
+ $data['payment_firstdata_geo_zone_id'] = $this->config->get('payment_firstdata_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_firstdata_total'])) {
+ $data['payment_firstdata_total'] = $this->request->post['payment_firstdata_total'];
+ } else {
+ $data['payment_firstdata_total'] = $this->config->get('payment_firstdata_total');
+ }
+
+ if (isset($this->request->post['payment_firstdata_sort_order'])) {
+ $data['payment_firstdata_sort_order'] = $this->request->post['payment_firstdata_sort_order'];
+ } else {
+ $data['payment_firstdata_sort_order'] = $this->config->get('payment_firstdata_sort_order');
+ }
+
+ if (isset($this->request->post['payment_firstdata_status'])) {
+ $data['payment_firstdata_status'] = $this->request->post['payment_firstdata_status'];
+ } else {
+ $data['payment_firstdata_status'] = $this->config->get('payment_firstdata_status');
+ }
+
+ if (isset($this->request->post['payment_firstdata_debug'])) {
+ $data['payment_firstdata_debug'] = $this->request->post['payment_firstdata_debug'];
+ } else {
+ $data['payment_firstdata_debug'] = $this->config->get('payment_firstdata_debug');
+ }
+
+ if (isset($this->request->post['payment_firstdata_auto_settle'])) {
+ $data['payment_firstdata_auto_settle'] = $this->request->post['payment_firstdata_auto_settle'];
+ } elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('payment_firstdata_auto_settle') != '') {
+ $data['payment_firstdata_auto_settle'] = $this->config->get('payment_firstdata_auto_settle');
+ } else {
+ $data['payment_firstdata_auto_settle'] = 1;
+ }
+
+ if (isset($this->request->post['payment_firstdata_order_status_success_settled_id'])) {
+ $data['payment_firstdata_order_status_success_settled_id'] = $this->request->post['payment_firstdata_order_status_success_settled_id'];
+ } else {
+ $data['payment_firstdata_order_status_success_settled_id'] = $this->config->get('payment_firstdata_order_status_success_settled_id');
+ }
+
+ if (isset($this->request->post['payment_firstdata_order_status_success_unsettled_id'])) {
+ $data['payment_firstdata_order_status_success_unsettled_id'] = $this->request->post['payment_firstdata_order_status_success_unsettled_id'];
+ } else {
+ $data['payment_firstdata_order_status_success_unsettled_id'] = $this->config->get('payment_firstdata_order_status_success_unsettled_id');
+ }
+
+ if (isset($this->request->post['payment_firstdata_order_status_decline_id'])) {
+ $data['payment_firstdata_order_status_decline_id'] = $this->request->post['payment_firstdata_order_status_decline_id'];
+ } else {
+ $data['payment_firstdata_order_status_decline_id'] = $this->config->get('payment_firstdata_order_status_decline_id');
+ }
+
+ if (isset($this->request->post['payment_firstdata_order_status_void_id'])) {
+ $data['payment_firstdata_order_status_void_id'] = $this->request->post['payment_firstdata_order_status_void_id'];
+ } else {
+ $data['payment_firstdata_order_status_void_id'] = $this->config->get('payment_firstdata_order_status_void_id');
+ }
+
+ if (isset($this->request->post['payment_firstdata_live_url'])) {
+ $data['payment_firstdata_live_url'] = $this->request->post['payment_firstdata_live_url'];
+ } else {
+ $data['payment_firstdata_live_url'] = $this->config->get('payment_firstdata_live_url');
+ }
+
+ if (empty($data['payment_firstdata_live_url'])) {
+ $data['payment_firstdata_live_url'] = 'https://ipg-online.com/connect/gateway/processing';
+ }
+
+ if (isset($this->request->post['payment_firstdata_demo_url'])) {
+ $data['payment_firstdata_demo_url'] = $this->request->post['payment_firstdata_demo_url'];
+ } else {
+ $data['payment_firstdata_demo_url'] = $this->config->get('payment_firstdata_demo_url');
+ }
+
+ if (isset($this->request->post['payment_firstdata_card_storage'])) {
+ $data['payment_firstdata_card_storage'] = $this->request->post['payment_firstdata_card_storage'];
+ } else {
+ $data['payment_firstdata_card_storage'] = $this->config->get('payment_firstdata_card_storage');
+ }
+
+ if (empty($data['payment_firstdata_demo_url'])) {
+ $data['payment_firstdata_demo_url'] = 'https://test.ipg-online.com/connect/gateway/processing';
+ }
+
+ $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/firstdata', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/firstdata');
+ $this->model_extension_payment_firstdata->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/firstdata');
+ $this->model_extension_payment_firstdata->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_firstdata_status')) {
+ $this->load->model('extension/payment/firstdata');
+
+ $firstdata_order = $this->model_extension_payment_firstdata->getOrder($this->request->get['order_id']);
+
+ if (!empty($firstdata_order)) {
+ $this->load->language('extension/payment/firstdata');
+
+ $firstdata_order['total_captured'] = $this->model_extension_payment_firstdata->getTotalCaptured($firstdata_order['firstdata_order_id']);
+ $firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true);
+ $firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true);
+
+ $data['firstdata_order'] = $firstdata_order;
+ $data['merchant_id'] = $this->config->get('payment_firstdata_merchant_id');
+ $data['currency'] = $this->model_extension_payment_firstdata->mapCurrency($firstdata_order['currency_code']);
+ $data['amount'] = number_format($firstdata_order['total'], 2);
+
+ $data['request_timestamp'] = date("Y:m:d-H:i:s");
+
+ $data['hash'] = sha1(bin2hex($data['merchant_id'] . $data['request_timestamp'] . $data['amount'] . $data['currency'] . $this->config->get('payment_firstdata_secret')));
+
+ $data['void_url'] = $this->url->link('extension/payment/firstdata/void', 'user_token=' . $this->session->data['user_token'], true);
+ $data['capture_url'] = $this->url->link('extension/payment/firstdata/capture', 'user_token=' . $this->session->data['user_token'], true);
+ $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify';
+
+ if ($this->config->get('payment_firstdata_live_demo') == 1) {
+ $data['action_url'] = $this->config->get('payment_firstdata_live_url');
+ } else {
+ $data['action_url'] = $this->config->get('payment_firstdata_demo_url');
+ }
+
+ if (isset($this->session->data['void_success'])) {
+ $data['void_success'] = $this->session->data['void_success'];
+
+ unset($this->session->data['void_success']);
+ } else {
+ $data['void_success'] = '';
+ }
+
+ if (isset($this->session->data['void_error'])) {
+ $data['void_error'] = $this->session->data['void_error'];
+
+ unset($this->session->data['void_error']);
+ } else {
+ $data['void_error'] = '';
+ }
+
+ if (isset($this->session->data['capture_success'])) {
+ $data['capture_success'] = $this->session->data['capture_success'];
+
+ unset($this->session->data['capture_success']);
+ } else {
+ $data['capture_success'] = '';
+ }
+
+ if (isset($this->session->data['capture_error'])) {
+ $data['capture_error'] = $this->session->data['capture_error'];
+
+ unset($this->session->data['capture_error']);
+ } else {
+ $data['capture_error'] = '';
+ }
+
+ $data['text_payment_info'] = $this->language->get('text_payment_info');
+ $data['text_order_ref'] = $this->language->get('text_order_ref');
+ $data['text_order_total'] = $this->language->get('text_order_total');
+ $data['text_total_captured'] = $this->language->get('text_total_captured');
+ $data['text_capture_status'] = $this->language->get('text_capture_status');
+ $data['text_void_status'] = $this->language->get('text_void_status');
+ $data['text_transactions'] = $this->language->get('text_transactions');
+ $data['text_yes'] = $this->language->get('text_yes');
+ $data['text_no'] = $this->language->get('text_no');
+ $data['text_column_amount'] = $this->language->get('text_column_amount');
+ $data['text_column_type'] = $this->language->get('text_column_type');
+ $data['text_column_date_added'] = $this->language->get('text_column_date_added');
+ $data['button_capture'] = $this->language->get('button_capture');
+ $data['button_void'] = $this->language->get('button_void');
+ $data['text_confirm_void'] = $this->language->get('text_confirm_void');
+ $data['text_confirm_capture'] = $this->language->get('text_confirm_capture');
+
+ $data['order_id'] = $this->request->get['order_id'];
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/firstdata_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/firstdata');
+
+ if ($this->request->post['status'] == 'FAILED') {
+ if (isset($this->request->post['fail_reason'])) {
+ $this->session->data['void_error'] = $this->request->post['fail_reason'];
+ } else {
+ $this->session->data['void_error'] = $this->language->get('error_void_error');
+ }
+ }
+
+ if ($this->request->post['status'] == 'DECLINED') {
+ $this->session->data['void_success'] = $this->language->get('success_void');
+ }
+
+ $this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/firstdata');
+
+ if ($this->request->post['status'] == 'FAILED') {
+ if (isset($this->request->post['fail_reason'])) {
+ $this->session->data['capture_error'] = $this->request->post['fail_reason'];
+ } else {
+ $this->session->data['capture_error'] = $this->language->get('error_capture_error');
+ }
+ }
+
+ if ($this->request->post['status'] == 'APPROVED') {
+ $this->session->data['capture_success'] = $this->language->get('success_capture');
+ }
+
+ $this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/firstdata')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_firstdata_merchant_id']) {
+ $this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['payment_firstdata_secret']) {
+ $this->error['error_secret'] = $this->language->get('error_secret');
+ }
+
+ if (!$this->request->post['payment_firstdata_live_url']) {
+ $this->error['error_live_url'] = $this->language->get('error_live_url');
+ }
+
+ if (!$this->request->post['payment_firstdata_demo_url']) {
+ $this->error['error_demo_url'] = $this->language->get('error_demo_url');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/firstdata_remote.php b/public/admin/controller/extension/payment/firstdata_remote.php
new file mode 100644
index 0000000..1380a1b
--- /dev/null
+++ b/public/admin/controller/extension/payment/firstdata_remote.php
@@ -0,0 +1,482 @@
+<?php
+class ControllerExtensionPaymentFirstdataRemote extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/firstdata_remote');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_firstdata_remote', $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));
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['error_merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['error_merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['error_user_id'])) {
+ $data['error_user_id'] = $this->error['error_user_id'];
+ } else {
+ $data['error_user_id'] = '';
+ }
+
+ if (isset($this->error['error_password'])) {
+ $data['error_password'] = $this->error['error_password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ if (isset($this->error['error_certificate'])) {
+ $data['error_certificate'] = $this->error['error_certificate'];
+ } else {
+ $data['error_certificate'] = '';
+ }
+
+ if (isset($this->error['error_key'])) {
+ $data['error_key'] = $this->error['error_key'];
+ } else {
+ $data['error_key'] = '';
+ }
+
+ if (isset($this->error['error_key_pw'])) {
+ $data['error_key_pw'] = $this->error['error_key_pw'];
+ } else {
+ $data['error_key_pw'] = '';
+ }
+
+ if (isset($this->error['error_ca'])) {
+ $data['error_ca'] = $this->error['error_ca'];
+ } else {
+ $data['error_ca'] = '';
+ }
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_extension'),
+ 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/firstdata_remote', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/firstdata_remote', '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['firstdata_remote_merchant_id'])) {
+ $data['firstdata_remote_merchant_id'] = $this->request->post['firstdata_remote_merchant_id'];
+ } else {
+ $data['firstdata_remote_merchant_id'] = $this->config->get('firstdata_remote_merchant_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_user_id'])) {
+ $data['firstdata_remote_user_id'] = $this->request->post['firstdata_remote_user_id'];
+ } else {
+ $data['firstdata_remote_user_id'] = $this->config->get('firstdata_remote_user_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_password'])) {
+ $data['firstdata_remote_password'] = $this->request->post['firstdata_remote_password'];
+ } else {
+ $data['firstdata_remote_password'] = $this->config->get('firstdata_remote_password');
+ }
+
+ if (isset($this->request->post['firstdata_remote_certificate'])) {
+ $data['firstdata_remote_certificate'] = $this->request->post['firstdata_remote_certificate'];
+ } else {
+ $data['firstdata_remote_certificate'] = $this->config->get('firstdata_remote_certificate');
+ }
+
+ if (isset($this->request->post['firstdata_remote_key'])) {
+ $data['firstdata_remote_key'] = $this->request->post['firstdata_remote_key'];
+ } else {
+ $data['firstdata_remote_key'] = $this->config->get('firstdata_remote_key');
+ }
+
+ if (isset($this->request->post['firstdata_remote_key_pw'])) {
+ $data['firstdata_remote_key_pw'] = $this->request->post['firstdata_remote_key_pw'];
+ } else {
+ $data['firstdata_remote_key_pw'] = $this->config->get('firstdata_remote_key_pw');
+ }
+
+ if (isset($this->request->post['firstdata_remote_ca'])) {
+ $data['firstdata_remote_ca'] = $this->request->post['firstdata_remote_ca'];
+ } else {
+ $data['firstdata_remote_ca'] = $this->config->get('firstdata_remote_ca');
+ }
+
+ if (isset($this->request->post['firstdata_remote_geo_zone_id'])) {
+ $data['firstdata_remote_geo_zone_id'] = $this->request->post['firstdata_remote_geo_zone_id'];
+ } else {
+ $data['firstdata_remote_geo_zone_id'] = $this->config->get('firstdata_remote_geo_zone_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_total'])) {
+ $data['firstdata_remote_total'] = $this->request->post['firstdata_remote_total'];
+ } else {
+ $data['firstdata_remote_total'] = $this->config->get('firstdata_remote_total');
+ }
+
+ if (isset($this->request->post['firstdata_remote_sort_order'])) {
+ $data['firstdata_remote_sort_order'] = $this->request->post['firstdata_remote_sort_order'];
+ } else {
+ $data['firstdata_remote_sort_order'] = $this->config->get('firstdata_remote_sort_order');
+ }
+
+ if (isset($this->request->post['firstdata_remote_status'])) {
+ $data['firstdata_remote_status'] = $this->request->post['firstdata_remote_status'];
+ } else {
+ $data['firstdata_remote_status'] = $this->config->get('firstdata_remote_status');
+ }
+
+ if (isset($this->request->post['firstdata_remote_debug'])) {
+ $data['firstdata_remote_debug'] = $this->request->post['firstdata_remote_debug'];
+ } else {
+ $data['firstdata_remote_debug'] = $this->config->get('firstdata_remote_debug');
+ }
+ if (isset($this->request->post['firstdata_remote_auto_settle'])) {
+ $data['firstdata_remote_auto_settle'] = $this->request->post['firstdata_remote_auto_settle'];
+ } elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('firstdata_remote_auto_settle') != '') {
+ $data['firstdata_remote_auto_settle'] = $this->config->get('firstdata_remote_auto_settle');
+ } else {
+ $data['firstdata_remote_auto_settle'] = 1;
+ }
+
+ if (isset($this->request->post['firstdata_remote_3d'])) {
+ $data['firstdata_remote_3d'] = $this->request->post['firstdata_remote_3d'];
+ } else {
+ $data['firstdata_remote_3d'] = $this->config->get('firstdata_remote_3d');
+ }
+
+ if (isset($this->request->post['firstdata_remote_liability'])) {
+ $data['firstdata_remote_liability'] = $this->request->post['firstdata_remote_liability'];
+ } else {
+ $data['firstdata_remote_liability'] = $this->config->get('firstdata_remote_liability');
+ }
+
+ if (isset($this->request->post['firstdata_remote_order_status_success_settled_id'])) {
+ $data['firstdata_remote_order_status_success_settled_id'] = $this->request->post['firstdata_remote_order_status_success_settled_id'];
+ } else {
+ $data['firstdata_remote_order_status_success_settled_id'] = $this->config->get('firstdata_remote_order_status_success_settled_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_order_status_success_unsettled_id'])) {
+ $data['firstdata_remote_order_status_success_unsettled_id'] = $this->request->post['firstdata_remote_order_status_success_unsettled_id'];
+ } else {
+ $data['firstdata_remote_order_status_success_unsettled_id'] = $this->config->get('firstdata_remote_order_status_success_unsettled_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_order_status_decline_id'])) {
+ $data['firstdata_remote_order_status_decline_id'] = $this->request->post['firstdata_remote_order_status_decline_id'];
+ } else {
+ $data['firstdata_remote_order_status_decline_id'] = $this->config->get('firstdata_remote_order_status_decline_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_order_status_void_id'])) {
+ $data['firstdata_remote_order_status_void_id'] = $this->request->post['firstdata_remote_order_status_void_id'];
+ } else {
+ $data['firstdata_remote_order_status_void_id'] = $this->config->get('firstdata_remote_order_status_void_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_order_status_refunded_id'])) {
+ $data['firstdata_remote_order_status_refunded_id'] = $this->request->post['firstdata_remote_order_status_refunded_id'];
+ } else {
+ $data['firstdata_remote_order_status_refunded_id'] = $this->config->get('firstdata_remote_order_status_refunded_id');
+ }
+
+ if (isset($this->request->post['firstdata_remote_card_storage'])) {
+ $data['firstdata_remote_card_storage'] = $this->request->post['firstdata_remote_card_storage'];
+ } else {
+ $data['firstdata_remote_card_storage'] = $this->config->get('firstdata_remote_card_storage');
+ }
+
+ $data['cards'] = array();
+
+ $data['cards'][] = array(
+ 'text' => $this->language->get('text_mastercard'),
+ 'value' => 'mastercard'
+ );
+
+ $data['cards'][] = array(
+ 'text' => $this->language->get('text_visa'),
+ 'value' => 'visa'
+ );
+
+ $data['cards'][] = array(
+ 'text' => $this->language->get('text_diners'),
+ 'value' => 'diners'
+ );
+
+ $data['cards'][] = array(
+ 'text' => $this->language->get('text_amex'),
+ 'value' => 'amex'
+ );
+
+ $data['cards'][] = array(
+ 'text' => $this->language->get('text_maestro'),
+ 'value' => 'maestro'
+ );
+
+ if (isset($this->request->post['firstdata_remote_cards_accepted'])) {
+ $data['firstdata_remote_cards_accepted'] = $this->request->post['firstdata_remote_cards_accepted'];
+ } elseif ($this->config->get('firstdata_remote_cards_accepted')) {
+ $data['firstdata_remote_cards_accepted'] = $this->config->get('firstdata_remote_cards_accepted');
+ } else {
+ $data['firstdata_remote_cards_accepted'] = array();
+ }
+
+ $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/firstdata_remote', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/firstdata_remote');
+ $this->model_extension_payment_firstdata_remote->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/firstdata_remote');
+ $this->model_extension_payment_firstdata_remote->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('firstdata_remote_status')) {
+ $this->load->model('extension/payment/firstdata_remote');
+
+ $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->get['order_id']);
+
+ if (!empty($firstdata_order)) {
+ $this->load->language('extension/payment/firstdata_remote');
+
+ $firstdata_order['total_captured'] = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']);
+
+ $firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true);
+ $firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true);
+
+ $data['firstdata_order'] = $firstdata_order;
+
+ $data['text_payment_info'] = $this->language->get('text_payment_info');
+ $data['text_order_ref'] = $this->language->get('text_order_ref');
+ $data['text_order_total'] = $this->language->get('text_order_total');
+ $data['text_total_captured'] = $this->language->get('text_total_captured');
+ $data['text_capture_status'] = $this->language->get('text_capture_status');
+ $data['text_void_status'] = $this->language->get('text_void_status');
+ $data['text_refund_status'] = $this->language->get('text_refund_status');
+ $data['text_transactions'] = $this->language->get('text_transactions');
+ $data['text_yes'] = $this->language->get('text_yes');
+ $data['text_no'] = $this->language->get('text_no');
+ $data['text_column_amount'] = $this->language->get('text_column_amount');
+ $data['text_column_type'] = $this->language->get('text_column_type');
+ $data['text_column_date_added'] = $this->language->get('text_column_date_added');
+ $data['text_confirm_void'] = $this->language->get('text_confirm_void');
+ $data['text_confirm_capture'] = $this->language->get('text_confirm_capture');
+ $data['text_confirm_refund'] = $this->language->get('text_confirm_refund');
+
+ $data['button_capture'] = $this->language->get('button_capture');
+ $data['button_refund'] = $this->language->get('button_refund');
+ $data['button_void'] = $this->language->get('button_void');
+
+ $data['order_id'] = $this->request->get['order_id'];
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/firstdata_remote_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/firstdata_remote');
+
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/firstdata_remote');
+
+ $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_firstdata_remote->void($firstdata_order['order_ref'], $firstdata_order['tdate']);
+
+ $this->model_extension_payment_firstdata_remote->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if (strtoupper($void_response['transaction_result']) == 'APPROVED') {
+ $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'void', 0.00);
+
+ $this->model_extension_payment_firstdata_remote->updateVoidStatus($firstdata_order['firstdata_remote_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+ $json['data'] = array();
+ $json['data']['column_date_added'] = date('Y-m-d H:i:s');
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response['error']) && !empty($void_response['error']) ? (string)$void_response['error'] : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/firstdata');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/firstdata_remote');
+
+ $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']);
+
+ $capture_response = $this->model_extension_payment_firstdata_remote->capture($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']);
+
+ $this->model_extension_payment_firstdata_remote->logger('Settle result:\r\n' . print_r($capture_response, 1));
+
+ if (strtoupper($capture_response['transaction_result']) == 'APPROVED') {
+ $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'payment', $firstdata_order['total']);
+ $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']);
+
+ $this->model_extension_payment_firstdata_remote->updateCaptureStatus($firstdata_order['firstdata_remote_order_id'], 1);
+ $capture_status = 1;
+ $json['msg'] = $this->language->get('text_capture_ok_order');
+ $json['data'] = array();
+ $json['data']['column_date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = (float)$firstdata_order['total'];
+ $json['data']['capture_status'] = $capture_status;
+ $json['data']['total'] = (float)$total_captured;
+ $json['data']['total_formatted'] = $this->currency->format($total_captured, $firstdata_order['currency_code'], 1, true);
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($capture_response['error']) && !empty($capture_response['error']) ? (string)$capture_response['error'] : 'Unable to capture';
+
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/firstdata_remote');
+
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/firstdata_remote');
+
+ $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']);
+
+ $refund_response = $this->model_extension_payment_firstdata_remote->refund($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']);
+
+ $this->model_extension_payment_firstdata_remote->logger('Refund result:\r\n' . print_r($refund_response, 1));
+
+ if (strtoupper($refund_response['transaction_result']) == 'APPROVED') {
+ $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'refund', $firstdata_order['total'] * -1);
+
+ $total_refunded = $this->model_extension_payment_firstdata_remote->getTotalRefunded($firstdata_order['firstdata_remote_order_id']);
+ $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']);
+
+ if ($total_captured <= 0 && $firstdata_order['capture_status'] == 1) {
+ $this->model_extension_payment_firstdata_remote->updateRefundStatus($firstdata_order['firstdata_remote_order_id'], 1);
+ $refund_status = 1;
+ $json['msg'] = $this->language->get('text_refund_ok_order');
+ } else {
+ $refund_status = 0;
+ $json['msg'] = $this->language->get('text_refund_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['column_date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $firstdata_order['total'] * -1;
+ $json['data']['total_captured'] = (float)$total_captured;
+ $json['data']['total_refunded'] = (float)$total_refunded;
+ $json['data']['refund_status'] = $refund_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($refund_response['error']) && !empty($refund_response['error']) ? (string)$refund_response['error'] : 'Unable to refund';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/firstdata_remote')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['firstdata_remote_merchant_id']) {
+ $this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['firstdata_remote_user_id']) {
+ $this->error['error_user_id'] = $this->language->get('error_user_id');
+ }
+
+ if (!$this->request->post['firstdata_remote_password']) {
+ $this->error['error_password'] = $this->language->get('error_password');
+ }
+
+ if (!$this->request->post['firstdata_remote_certificate']) {
+ $this->error['error_certificate'] = $this->language->get('error_certificate');
+ }
+
+ if (!$this->request->post['firstdata_remote_key']) {
+ $this->error['error_key'] = $this->language->get('error_key');
+ }
+
+ if (!$this->request->post['firstdata_remote_key_pw']) {
+ $this->error['error_key_pw'] = $this->language->get('error_key_pw');
+ }
+
+ if (!$this->request->post['firstdata_remote_ca']) {
+ $this->error['error_ca'] = $this->language->get('error_ca');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/free_checkout.php b/public/admin/controller/extension/payment/free_checkout.php
new file mode 100644
index 0000000..90578c5
--- /dev/null
+++ b/public/admin/controller/extension/payment/free_checkout.php
@@ -0,0 +1,83 @@
+<?php
+class ControllerExtensionPaymentFreeCheckout extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/free_checkout');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_free_checkout', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/free_checkout', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/free_checkout', '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['free_checkout_order_status_id'])) {
+ $data['free_checkout_order_status_id'] = $this->request->post['free_checkout_order_status_id'];
+ } else {
+ $data['free_checkout_order_status_id'] = $this->config->get('free_checkout_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_free_checkout_status'])) {
+ $data['payment_free_checkout_status'] = $this->request->post['payment_free_checkout_status'];
+ } else {
+ $data['payment_free_checkout_status'] = $this->config->get('payment_free_checkout_status');
+ }
+
+ if (isset($this->request->post['payment_free_checkout_sort_order'])) {
+ $data['payment_free_checkout_sort_order'] = $this->request->post['payment_free_checkout_sort_order'];
+ } else {
+ $data['payment_free_checkout_sort_order'] = $this->config->get('payment_free_checkout_sort_order');
+ }
+
+ $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/free_checkout', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/free_checkout')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/g2apay.php b/public/admin/controller/extension/payment/g2apay.php
new file mode 100644
index 0000000..19014f5
--- /dev/null
+++ b/public/admin/controller/extension/payment/g2apay.php
@@ -0,0 +1,302 @@
+<?php
+
+class ControllerExtensionPaymentG2APay extends Controller {
+
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/g2apay');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_g2apay', $this->request->post);
+
+ $this->session->data['complete'] = $this->language->get('text_complete');
+
+ $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['username'])) {
+ $data['error_username'] = $this->error['username'];
+ } else {
+ $data['error_username'] = '';
+ }
+
+ if (isset($this->error['secret'])) {
+ $data['error_secret'] = $this->error['secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ if (isset($this->error['api_hash'])) {
+ $data['error_api_hash'] = $this->error['api_hash'];
+ } else {
+ $data['error_api_hash'] = '';
+ }
+
+ if (isset($this->request->post['payment_g2apay_order_status_id'])) {
+ $data['payment_g2apay_order_status_id'] = $this->request->post['payment_g2apay_order_status_id'];
+ } else {
+ $data['payment_g2apay_order_status_id'] = $this->config->get('payment_g2apay_order_status_id');
+ }
+
+ if (isset($this->request->post['payment_g2apay_complete_status_id'])) {
+ $data['payment_g2apay_complete_status_id'] = $this->request->post['payment_g2apay_complete_status_id'];
+ } else {
+ $data['payment_g2apay_complete_status_id'] = $this->config->get('payment_g2apay_complete_status_id');
+ }
+
+ if (isset($this->request->post['payment_g2apay_rejected_status_id'])) {
+ $data['payment_g2apay_rejected_status_id'] = $this->request->post['payment_g2apay_rejected_status_id'];
+ } else {
+ $data['payment_g2apay_rejected_status_id'] = $this->config->get('payment_g2apay_rejected_status_id');
+ }
+
+ if (isset($this->request->post['payment_g2apay_cancelled_status_id'])) {
+ $data['payment_g2apay_cancelled_status_id'] = $this->request->post['payment_g2apay_cancelled_status_id'];
+ } else {
+ $data['payment_g2apay_cancelled_status_id'] = $this->config->get('payment_g2apay_cancelled_status_id');
+ }
+
+ if (isset($this->request->post['payment_g2apay_pending_status_id'])) {
+ $data['payment_g2apay_pending_status_id'] = $this->request->post['payment_g2apay_pending_status_id'];
+ } else {
+ $data['payment_g2apay_pending_status_id'] = $this->config->get('payment_g2apay_pending_status_id');
+ }
+
+ if (isset($this->request->post['payment_g2apay_refunded_status_id'])) {
+ $data['payment_g2apay_refunded_status_id'] = $this->request->post['payment_g2apay_refunded_status_id'];
+ } else {
+ $data['payment_g2apay_refunded_status_id'] = $this->config->get('payment_g2apay_refunded_status_id');
+ }
+
+ if (isset($this->request->post['payment_g2apay_partially_refunded_status_id'])) {
+ $data['payment_g2apay_partially_refunded_status_id'] = $this->request->post['payment_g2apay_partially_refunded_status_id'];
+ } else {
+ $data['payment_g2apay_partially_refunded_status_id'] = $this->config->get('payment_g2apay_partially_refunded_status_id');
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/g2apay', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $this->load->model('localisation/order_status');
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $data['action'] = $this->url->link('extension/payment/g2apay', '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_g2apay_username'])) {
+ $data['payment_g2apay_username'] = $this->request->post['payment_g2apay_username'];
+ } else {
+ $data['payment_g2apay_username'] = $this->config->get('payment_g2apay_username');
+ }
+
+ if (isset($this->request->post['payment_g2apay_secret'])) {
+ $data['payment_g2apay_secret'] = $this->request->post['payment_g2apay_secret'];
+ } else {
+ $data['payment_g2apay_secret'] = $this->config->get('payment_g2apay_secret');
+ }
+
+ if (isset($this->request->post['payment_g2apay_api_hash'])) {
+ $data['payment_g2apay_api_hash'] = $this->request->post['payment_g2apay_api_hash'];
+ } else {
+ $data['payment_g2apay_api_hash'] = $this->config->get('payment_g2apay_api_hash');
+ }
+
+ if (isset($this->request->post['payment_g2apay_environment'])) {
+ $data['payment_g2apay_environment'] = $this->request->post['payment_g2apay_environment'];
+ } else {
+ $data['payment_g2apay_environment'] = $this->config->get('payment_g2apay_environment');
+ }
+
+ if (isset($this->request->post['payment_g2apay_total'])) {
+ $data['payment_g2apay_total'] = $this->request->post['payment_g2apay_total'];
+ } else {
+ $data['payment_g2apay_total'] = $this->config->get('payment_g2apay_total');
+ }
+
+ if (isset($this->request->post['payment_g2apay_secret_token'])) {
+ $data['payment_g2apay_secret_token'] = $this->request->post['payment_g2apay_secret_token'];
+ } elseif ($this->config->get('payment_g2apay_secret_token')) {
+ $data['payment_g2apay_secret_token'] = $this->config->get('payment_g2apay_secret_token');
+ } else {
+ $data['payment_g2apay_secret_token'] = sha1(uniqid(mt_rand(), 1));
+ }
+
+ $data['g2apay_ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/g2apay/ipn&token=' . $data['payment_g2apay_secret_token'];
+
+ if (isset($this->request->post['payment_g2apay_ipn_uri'])) {
+ $data['payment_g2apay_ipn_uri'] = $this->request->post['payment_g2apay_ipn_uri'];
+ } else {
+ $data['payment_g2apay_ipn_uri'] = $this->config->get('payment_g2apay_ipn_uri');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_g2apay_geo_zone_id'])) {
+ $data['payment_g2apay_geo_zone_id'] = $this->request->post['payment_g2apay_geo_zone_id'];
+ } else {
+ $data['payment_g2apay_geo_zone_id'] = $this->config->get('payment_g2apay_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_g2apay_status'])) {
+ $data['payment_g2apay_status'] = $this->request->post['payment_g2apay_status'];
+ } else {
+ $data['payment_g2apay_status'] = $this->config->get('payment_g2apay_status');
+ }
+
+ if (isset($this->request->post['payment_g2apay_debug'])) {
+ $data['payment_g2apay_debug'] = $this->request->post['payment_g2apay_debug'];
+ } else {
+ $data['payment_g2apay_debug'] = $this->config->get('payment_g2apay_debug');
+ }
+
+ if (isset($this->request->post['payment_g2apay_sort_order'])) {
+ $data['payment_g2apay_sort_order'] = $this->request->post['payment_g2apay_sort_order'];
+ } else {
+ $data['payment_g2apay_sort_order'] = $this->config->get('payment_g2apay_sort_order');
+ }
+
+ $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/g2apay', $data));
+ }
+
+ public function order() {
+
+ if ($this->config->get('payment_g2apay_status')) {
+
+ $this->load->model('extension/payment/g2apay');
+
+ $g2apay_order = $this->model_extension_payment_g2apay->getOrder($this->request->get['order_id']);
+
+ if (!empty($g2apay_order)) {
+ $this->load->language('extension/payment/g2apay');
+
+ $g2apay_order['total_released'] = $this->model_extension_payment_g2apay->getTotalReleased($g2apay_order['g2apay_order_id']);
+
+ $g2apay_order['total_formatted'] = $this->currency->format($g2apay_order['total'], $g2apay_order['currency_code'], false);
+ $g2apay_order['total_released_formatted'] = $this->currency->format($g2apay_order['total_released'], $g2apay_order['currency_code'], false);
+
+ $data['g2apay_order'] = $g2apay_order;
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/g2apay_order', $data);
+ }
+ }
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/g2apay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/g2apay');
+
+ $g2apay_order = $this->model_extension_payment_g2apay->getOrder($this->request->post['order_id']);
+
+ $refund_response = $this->model_extension_payment_g2apay->refund($g2apay_order, $this->request->post['amount']);
+
+ $this->model_extension_payment_g2apay->logger($refund_response);
+
+ if ($refund_response == 'ok') {
+ $this->model_extension_payment_g2apay->addTransaction($g2apay_order['g2apay_order_id'], 'refund', $this->request->post['amount'] * -1);
+
+ $total_refunded = $this->model_extension_payment_g2apay->getTotalRefunded($g2apay_order['g2apay_order_id']);
+ $total_released = $this->model_extension_payment_g2apay->getTotalReleased($g2apay_order['g2apay_order_id']);
+
+ if ($total_released <= 0 && $g2apay_order['release_status'] == 1) {
+ $this->model_extension_payment_g2apay->updateRefundStatus($g2apay_order['g2apay_order_id'], 1);
+ $refund_status = 1;
+ $json['msg'] = $this->language->get('text_refund_ok_order');
+ } else {
+ $refund_status = 0;
+ $json['msg'] = $this->language->get('text_refund_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->currency->format(($this->request->post['amount'] * -1), $g2apay_order['currency_code'], false);
+ $json['data']['total_released'] = (float)$total_released;
+ $json['data']['total_refunded'] = (float)$total_refunded;
+ $json['data']['refund_status'] = $refund_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Unable to refund: ' . $refund_response;
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/g2apay');
+ $this->model_extension_payment_g2apay->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/g2apay');
+ $this->model_extension_payment_g2apay->uninstall();
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/g2apay')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_g2apay_username']) {
+ $this->error['username'] = $this->language->get('error_username');
+ }
+
+ if (!$this->request->post['payment_g2apay_secret']) {
+ $this->error['secret'] = $this->language->get('error_secret');
+ }
+
+ if (!$this->request->post['payment_g2apay_api_hash']) {
+ $this->error['api_hash'] = $this->language->get('error_api_hash');
+ }
+
+ return !$this->error;
+ }
+
+}
diff --git a/public/admin/controller/extension/payment/globalpay.php b/public/admin/controller/extension/payment/globalpay.php
new file mode 100644
index 0000000..4e833d6
--- /dev/null
+++ b/public/admin/controller/extension/payment/globalpay.php
@@ -0,0 +1,408 @@
+<?php
+class ControllerExtensionPaymentGlobalpay extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/globalpay');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_globalpay', $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));
+ }
+
+ $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/globalpay/notify';
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['error_merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['error_merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['error_secret'])) {
+ $data['error_secret'] = $this->error['error_secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ if (isset($this->error['error_live_url'])) {
+ $data['error_live_url'] = $this->error['error_live_url'];
+ } else {
+ $data['error_live_url'] = '';
+ }
+
+ if (isset($this->error['error_demo_url'])) {
+ $data['error_demo_url'] = $this->error['error_demo_url'];
+ } else {
+ $data['error_demo_url'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/globalpay', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/globalpay', '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_globalpay_merchant_id'])) {
+ $data['payment_globalpay_merchant_id'] = $this->request->post['payment_globalpay_merchant_id'];
+ } else {
+ $data['payment_globalpay_merchant_id'] = $this->config->get('payment_globalpay_merchant_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_secret'])) {
+ $data['payment_globalpay_secret'] = $this->request->post['payment_globalpay_secret'];
+ } else {
+ $data['payment_globalpay_secret'] = $this->config->get('payment_globalpay_secret');
+ }
+
+ if (isset($this->request->post['payment_globalpay_rebate_password'])) {
+ $data['payment_globalpay_rebate_password'] = $this->request->post['payment_globalpay_rebate_password'];
+ } else {
+ $data['payment_globalpay_rebate_password'] = $this->config->get('payment_globalpay_rebate_password');
+ }
+
+ if (isset($this->request->post['payment_globalpay_live_demo'])) {
+ $data['payment_globalpay_live_demo'] = $this->request->post['payment_globalpay_live_demo'];
+ } else {
+ $data['payment_globalpay_live_demo'] = $this->config->get('payment_globalpay_live_demo');
+ }
+
+ if (isset($this->request->post['payment_globalpay_geo_zone_id'])) {
+ $data['payment_globalpay_geo_zone_id'] = $this->request->post['payment_globalpay_geo_zone_id'];
+ } else {
+ $data['payment_globalpay_geo_zone_id'] = $this->config->get('payment_globalpay_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_globalpay_total'])) {
+ $data['payment_globalpay_total'] = $this->request->post['payment_globalpay_total'];
+ } else {
+ $data['payment_globalpay_total'] = $this->config->get('payment_globalpay_total');
+ }
+
+ if (isset($this->request->post['payment_globalpay_sort_order'])) {
+ $data['payment_globalpay_sort_order'] = $this->request->post['payment_globalpay_sort_order'];
+ } else {
+ $data['payment_globalpay_sort_order'] = $this->config->get('payment_globalpay_sort_order');
+ }
+
+ if (isset($this->request->post['payment_globalpay_status'])) {
+ $data['payment_globalpay_status'] = $this->request->post['payment_globalpay_status'];
+ } else {
+ $data['payment_globalpay_status'] = $this->config->get('payment_globalpay_status');
+ }
+
+ if (isset($this->request->post['payment_globalpay_debug'])) {
+ $data['payment_globalpay_debug'] = $this->request->post['payment_globalpay_debug'];
+ } else {
+ $data['payment_globalpay_debug'] = $this->config->get('payment_globalpay_debug');
+ }
+
+ if (isset($this->request->post['payment_globalpay_account'])) {
+ $data['payment_globalpay_account'] = $this->request->post['payment_globalpay_account'];
+ } else {
+ $data['payment_globalpay_account'] = $this->config->get('payment_globalpay_account');
+ }
+
+ if (isset($this->request->post['payment_globalpay_auto_settle'])) {
+ $data['payment_globalpay_auto_settle'] = $this->request->post['payment_globalpay_auto_settle'];
+ } else {
+ $data['payment_globalpay_auto_settle'] = $this->config->get('payment_globalpay_auto_settle');
+ }
+
+ if (isset($this->request->post['payment_globalpay_card_select'])) {
+ $data['payment_globalpay_card_select'] = $this->request->post['payment_globalpay_card_select'];
+ } else {
+ $data['payment_globalpay_card_select'] = $this->config->get('payment_globalpay_card_select');
+ }
+
+ if (isset($this->request->post['payment_globalpay_tss_check'])) {
+ $data['payment_globalpay_tss_check'] = $this->request->post['payment_globalpay_tss_check'];
+ } else {
+ $data['payment_globalpay_tss_check'] = $this->config->get('payment_globalpay_tss_check');
+ }
+
+ if (isset($this->request->post['globalpay_order_status_success_settled_id'])) {
+ $data['globalpay_order_status_success_settled_id'] = $this->request->post['globalpay_order_status_success_settled_id'];
+ } else {
+ $data['globalpay_order_status_success_settled_id'] = $this->config->get('globalpay_order_status_success_settled_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_order_status_success_unsettled_id'])) {
+ $data['payment_globalpay_order_status_success_unsettled_id'] = $this->request->post['payment_globalpay_order_status_success_unsettled_id'];
+ } else {
+ $data['payment_globalpay_order_status_success_unsettled_id'] = $this->config->get('payment_globalpay_order_status_success_unsettled_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_order_status_decline_id'])) {
+ $data['payment_globalpay_order_status_decline_id'] = $this->request->post['payment_globalpay_order_status_decline_id'];
+ } else {
+ $data['payment_globalpay_order_status_decline_id'] = $this->config->get('payment_globalpay_order_status_decline_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_order_status_decline_pending_id'])) {
+ $data['payment_globalpay_order_status_decline_pending_id'] = $this->request->post['payment_globalpay_order_status_decline_pending_id'];
+ } else {
+ $data['payment_globalpay_order_status_decline_pending_id'] = $this->config->get('payment_globalpay_order_status_decline_pending_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_order_status_decline_stolen_id'])) {
+ $data['payment_globalpay_order_status_decline_stolen_id'] = $this->request->post['payment_globalpay_order_status_decline_stolen_id'];
+ } else {
+ $data['payment_globalpay_order_status_decline_stolen_id'] = $this->config->get('payment_globalpay_order_status_decline_stolen_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_order_status_decline_bank_id'])) {
+ $data['payment_globalpay_order_status_decline_bank_id'] = $this->request->post['payment_globalpay_order_status_decline_bank_id'];
+ } else {
+ $data['payment_globalpay_order_status_decline_bank_id'] = $this->config->get('payment_globalpay_order_status_decline_bank_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_globalpay_live_url'])) {
+ $data['payment_globalpay_live_url'] = $this->request->post['payment_globalpay_live_url'];
+ } else {
+ $data['payment_globalpay_live_url'] = $this->config->get('payment_globalpay_live_url');
+ }
+
+ if (empty($data['payment_globalpay_live_url'])) {
+ $data['payment_globalpay_live_url'] = 'https://hpp.globaliris.com/pay';
+ }
+
+ if (isset($this->request->post['payment_globalpay_demo_url'])) {
+ $data['payment_globalpay_demo_url'] = $this->request->post['payment_globalpay_demo_url'];
+ } else {
+ $data['payment_globalpay_demo_url'] = $this->config->get('payment_globalpay_demo_url');
+ }
+
+ if (empty($data['payment_globalpay_demo_url'])) {
+ $data['payment_globalpay_demo_url'] = 'https://hpp.sandbox.globaliris.com/pay';
+ }
+
+ $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/globalpay', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/globalpay');
+
+ $this->model_extension_payment_globalpay->install();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_globalpay_status')) {
+ $this->load->model('extension/payment/globalpay');
+
+ $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->get['order_id']);
+
+ if (!empty($globalpay_order)) {
+ $this->load->language('extension/payment/globalpay');
+
+ $globalpay_order['total_captured'] = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']);
+
+ $globalpay_order['total_formatted'] = $this->currency->format($globalpay_order['total'], $globalpay_order['currency_code'], 1, true);
+ $globalpay_order['total_captured_formatted'] = $this->currency->format($globalpay_order['total_captured'], $globalpay_order['currency_code'], 1, true);
+
+ $data['globalpay_order'] = $globalpay_order;
+
+ $data['auto_settle'] = $globalpay_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/globalpay_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/globalpay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/globalpay');
+
+ $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_globalpay->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_globalpay->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if (isset($void_response->result) && $void_response->result == '00') {
+ $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'void', 0.00);
+ $this->model_extension_payment_globalpay->updateVoidStatus($globalpay_order['globalpay_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/globalpay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/globalpay');
+
+ $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']);
+
+ $capture_response = $this->model_extension_payment_globalpay->capture($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_globalpay->logger('Settle result:\r\n' . print_r($capture_response, 1));
+
+ if (isset($capture_response->result) && $capture_response->result == '00') {
+ $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'payment', $this->request->post['amount']);
+
+ $total_captured = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']);
+
+ if ($total_captured >= $globalpay_order['total'] || $globalpay_order['settle_type'] == 0) {
+ $this->model_extension_payment_globalpay->updateCaptureStatus($globalpay_order['globalpay_order_id'], 1);
+ $capture_status = 1;
+ $json['msg'] = $this->language->get('text_capture_ok_order');
+ } else {
+ $capture_status = 0;
+ $json['msg'] = $this->language->get('text_capture_ok');
+ }
+
+ $this->model_extension_payment_globalpay->updateForRebate($globalpay_order['globalpay_order_id'], $capture_response->pasref, $capture_response->orderid);
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'];
+ $json['data']['capture_status'] = $capture_status;
+ $json['data']['total'] = (float)$total_captured;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/globalpay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/globalpay');
+
+ $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_globalpay->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_globalpay->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if (isset($rebate_response->result) && $rebate_response->result == '00') {
+ $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'rebate', $this->request->post['amount']*-1);
+
+ $total_rebated = $this->model_extension_payment_globalpay->getTotalRebated($globalpay_order['globalpay_order_id']);
+ $total_captured = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']);
+
+ if ($total_captured <= 0 && $globalpay_order['capture_status'] == 1) {
+ $this->model_extension_payment_globalpay->updateRebateStatus($globalpay_order['globalpay_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount']*-1;
+ $json['data']['total_captured'] = (float)$total_captured;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/globalpay')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_globalpay_merchant_id']) {
+ $this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['payment_globalpay_secret']) {
+ $this->error['error_secret'] = $this->language->get('error_secret');
+ }
+
+ if (!$this->request->post['payment_globalpay_live_url']) {
+ $this->error['error_live_url'] = $this->language->get('error_live_url');
+ }
+
+ if (!$this->request->post['payment_globalpay_demo_url']) {
+ $this->error['error_demo_url'] = $this->language->get('error_demo_url');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/globalpay_remote.php b/public/admin/controller/extension/payment/globalpay_remote.php
new file mode 100644
index 0000000..c4e69c3
--- /dev/null
+++ b/public/admin/controller/extension/payment/globalpay_remote.php
@@ -0,0 +1,372 @@
+<?php
+class ControllerExtensionPaymentGlobalpayRemote extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/globalpay_remote');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_globalpay_remote', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['error_merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['error_merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['error_secret'])) {
+ $data['error_secret'] = $this->error['error_secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/globalpay_remote', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/globalpay_remote', '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_globalpay_remote_merchant_id'])) {
+ $data['payment_globalpay_remote_merchant_id'] = $this->request->post['payment_globalpay_remote_merchant_id'];
+ } else {
+ $data['payment_globalpay_remote_merchant_id'] = $this->config->get('payment_globalpay_remote_merchant_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_secret'])) {
+ $data['payment_globalpay_remote_secret'] = $this->request->post['payment_globalpay_remote_secret'];
+ } else {
+ $data['payment_globalpay_remote_secret'] = $this->config->get('payment_globalpay_remote_secret');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_rebate_password'])) {
+ $data['payment_globalpay_remote_rebate_password'] = $this->request->post['payment_globalpay_remote_rebate_password'];
+ } else {
+ $data['payment_globalpay_remote_rebate_password'] = $this->config->get('payment_globalpay_remote_rebate_password');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_geo_zone_id'])) {
+ $data['payment_globalpay_remote_geo_zone_id'] = $this->request->post['payment_globalpay_remote_geo_zone_id'];
+ } else {
+ $data['payment_globalpay_remote_geo_zone_id'] = $this->config->get('payment_globalpay_remote_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_globalpay_remote_total'])) {
+ $data['payment_globalpay_remote_total'] = $this->request->post['payment_globalpay_remote_total'];
+ } else {
+ $data['payment_globalpay_remote_total'] = $this->config->get('payment_globalpay_remote_total');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_sort_order'])) {
+ $data['payment_globalpay_remote_sort_order'] = $this->request->post['payment_globalpay_remote_sort_order'];
+ } else {
+ $data['payment_globalpay_remote_sort_order'] = $this->config->get('payment_globalpay_remote_sort_order');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_status'])) {
+ $data['payment_globalpay_remote_status'] = $this->request->post['payment_globalpay_remote_status'];
+ } else {
+ $data['payment_globalpay_remote_status'] = $this->config->get('payment_globalpay_remote_status');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_card_data_status'])) {
+ $data['payment_globalpay_remote_card_data_status'] = $this->request->post['payment_globalpay_remote_card_data_status'];
+ } else {
+ $data['payment_globalpay_remote_card_data_status'] = $this->config->get('payment_globalpay_remote_card_data_status');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_debug'])) {
+ $data['payment_globalpay_remote_debug'] = $this->request->post['payment_globalpay_remote_debug'];
+ } else {
+ $data['payment_globalpay_remote_debug'] = $this->config->get('payment_globalpay_remote_debug');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_account'])) {
+ $data['payment_globalpay_remote_account'] = $this->request->post['payment_globalpay_remote_account'];
+ } else {
+ $data['payment_globalpay_remote_account'] = $this->config->get('payment_globalpay_remote_account');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_auto_settle'])) {
+ $data['payment_globalpay_remote_auto_settle'] = $this->request->post['payment_globalpay_remote_auto_settle'];
+ } else {
+ $data['payment_globalpay_remote_auto_settle'] = $this->config->get('payment_globalpay_remote_auto_settle');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_tss_check'])) {
+ $data['payment_globalpay_remote_tss_check'] = $this->request->post['payment_globalpay_remote_tss_check'];
+ } else {
+ $data['payment_globalpay_remote_tss_check'] = $this->config->get('payment_globalpay_remote_tss_check');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_3d'])) {
+ $data['payment_globalpay_remote_3d'] = $this->request->post['payment_globalpay_remote_3d'];
+ } else {
+ $data['payment_globalpay_remote_3d'] = $this->config->get('payment_globalpay_remote_3d');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_liability'])) {
+ $data['payment_globalpay_remote_liability'] = $this->request->post['payment_globalpay_remote_liability'];
+ } else {
+ $data['payment_globalpay_remote_liability'] = $this->config->get('payment_globalpay_remote_liability');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_order_status_success_settled_id'])) {
+ $data['payment_globalpay_remote_order_status_success_settled_id'] = $this->request->post['payment_globalpay_remote_order_status_success_settled_id'];
+ } else {
+ $data['payment_globalpay_remote_order_status_success_settled_id'] = $this->config->get('payment_globalpay_remote_order_status_success_settled_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_order_status_success_unsettled_id'])) {
+ $data['payment_globalpay_remote_order_status_success_unsettled_id'] = $this->request->post['payment_globalpay_remote_order_status_success_unsettled_id'];
+ } else {
+ $data['payment_globalpay_remote_order_status_success_unsettled_id'] = $this->config->get('payment_globalpay_remote_order_status_success_unsettled_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_order_status_decline_id'])) {
+ $data['payment_globalpay_remote_order_status_decline_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_id'];
+ } else {
+ $data['payment_globalpay_remote_order_status_decline_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_order_status_decline_pending_id'])) {
+ $data['payment_globalpay_remote_order_status_decline_pending_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_pending_id'];
+ } else {
+ $data['payment_globalpay_remote_order_status_decline_pending_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_pending_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_order_status_decline_stolen_id'])) {
+ $data['payment_globalpay_remote_order_status_decline_stolen_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_stolen_id'];
+ } else {
+ $data['payment_globalpay_remote_order_status_decline_stolen_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_stolen_id');
+ }
+
+ if (isset($this->request->post['payment_globalpay_remote_order_status_decline_bank_id'])) {
+ $data['payment_globalpay_remote_order_status_decline_bank_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_bank_id'];
+ } else {
+ $data['payment_globalpay_remote_order_status_decline_bank_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_bank_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $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/globalpay_remote', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/globalpay_remote');
+ $this->model_extension_payment_globalpay_remote->install();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_globalpay_remote_status')) {
+ $this->load->model('extension/payment/globalpay_remote');
+
+ $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->get['order_id']);
+
+ if (!empty($globalpay_order)) {
+ $this->load->language('extension/payment/globalpay_remote');
+
+ $globalpay_order['total_captured'] = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']);
+
+ $globalpay_order['total_formatted'] = $this->currency->format($globalpay_order['total'], $globalpay_order['currency_code'], 1, true);
+ $globalpay_order['total_captured_formatted'] = $this->currency->format($globalpay_order['total_captured'], $globalpay_order['currency_code'], 1, true);
+
+ $data['globalpay_order'] = $globalpay_order;
+
+ $data['auto_settle'] = $globalpay_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/globalpay_remote_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/globalpay_remote');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/globalpay_remote');
+
+ $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_globalpay_remote->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_globalpay_remote->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if (isset($void_response->result) && $void_response->result == '00') {
+ $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'void', 0.00);
+ $this->model_extension_payment_globalpay_remote->updateVoidStatus($globalpay_order['globalpay_remote_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/globalpay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/globalpay_remote');
+
+ $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']);
+
+ $capture_response = $this->model_extension_payment_globalpay_remote->capture($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_globalpay_remote->logger('Settle result:\r\n' . print_r($capture_response, 1));
+
+ if (isset($capture_response->result) && $capture_response->result == '00') {
+ $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'payment', $this->request->post['amount']);
+ $total_captured = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']);
+
+ if ($total_captured >= $globalpay_order['total'] || $globalpay_order['settle_type'] == 0) {
+ $this->model_extension_payment_globalpay_remote->updateCaptureStatus($globalpay_order['globalpay_remote_order_id'], 1);
+ $capture_status = 1;
+ $json['msg'] = $this->language->get('text_capture_ok_order');
+ } else {
+ $capture_status = 0;
+ $json['msg'] = $this->language->get('text_capture_ok');
+ }
+
+ $this->model_extension_payment_globalpay_remote->updateForRebate($globalpay_order['globalpay_remote_order_id'], $capture_response->pasref, $capture_response->orderid);
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = (float)$this->request->post['amount'];
+ $json['data']['capture_status'] = $capture_status;
+ $json['data']['total'] = (float)$total_captured;
+ $json['data']['total_formatted'] = $this->currency->format($total_captured, $globalpay_order['currency_code'], 1, true);
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture';
+
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/globalpay_remote');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/globalpay_remote');
+
+ $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_globalpay_remote->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_globalpay_remote->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if (isset($rebate_response->result) && $rebate_response->result == '00') {
+ $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'rebate', $this->request->post['amount']*-1);
+
+ $total_rebated = $this->model_extension_payment_globalpay_remote->getTotalRebated($globalpay_order['globalpay_remote_order_id']);
+ $total_captured = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']);
+
+ if ($total_captured <= 0 && $globalpay_order['capture_status'] == 1) {
+ $this->model_extension_payment_globalpay_remote->updateRebateStatus($globalpay_order['globalpay_remote_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'] * -1;
+ $json['data']['total_captured'] = (float)$total_captured;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/globalpay_remote')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_globalpay_remote_merchant_id']) {
+ $this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['payment_globalpay_remote_secret']) {
+ $this->error['error_secret'] = $this->language->get('error_secret');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/klarna_account.php b/public/admin/controller/extension/payment/klarna_account.php
new file mode 100644
index 0000000..30dff8b
--- /dev/null
+++ b/public/admin/controller/extension/payment/klarna_account.php
@@ -0,0 +1,329 @@
+<?php
+class ControllerExtensionPaymentKlarnaAccount extends Controller {
+ private $error = array();
+ private $pclasses = array();
+
+ public function index() {
+ $this->load->language('extension/payment/klarna_account');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $status = false;
+
+ foreach ($this->request->post['payment_klarna_account_'] as $klarna_account) {
+ if ($klarna_account['status']) {
+ $status = true;
+
+ break;
+ }
+ }
+
+ $klarna_data = array(
+ 'klarna_account_pclasses' => $this->pclasses,
+ 'klarna_account_status' => $status
+ );
+
+ $this->model_setting_setting->editSetting('payment_klarna_account', array_merge($this->request->post, $klarna_data));
+
+ $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->session->data['success'])) {
+ $data['success'] = $this->session->data['success'];
+
+ unset($this->session->data['success']);
+ } else {
+ $data['success'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/klarna_account', '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);
+
+ $data['countries'] = array();
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_germany'),
+ 'code' => 'DEU'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_netherlands'),
+ 'code' => 'NLD'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_denmark'),
+ 'code' => 'DNK'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_sweden'),
+ 'code' => 'SWE'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_norway'),
+ 'code' => 'NOR'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_finland'),
+ 'code' => 'FIN'
+ );
+
+ if (isset($this->request->post['payment_klarna_account'])) {
+ $data['payment_klarna_account'] = $this->request->post['payment_klarna_account'];
+ } else {
+ $data['payment_klarna_account'] = $this->config->get('payment_klarna_account');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $file = DIR_LOGS . 'klarna_account.log';
+
+ if (file_exists($file)) {
+ $data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);
+ } else {
+ $data['log'] = '';
+ }
+
+ $data['clear'] = $this->url->link('extension/payment/klarna_account/clear', 'user_token=' . $this->session->data['user_token'], true);
+
+ $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/klarna_account', $data));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/klarna_account')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ $log = new Log('klarna_account.log');
+
+ $country = array(
+ 'NOR' => array(
+ 'currency' => 1,
+ 'country' => 164,
+ 'language' => 97,
+ ),
+ 'SWE' => array(
+ 'currency' => 0,
+ 'country' => 209,
+ 'language' => 138,
+ ),
+ 'FIN' => array(
+ 'currency' => 2,
+ 'country' => 73,
+ 'language' => 101,
+ ),
+ 'DNK' => array(
+ 'currency' => 3,
+ 'country' => 59,
+ 'language' => 27,
+ ),
+ 'DEU' => array(
+ 'currency' => 2,
+ 'country' => 81,
+ 'language' => 28,
+ ),
+ 'NLD' => array(
+ 'currency' => 2,
+ 'country' => 154,
+ 'language' => 101,
+ ),
+ );
+
+ foreach ($this->request->post['klarna_account'] as $key => $klarna_account) {
+ if ($klarna_account['status']) {
+ $digest = base64_encode(pack("H*", hash('sha256', $klarna_account['merchant'] . ':' . $country[$key]['currency'] . ':' . $klarna_account['secret'])));
+
+ $xml = '<methodCall>';
+ $xml .= ' <methodName>get_pclasses</methodName>';
+ $xml .= ' <params>';
+ $xml .= ' <param><value><string>4.1</string></value></param>';
+ $xml .= ' <param><value><string>API:OPENCART:' . VERSION . '</string></value></param>';
+ $xml .= ' <param><value><int>' . (int)$klarna_account['merchant'] . '</int></value></param>';
+ $xml .= ' <param><value><int>' . $country[$key]['currency'] . '</int></value></param>';
+ $xml .= ' <param><value><string>' . $digest . '</string></value></param>';
+ $xml .= ' <param><value><int>' . $country[$key]['country'] . '</int></value></param>';
+ $xml .= ' <param><value><int>' . $country[$key]['language'] . '</int></value></param>';
+ $xml .= ' </params>';
+ $xml .= '</methodCall>';
+
+ if ($klarna_account['server'] == 'live') {
+ $url = 'https://payment.klarna.com';
+ } else {
+ $url = 'https://payment.testdrive.klarna.com';
+ }
+
+ $curl = curl_init();
+
+ $header = array();
+
+ $header[] = 'Content-Type: text/xml';
+ $header[] = 'Content-Length: ' . strlen($xml);
+
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
+
+ $response = curl_exec($curl);
+
+ if ($response !== false) {
+ $xml = new DOMDocument();
+ $xml->loadXML($response);
+
+ $xpath = new DOMXPath($xml);
+
+ $nodes = $xpath->query('//methodResponse/params/param/value');
+
+ if ($nodes->length == 0) {
+ $this->error['warning'] = $this->language->get('error_log');
+
+ $error_code = $xpath->query('//methodResponse/fault/value/struct/member/value/int')->item(0)->nodeValue;
+ $error_message = $xpath->query('//methodResponse/fault/value/struct/member/value/string')->item(0)->nodeValue;
+
+ $log->write(sprintf($this->language->get('error_pclass'), $key, $error_code, $error_message));
+
+ continue;
+ }
+
+ $pclasses = $this->parseResponse($nodes->item(0)->firstChild, $xml);
+
+ while ($pclasses) {
+ $pclass = array_slice($pclasses, 0, 10);
+ $pclasses = array_slice($pclasses, 10);
+
+ $pclass[3] /= 100;
+ $pclass[4] /= 100;
+ $pclass[5] /= 100;
+ $pclass[6] /= 100;
+ $pclass[9] = ($pclass[9] != '-') ? strtotime($pclass[9]) : $pclass[9];
+
+ array_unshift($pclass, $klarna_account['merchant']);
+
+ $this->pclasses[$key][] = array(
+ 'eid' => intval($pclass[0]),
+ 'id' => intval($pclass[1]),
+ 'description' => $pclass[2],
+ 'months' => intval($pclass[3]),
+ 'startfee' => floatval($pclass[4]),
+ 'invoicefee' => floatval($pclass[5]),
+ 'interestrate' => floatval($pclass[6]),
+ 'minamount' => floatval($pclass[7]),
+ 'country' => intval($pclass[8]),
+ 'type' => intval($pclass[9]),
+ );
+ }
+ } else {
+ $this->error['warning'] = $this->language->get('error_log');
+
+ $log->write(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl)));
+ }
+
+ curl_close($curl);
+ }
+ }
+
+ return !$this->error;
+ }
+
+ private function parseResponse($node, $document) {
+ $child = $node;
+
+ switch ($child->nodeName) {
+ case 'string':
+ $value = $child->nodeValue;
+ break;
+ case 'boolean':
+ $value = (string)$child->nodeValue;
+
+ if ($value == '0') {
+ $value = false;
+ } elseif ($value == '1') {
+ $value = true;
+ } else {
+ $value = null;
+ }
+
+ break;
+ case 'integer':
+ case 'int':
+ case 'i4':
+ case 'i8':
+ $value = (int)$child->nodeValue;
+ break;
+ case 'array':
+ $value = array();
+
+ $xpath = new DOMXPath($document);
+ $entries = $xpath->query('.//array/data/value', $child);
+
+ for ($i = 0; $i < $entries->length; $i++) {
+ $value[] = $this->parseResponse($entries->item($i)->firstChild, $document);
+ }
+
+ break;
+ default:
+ $value = null;
+ }
+
+ return $value;
+ }
+
+ public function clear() {
+ $this->load->language('extension/payment/klarna_account');
+
+ $file = DIR_LOGS . 'klarna_account.log';
+
+ $handle = fopen($file, 'w+');
+
+ fclose($handle);
+
+ $this->session->data['success'] = $this->language->get('text_success');
+
+ $this->response->redirect($this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true));
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/klarna_checkout.php b/public/admin/controller/extension/payment/klarna_checkout.php
new file mode 100644
index 0000000..edeb9c4
--- /dev/null
+++ b/public/admin/controller/extension/payment/klarna_checkout.php
@@ -0,0 +1,859 @@
+<?php
+class ControllerExtensionPaymentKlarnaCheckout extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/klarna_checkout');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_klarna_checkout', $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));
+ }
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $this->load->model('localisation/language');
+
+ $data['languages'] = $this->model_localisation_language->getLanguages();
+
+ $this->load->model('localisation/country');
+
+ $data['countries'] = $this->model_localisation_country->getCountries();
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $data['api_locations'] = array(
+ array(
+ 'name' => 'North America',
+ 'code' => 'NA'
+ ),
+ array(
+ 'name' => 'Europe',
+ 'code' => 'EU'
+ )
+ );
+
+ $this->load->model('catalog/information');
+
+ $data['informations'] = $this->model_catalog_information->getInformations();
+
+ $this->load->model('localisation/currency');
+
+ $data['currencies'] = $this->model_localisation_currency->getCurrencies();
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ $this->load->model('extension/payment/klarna_checkout');
+
+ if ($this->model_extension_payment_klarna_checkout->checkForPaymentTaxes()) {
+ $data['error_tax_warning'] = $this->language->get('error_tax_warning');
+ } else {
+ $data['error_tax_warning'] = '';
+ }
+
+ if (isset($this->error['account_warning'])) {
+ $data['error_account_warning'] = $this->error['account_warning'];
+ } else {
+ $data['error_account_warning'] = '';
+ }
+
+ if (isset($this->error['account'])) {
+ $data['error_account'] = $this->error['account'];
+ } else {
+ $data['error_account'] = array();
+ }
+
+ if (isset($this->error['settlement_warning'])) {
+ $data['error_settlement_warning'] = $this->error['settlement_warning'];
+ } else {
+ $data['error_settlement_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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/klarna_checkout', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/klarna_checkout', '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['klarna_checkout_debug'])) {
+ $data['klarna_checkout_debug'] = $this->request->post['klarna_checkout_debug'];
+ } else {
+ $data['klarna_checkout_debug'] = $this->config->get('klarna_checkout_debug');
+ }
+
+ if (isset($this->request->post['klarna_checkout_colour_button'])) {
+ $data['klarna_checkout_colour_button'] = $this->request->post['klarna_checkout_colour_button'];
+ } elseif ($this->config->get('klarna_checkout_colour_button')) {
+ $data['klarna_checkout_colour_button'] = $this->config->get('klarna_checkout_colour_button');
+ } else {
+ $data['klarna_checkout_colour_button'] = '#0072cc';
+ }
+
+ if (isset($this->request->post['klarna_checkout_colour_button_text'])) {
+ $data['klarna_checkout_colour_button_text'] = $this->request->post['klarna_checkout_colour_button_text'];
+ } elseif ($this->config->get('klarna_checkout_colour_button_text')) {
+ $data['klarna_checkout_colour_button_text'] = $this->config->get('klarna_checkout_colour_button_text');
+ } else {
+ $data['klarna_checkout_colour_button_text'] = '#ffffff';
+ }
+
+ if (isset($this->request->post['klarna_checkout_colour_checkbox'])) {
+ $data['klarna_checkout_colour_checkbox'] = $this->request->post['klarna_checkout_colour_checkbox'];
+ } elseif ($this->config->get('klarna_checkout_colour_checkbox')) {
+ $data['klarna_checkout_colour_checkbox'] = $this->config->get('klarna_checkout_colour_checkbox');
+ } else {
+ $data['klarna_checkout_colour_checkbox'] = '#0072cc';
+ }
+
+ if (isset($this->request->post['klarna_checkout_colour_checkbox_checkmark'])) {
+ $data['klarna_checkout_colour_checkbox_checkmark'] = $this->request->post['klarna_checkout_colour_checkbox_checkmark'];
+ } elseif ($this->config->get('klarna_checkout_colour_checkbox_checkmark')) {
+ $data['klarna_checkout_colour_checkbox_checkmark'] = $this->config->get('klarna_checkout_colour_checkbox_checkmark');
+ } else {
+ $data['klarna_checkout_colour_checkbox_checkmark'] = '#ffffff';
+ }
+
+ if (isset($this->request->post['klarna_checkout_colour_header'])) {
+ $data['klarna_checkout_colour_header'] = $this->request->post['klarna_checkout_colour_header'];
+ } elseif ($this->config->get('klarna_checkout_colour_header')) {
+ $data['klarna_checkout_colour_header'] = $this->config->get('klarna_checkout_colour_header');
+ } else {
+ $data['klarna_checkout_colour_header'] = '#434343';
+ }
+
+ if (isset($this->request->post['klarna_checkout_colour_link'])) {
+ $data['klarna_checkout_colour_link'] = $this->request->post['klarna_checkout_colour_link'];
+ } elseif ($this->config->get('klarna_checkout_colour_link')) {
+ $data['klarna_checkout_colour_link'] = $this->config->get('klarna_checkout_colour_link');
+ } else {
+ $data['klarna_checkout_colour_link'] = '#0072cc';
+ }
+
+ if (isset($this->request->post['klarna_checkout_separate_shipping_address'])) {
+ $data['klarna_checkout_separate_shipping_address'] = $this->request->post['klarna_checkout_separate_shipping_address'];
+ } else {
+ $data['klarna_checkout_separate_shipping_address'] = $this->config->get('klarna_checkout_separate_shipping_address');
+ }
+
+ if (isset($this->request->post['klarna_checkout_dob_mandatory'])) {
+ $data['klarna_checkout_dob_mandatory'] = $this->request->post['klarna_checkout_dob_mandatory'];
+ } else {
+ $data['klarna_checkout_dob_mandatory'] = $this->config->get('klarna_checkout_dob_mandatory');
+ }
+
+ if (isset($this->request->post['klarna_checkout_title_mandatory'])) {
+ $data['klarna_checkout_title_mandatory'] = $this->request->post['klarna_checkout_title_mandatory'];
+ } else {
+ $data['klarna_checkout_title_mandatory'] = $this->config->get('klarna_checkout_title_mandatory');
+ }
+
+ if (isset($this->request->post['klarna_checkout_additional_text_box'])) {
+ $data['klarna_checkout_additional_text_box'] = $this->request->post['klarna_checkout_additional_text_box'];
+ } else {
+ $data['klarna_checkout_additional_text_box'] = $this->config->get('klarna_checkout_additional_text_box');
+ }
+
+ if (isset($this->request->post['klarna_checkout_total'])) {
+ $data['klarna_checkout_total'] = $this->request->post['klarna_checkout_total'];
+ } else {
+ $data['klarna_checkout_total'] = $this->config->get('klarna_checkout_total');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_authorised_id'])) {
+ $data['klarna_checkout_order_status_authorised_id'] = $this->request->post['klarna_checkout_order_status_authorised_id'];
+ } else {
+ $data['klarna_checkout_order_status_authorised_id'] = $this->config->get('klarna_checkout_order_status_authorised_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_part_captured_id'])) {
+ $data['klarna_checkout_order_status_part_captured_id'] = $this->request->post['klarna_checkout_order_status_part_captured_id'];
+ } else {
+ $data['klarna_checkout_order_status_part_captured_id'] = $this->config->get('klarna_checkout_order_status_part_captured_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_captured_id'])) {
+ $data['klarna_checkout_order_status_captured_id'] = $this->request->post['klarna_checkout_order_status_captured_id'];
+ } else {
+ $data['klarna_checkout_order_status_captured_id'] = $this->config->get('klarna_checkout_order_status_captured_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_cancelled_id'])) {
+ $data['klarna_checkout_order_status_cancelled_id'] = $this->request->post['klarna_checkout_order_status_cancelled_id'];
+ } else {
+ $data['klarna_checkout_order_status_cancelled_id'] = $this->config->get('klarna_checkout_order_status_cancelled_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_refund_id'])) {
+ $data['klarna_checkout_order_status_refund_id'] = $this->request->post['klarna_checkout_order_status_refund_id'];
+ } else {
+ $data['klarna_checkout_order_status_refund_id'] = $this->config->get('klarna_checkout_order_status_refund_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_fraud_rejected_id'])) {
+ $data['klarna_checkout_order_status_fraud_rejected_id'] = $this->request->post['klarna_checkout_order_status_fraud_rejected_id'];
+ } else {
+ $data['klarna_checkout_order_status_fraud_rejected_id'] = $this->config->get('klarna_checkout_order_status_fraud_rejected_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_fraud_pending_id'])) {
+ $data['klarna_checkout_order_status_fraud_pending_id'] = $this->request->post['klarna_checkout_order_status_fraud_pending_id'];
+ } else {
+ $data['klarna_checkout_order_status_fraud_pending_id'] = $this->config->get('klarna_checkout_order_status_fraud_pending_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_order_status_fraud_accepted_id'])) {
+ $data['klarna_checkout_order_status_fraud_accepted_id'] = $this->request->post['klarna_checkout_order_status_fraud_accepted_id'];
+ } else {
+ $data['klarna_checkout_order_status_fraud_accepted_id'] = $this->config->get('klarna_checkout_order_status_fraud_accepted_id');
+ }
+
+ if (isset($this->request->post['klarna_checkout_terms'])) {
+ $data['klarna_checkout_terms'] = $this->request->post['klarna_checkout_terms'];
+ } else {
+ $data['klarna_checkout_terms'] = $this->config->get('klarna_checkout_terms');
+ }
+
+ if (isset($this->request->post['klarna_checkout_status'])) {
+ $data['klarna_checkout_status'] = $this->request->post['klarna_checkout_status'];
+ } else {
+ $data['klarna_checkout_status'] = $this->config->get('klarna_checkout_status');
+ }
+
+ if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post['klarna_checkout_account'])) {
+ $data['klarna_checkout_account'] = array();
+ } elseif ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->post['klarna_checkout_account'])) {
+ $data['klarna_checkout_account'] = $this->request->post['klarna_checkout_account'];
+ } elseif ($this->config->get('klarna_checkout_account')) {
+ $data['klarna_checkout_account'] = $this->config->get('klarna_checkout_account');
+ } else {
+ $data['klarna_checkout_account'] = array();
+ }
+
+ if (isset($this->request->post['klarna_checkout_sftp_username'])) {
+ $data['klarna_checkout_sftp_username'] = $this->request->post['klarna_checkout_sftp_username'];
+ } else {
+ $data['klarna_checkout_sftp_username'] = $this->config->get('klarna_checkout_sftp_username');
+ }
+
+ if (isset($this->request->post['klarna_checkout_sftp_password'])) {
+ $data['klarna_checkout_sftp_password'] = $this->request->post['klarna_checkout_sftp_password'];
+ } else {
+ $data['klarna_checkout_sftp_password'] = $this->config->get('klarna_checkout_sftp_password');
+ }
+
+ if (isset($this->request->post['klarna_checkout_settlement_order_status_id'])) {
+ $data['klarna_checkout_settlement_order_status_id'] = $this->request->post['klarna_checkout_settlement_order_status_id'];
+ } else {
+ $data['klarna_checkout_settlement_order_status_id'] = $this->config->get('klarna_checkout_settlement_order_status_id');
+ }
+
+ $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
+
+ // API login
+ $this->load->model('user/api');
+
+ $api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
+
+ if ($api_info) {
+ $data['api_id'] = $api_info['api_id'];
+ $data['api_key'] = $api_info['key'];
+ $data['api_ip'] = $this->request->server['REMOTE_ADDR'];
+ } else {
+ $data['api_id'] = '';
+ $data['api_key'] = '';
+ $data['api_ip'] = '';
+ }
+
+ $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/klarna_checkout', $data));
+ }
+
+ public function order() {
+ $this->load->language('extension/payment/klarna_checkout');
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ return $this->load->view('extension/payment/klarna_checkout_order', $data);
+ }
+
+ public function getTransaction() {
+ $this->load->language('extension/payment/klarna_checkout');
+
+ $this->load->model('extension/payment/klarna_checkout');
+ $this->load->model('sale/order');
+
+ if (!$this->config->get('klarna_checkout_status') || !isset($this->request->get['order_id'])) {
+ return;
+ }
+
+ $order_reference = $this->model_extension_payment_klarna_checkout->getOrder($this->request->get['order_id']);
+
+ $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
+
+ if (!$order_reference || !$order_reference['order_ref'] || !$order_info) {
+ return;
+ }
+
+ list($klarna_account, $connector) = $this->model_extension_payment_klarna_checkout->getConnector($this->config->get('klarna_checkout_account'), $order_info['currency_code']);
+
+ if (!$klarna_account || !$connector) {
+ return;
+ }
+
+ $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $order_reference['order_ref']);
+
+ if (!$klarna_order) {
+ return;
+ }
+
+ $data['order_ref'] = $order_reference['order_ref'];
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
+
+ $extend_authorization_action = $cancel_action = $capture_action = $refund_action = $merchant_reference_action = $address_action = $release_authorization_action = false;
+
+ switch (strtoupper($klarna_order['status'])) {
+ case 'AUTHORIZED':
+ $merchant_reference_action = true;
+ $extend_authorization_action = true;
+ $address_action = true;
+ $cancel_action = true;
+ $capture_action = true;
+ break;
+ case 'PART_CAPTURED':
+ $merchant_reference_action = true;
+ $extend_authorization_action = true;
+ $release_authorization_action = true;
+ $address_action = true;
+ $capture_action = true;
+ $refund_action = true;
+ break;
+ case 'CAPTURED':
+ $address_action = true;
+ $merchant_reference_action = true;
+ $refund_action = true;
+ break;
+ case 'CANCELLED':
+ break;
+ case 'EXPIRED':
+ break;
+ case 'CLOSED':
+ break;
+ }
+
+ $format = '{title} {given_name} {family_name}' . "\n" . '{street_address}' . "\n" . '{street_address2}' . "\n" . '{city} {postcode}' . "\n" . '{region}' . "\n" . '{country}' . "\n" . '{email} {phone}';
+
+ $find = array(
+ '{title}',
+ '{given_name}',
+ '{family_name}',
+ '{street_address}',
+ '{street_address2}',
+ '{city}',
+ '{postcode}',
+ '{region}',
+ '{country}',
+ '{email}',
+ '{phone}',
+ );
+
+ $replace = array(
+ 'title' => $klarna_order['billing_address']['title'],
+ 'given_name' => $klarna_order['billing_address']['given_name'],
+ 'family_name' => $klarna_order['billing_address']['family_name'],
+ 'street_address' => $klarna_order['billing_address']['street_address'],
+ 'street_address2' => $klarna_order['billing_address']['street_address2'],
+ 'city' => $klarna_order['billing_address']['city'],
+ 'postcode' => $klarna_order['billing_address']['postal_code'],
+ 'region' => $klarna_order['billing_address']['region'],
+ 'country' => $klarna_order['billing_address']['country'],
+ 'email' => $klarna_order['billing_address']['email'],
+ 'phone' => $klarna_order['billing_address']['phone']
+ );
+
+ $billing_address_formatted = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
+
+ $replace = array(
+ 'title' => $klarna_order['shipping_address']['title'],
+ 'given_name' => $klarna_order['shipping_address']['given_name'],
+ 'family_name' => $klarna_order['shipping_address']['family_name'],
+ 'street_address' => $klarna_order['shipping_address']['street_address'],
+ 'street_address2' => $klarna_order['shipping_address']['street_address2'],
+ 'city' => $klarna_order['shipping_address']['city'],
+ 'postcode' => $klarna_order['shipping_address']['postal_code'],
+ 'region' => $klarna_order['shipping_address']['region'],
+ 'country' => $klarna_order['shipping_address']['country'],
+ 'email' => $klarna_order['shipping_address']['email'],
+ 'phone' => $klarna_order['shipping_address']['phone']
+ );
+
+ $shipping_address_formatted = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
+
+ $order_lines = array();
+
+ foreach ($klarna_order['order_lines'] as $order_line) {
+ $order_lines[] = array(
+ 'reference' => $order_line['reference'],
+ 'type' => $order_line['type'],
+ 'quantity' => $order_line['quantity'],
+ 'quantity_unit' => $order_line['quantity_unit'],
+ 'name' => $order_line['name'],
+ 'total_amount' => $this->currency->format($order_line['total_amount'] / 100, $order_info['currency_code'], '1.00000000'),
+ 'unit_price' => $this->currency->format($order_line['unit_price'] / 100, $order_info['currency_code'], '1.00000000'),
+ 'total_discount_amount' => $this->currency->format($order_line['total_discount_amount'] / 100, $order_info['currency_code'], '1.00000000'),
+ 'tax_rate' => ($order_line['tax_rate'] / 100) . '%',
+ 'total_tax_amount' => $this->currency->format($order_line['total_tax_amount'] / 100, $order_info['currency_code'], '1.00000000')
+ );
+ }
+
+ $merchant_id = '';
+ if ($order_reference['data']) {
+ $klarna_checkout_order_data = json_decode($this->encryption->decrypt($this->config->get('config_encryption'), $order_reference['data']), true);
+ if ($klarna_checkout_order_data && $klarna_checkout_order_data['merchant_id']) {
+ $merchant_id = $klarna_checkout_order_data['merchant_id'];
+ }
+ }
+
+ $data['transaction'] = array(
+ 'order_id' => $klarna_order['order_id'],
+ 'merchant_id' => $merchant_id,
+ 'reference' => $klarna_order['klarna_reference'],
+ 'status' => $klarna_order['status'],
+ 'fraud_status' => $klarna_order['fraud_status'],
+ 'merchant_reference_1' => $klarna_order['merchant_reference1'],
+ 'billing_address' => $klarna_order['billing_address'],
+ 'shipping_address' => $klarna_order['shipping_address'],
+ 'billing_address_formatted' => $billing_address_formatted,
+ 'shipping_address_formatted' => $shipping_address_formatted,
+ 'order_lines' => $order_lines,
+ 'amount' => $this->currency->format($klarna_order['order_amount'] / 100, $order_info['currency_code'], '1.00000000'),
+ 'authorization_expiry' => isset($klarna_order['expires_at']) ? date($this->language->get('date_format_short'), strtotime($klarna_order['expires_at'])) : '',
+ 'authorization_remaining' => $this->currency->format($klarna_order['remaining_authorized_amount'] / 100, $order_info['currency_code'], '1.00000000'),
+ );
+
+ $max_capture_amount = $klarna_order['remaining_authorized_amount'] / 100;
+
+ $max_refund_amount = $klarna_order['captured_amount'] / 100;
+
+ $data['captures'] = array();
+
+ foreach ($klarna_order['captures'] as $capture) {
+ $data['captures'][] = array(
+ 'capture_id' => $capture['capture_id'],
+ 'shipping_info_title' => sprintf($this->language->get('text_capture_shipping_info_title'), $capture['capture_id']),
+ 'billing_address_title' => sprintf($this->language->get('text_capture_billing_address_title'), $capture['capture_id']),
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($capture['captured_at'])),
+ 'amount' => $this->currency->format($capture['captured_amount'] / 100, $order_info['currency_code'], '1.00000000', true),
+ 'reference' => $capture['klarna_reference'],
+ 'shipping_info' => $capture['shipping_info'],
+ 'billing_address' => $capture['billing_address'],
+ 'shipping_address' => $capture['shipping_address']
+ );
+ }
+
+ $data['refunds'] = array();
+
+ foreach ($klarna_order['refunds'] as $capture) {
+ $max_refund_amount -= ($capture['refunded_amount'] / 100);
+
+ $data['refunds'][] = array(
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($capture['refunded_at'])),
+ 'amount' => $this->currency->format($capture['refunded_amount'] / 100, $order_info['currency_code'], '1.00000000', true)
+ );
+ }
+
+ if (!$max_capture_amount) {
+ $capture_action = false;
+ }
+
+ if (!$max_refund_amount) {
+ $refund_action = false;
+ }
+
+ $data['allowed_shipping_methods'] = array(
+ 'PickUpStore',
+ 'Home',
+ 'BoxReg',
+ 'BoxUnreg',
+ 'PickUpPoint',
+ 'Own'
+ );
+
+ $data['extend_authorization_action'] = $extend_authorization_action;
+ $data['cancel_action'] = $cancel_action;
+ $data['capture_action'] = $capture_action;
+ $data['refund_action'] = $refund_action;
+ $data['address_action'] = $address_action;
+ $data['merchant_reference_action'] = $merchant_reference_action;
+ $data['release_authorization_action'] = $release_authorization_action;
+ $data['max_capture_amount'] = $this->currency->format($max_capture_amount, $order_info['currency_code'], '1.00000000', false);
+ $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $order_info['currency_code'], '1.00000000', false);
+ $data['symbol_left'] = $this->currency->getSymbolLeft($order_info['currency_code']);
+ $data['symbol_right'] = $this->currency->getSymbolRight($order_info['currency_code']);
+
+ // The URL we send API requests to
+ $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
+
+ // API login
+ $this->load->model('user/api');
+
+ $api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
+
+ if ($api_info && $this->user->hasPermission('modify', 'sale/order')) {
+ $session = new Session($this->config->get('session_engine'), $this->registry);
+
+ $session->start();
+
+ $this->model_user_api->deleteApiSessionBySessonId($session->getId());
+
+ $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']);
+
+ $session->data['api_id'] = $api_info['api_id'];
+
+ $data['api_token'] = $session->getId();
+ } else {
+ $data['api_token'] = '';
+ }
+
+ $this->response->setOutput($this->load->view('extension/payment/klarna_checkout_order_ajax', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/klarna_checkout');
+ $this->model_extension_payment_klarna_checkout->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/klarna_checkout');
+ $this->model_extension_payment_klarna_checkout->uninstall();
+ }
+
+ public function transactionCommand() {
+ $this->load->language('extension/payment/klarna_checkout');
+
+ $this->load->model('extension/payment/klarna_checkout');
+ $this->load->model('sale/order');
+
+ $json = array();
+
+ $success = $error = '';
+
+ $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
+
+ list($klarna_account, $connector) = $this->model_extension_payment_klarna_checkout->getConnector($this->config->get('klarna_checkout_account'), $order_info['currency_code']);
+
+ if (!$klarna_account || !$connector) {
+ return;
+ }
+
+ $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $this->request->post['order_ref']);
+
+ if (!$klarna_order) {
+ return;
+ }
+
+ $old_klarna_status = $klarna_order['status'];
+
+ if ($this->request->post['type'] == 'cancel') {
+ $action = $this->model_extension_payment_klarna_checkout->omCancel($connector, $this->request->post['order_ref']);
+ } elseif ($this->request->post['type'] == 'capture' && $this->request->post['data']) {
+ $action = $this->model_extension_payment_klarna_checkout->omCapture($connector, $this->request->post['order_ref'], array(
+ 'captured_amount' => $this->request->post['data'] * 100
+ ));
+ } elseif ($this->request->post['type'] == 'refund' && $this->request->post['data']) {
+ $action = $this->model_extension_payment_klarna_checkout->omRefund($connector, $this->request->post['order_ref'], array(
+ 'refunded_amount' => $this->request->post['data'] * 100
+ ));
+ } elseif ($this->request->post['type'] == 'extend_authorization') {
+ $action = $this->model_extension_payment_klarna_checkout->omExtendAuthorizationTime($connector, $this->request->post['order_ref']);
+ } elseif ($this->request->post['type'] == 'merchant_reference' && $this->request->post['data']) {
+ $data = array();
+ parse_str(html_entity_decode($this->request->post['data']), $data);
+
+ $action = $this->model_extension_payment_klarna_checkout->omUpdateMerchantReference($connector, $this->request->post['order_ref'], array(
+ 'merchant_reference1' => (string)$data['merchant_reference_1']
+ ));
+ } elseif (($this->request->post['type'] == 'billing_address' || $this->request->post['type'] == 'shipping_address') && $this->request->post['data']) {
+ if ($this->request->post['type'] == 'billing_address') {
+ $data['billing_address'] = array();
+ parse_str(html_entity_decode($this->request->post['data']), $data['billing_address']);
+ } else if ($this->request->post['type'] == 'shipping_address') {
+ $data['shipping_address'] = array();
+ parse_str(html_entity_decode($this->request->post['data']), $data['shipping_address']);
+ }
+
+ $action = $this->model_extension_payment_klarna_checkout->omUpdateAddress($connector, $this->request->post['order_ref'], $data);
+ } elseif ($this->request->post['type'] == 'release_authorization') {
+ $action = $this->model_extension_payment_klarna_checkout->omReleaseAuthorization($connector, $this->request->post['order_ref']);
+ } elseif ($this->request->post['type'] == 'capture_shipping_info' && isset($this->request->post['id'])) {
+ $data = array();
+ parse_str(html_entity_decode($this->request->post['data']), $data);
+
+ $action = $this->model_extension_payment_klarna_checkout->omShippingInfo($connector, $this->request->post['order_ref'], $this->request->post['id'], $data);
+ } elseif ($this->request->post['type'] == 'capture_billing_address' && isset($this->request->post['id'])) {
+ $data['billing_address'] = array();
+ parse_str(html_entity_decode($this->request->post['data']), $data['billing_address']);
+
+ $action = $this->model_extension_payment_klarna_checkout->omCustomerDetails($connector, $this->request->post['order_ref'], $this->request->post['id'], $data);
+ } elseif ($this->request->post['type'] == 'trigger_send_out' && isset($this->request->post['id'])) {
+ $action = $this->model_extension_payment_klarna_checkout->omTriggerSendOut($connector, $this->request->post['order_ref'], $this->request->post['id']);
+ } else {
+ $error = true;
+ }
+
+ $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $this->request->post['order_ref']);
+
+ if (!$klarna_order) {
+ return;
+ }
+
+ $new_klarna_status = $klarna_order['status'];
+
+ $order_status_id = '';
+ if ($old_klarna_status != $new_klarna_status) {
+ switch ($klarna_order['status']) {
+ case 'AUTHORIZED':
+ $order_status_id = $this->config->get('klarna_checkout_order_status_authorised_id');
+
+ if ($klarna_order['fraud_status'] == 'PENDING') {
+ $order_status_id = $this->config->get('klarna_checkout_order_status_fraud_pending_id');
+ } elseif ($klarna_order['fraud_status'] == 'REJECTED') {
+ $order_status_id = $this->config->get('klarna_checkout_order_status_fraud_rejected_id');
+ }
+ break;
+ case 'PART_CAPTURED':
+ $order_status_id = $this->config->get('klarna_checkout_order_status_part_captured_id');
+ break;
+ case 'CAPTURED':
+ $order_status_id = $this->config->get('klarna_checkout_order_status_captured_id');
+ break;
+ case 'CANCELLED':
+ $order_status_id = $this->config->get('klarna_checkout_order_status_cancelled_id');
+ break;
+ }
+ } elseif ($this->request->post['type'] == 'refund' && ($klarna_order['captured_amount'] - $klarna_order['refunded_amount'] == 0)) {
+ $order_status_id = $this->config->get('klarna_checkout_order_status_refund_id');
+ }
+
+ if (!$error && $action) {
+ $success = $this->language->get('text_success_action');
+ } elseif (!$error && $action && isset($action->message)) {
+ $error = sprintf($this->language->get('text_error_settle'), $action->message);
+ } else {
+ $error = $this->language->get('text_error_generic');
+ }
+
+ $json['success'] = $success;
+ $json['error'] = $error;
+ $json['order_status_id'] = $order_status_id;
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function downloadSettlementFiles() {
+ $this->load->language('extension/payment/klarna_checkout');
+
+ $this->load->model('extension/payment/klarna_checkout');
+ $this->load->model('sale/order');
+
+ $json = array();
+
+ $error = array();
+
+ $klarna_checkout_directory = DIR_UPLOAD . 'klarna_checkout/';
+
+ if (isset($this->request->post['username'])) {
+ $username = $this->request->post['username'];
+ } else {
+ $username = '';
+ }
+
+ if (isset($this->request->post['password'])) {
+ $password = html_entity_decode($this->request->post['password']);
+ } else {
+ $password = '';
+ }
+
+ if (isset($this->request->post['order_status_id'])) {
+ $order_status_id = $this->request->post['order_status_id'];
+ } else {
+ $order_status_id = false;
+ }
+
+ if (!$username || !$password || !$order_status_id) {
+ $error[] = 'Please supply a username, password and order status';
+ }
+
+ if (!$error) {
+ // Connect to the site via FTP
+ $connection = ftp_connect('mft.klarna.com', '4001');
+
+ $files = array();
+
+ if ($connection) {
+ $login = ftp_login($connection, $username, $password);
+
+ if ($login) {
+ $files = ftp_nlist($connection, '.');
+
+ rsort($files);
+
+ if (!is_dir($klarna_checkout_directory)) {
+ mkdir($klarna_checkout_directory, 0777);
+ }
+
+ // Save all files to local
+ foreach (array_diff($files, array('.', '..')) as $file) {
+ if (!ftp_get($connection, $klarna_checkout_directory . $file, $file, FTP_BINARY)) {
+ $error[] = 'There was a problem saving one or more files';
+ }
+ }
+ }
+ }
+ }
+
+ $orders_to_process = array();
+
+ $files = scandir($klarna_checkout_directory);
+
+ if (!$error) {
+ // Loop local files and process
+ foreach (array_diff($files, array('.', '..')) as $file) {
+ $handle = fopen($klarna_checkout_directory . $file, 'r');
+
+ // Skip first 2 lines, use third as headings
+ fgetcsv($handle);
+ fgetcsv($handle);
+ $headings = fgetcsv($handle);
+
+ while ($data = fgetcsv($handle)) {
+ $row = array_combine($headings, $data);
+
+ if ($row['type'] == 'SALE') {
+ $order_id = $this->encryption->decrypt($this->config->get('config_encryption'), $row['merchant_reference1']);
+
+ $klarna_order_info = $this->model_extension_payment_klarna_checkout->getOrder($order_id);
+
+ $order_info = $this->model_sale_order->getOrder($order_id);
+
+ // Check if order exists in system, if it does, pass back to process
+ if ($klarna_order_info && $order_info && ($order_info['payment_code'] == 'klarna_checkout') && ($order_info['order_status_id'] != $order_status_id)) {
+ $orders_to_process[] = $order_id;
+ }
+ }
+ }
+
+ fclose($handle);
+ }
+ }
+
+ // Delete local files
+ foreach (array_diff($files, array('.', '..')) as $file) {
+ if (!unlink($klarna_checkout_directory . $file)) {
+ $error[] = 'Cannot delete files';
+ }
+ }
+
+ if ($error) {
+ $orders_to_process = array();
+ }
+
+ $json['error'] = $error;
+ $json['orders'] = $orders_to_process;
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ $this->load->model('extension/payment/klarna_checkout');
+ $this->load->model('localisation/geo_zone');
+
+ if (version_compare(phpversion(), '5.4.0', '<')) {
+ $this->error['warning'] = $this->language->get('error_php_version');
+ }
+
+ if (!$this->user->hasPermission('modify', 'extension/payment/klarna_checkout')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->config->get('config_secure')) {
+ $this->error['warning'] = $this->language->get('error_ssl');
+ }
+
+ if (empty($this->request->post['klarna_checkout_account'])) {
+ $this->error['account_warning'] = $this->language->get('error_account_minimum');
+ } else {
+ $currencies = array();
+
+ foreach ($this->request->post['klarna_checkout_account'] as $key => $account) {
+ if (in_array($account['currency'], $currencies)) {
+ $this->error['account_warning'] = $this->language->get('error_account_currency');
+
+ break;
+ } else {
+ $currencies[] = $account['currency'];
+ }
+
+ if (!$account['merchant_id']) {
+ $this->error['account'][$key]['merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$account['secret']) {
+ $this->error['account'][$key]['secret'] = $this->language->get('error_secret');
+ }
+
+ if (!$account['locale']) {
+ $this->error['account'][$key]['locale'] = $this->language->get('error_locale');
+ }
+ }
+ }
+
+ if ($this->error && !isset($this->error['warning'])) {
+ $this->error['warning'] = $this->language->get('error_warning');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/klarna_invoice.php b/public/admin/controller/extension/payment/klarna_invoice.php
new file mode 100644
index 0000000..584d9cd
--- /dev/null
+++ b/public/admin/controller/extension/payment/klarna_invoice.php
@@ -0,0 +1,201 @@
+<?php
+class ControllerExtensionPaymentKlarnaInvoice extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/klarna_invoice');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $status = false;
+
+ foreach ($this->request->post['payment_klarna_invoice'] as $klarna_invoice) {
+ if ($klarna_invoice['status']) {
+ $status = true;
+
+ break;
+ }
+ }
+
+ $klarna_data = array(
+ 'klarna_invoice_pclasses' => $this->pclasses,
+ 'klarna_invoice_status' => $status
+ );
+
+ $this->model_setting_setting->editSetting('payment_klarna_invoice', array_merge($this->request->post, $klarna_data));
+
+ $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->session->data['success'])) {
+ $data['success'] = $this->session->data['success'];
+
+ unset($this->session->data['success']);
+ } else {
+ $data['success'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/klarna_invoice', '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);
+
+ $data['countries'] = array();
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_germany'),
+ 'code' => 'DEU'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_netherlands'),
+ 'code' => 'NLD'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_denmark'),
+ 'code' => 'DNK'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_sweden'),
+ 'code' => 'SWE'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_norway'),
+ 'code' => 'NOR'
+ );
+
+ $data['countries'][] = array(
+ 'name' => $this->language->get('text_finland'),
+ 'code' => 'FIN'
+ );
+
+ if (isset($this->request->post['payment_klarna_invoice'])) {
+ $data['payment_klarna_invoice'] = $this->request->post['payment_klarna_invoice'];
+ } else {
+ $data['payment_klarna_invoice'] = $this->config->get('payment_klarna_invoice');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $file = DIR_LOGS . 'klarna_invoice.log';
+
+ if (file_exists($file)) {
+ $data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);
+ } else {
+ $data['log'] = '';
+ }
+
+ $data['clear'] = $this->url->link('extension/payment/klarna_invoice/clear', 'user_token=' . $this->session->data['user_token'], true);
+
+ $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/klarna_invoice', $data));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/klarna_invoice')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ return !$this->error;
+ }
+
+ private function parseResponse($node, $document) {
+ $child = $node;
+
+ switch ($child->nodeName) {
+ case 'string':
+ $value = $child->nodeValue;
+ break;
+
+ case 'boolean':
+ $value = (string)$child->nodeValue;
+
+ if ($value == '0') {
+ $value = false;
+ } elseif ($value == '1') {
+ $value = true;
+ } else {
+ $value = null;
+ }
+
+ break;
+
+ case 'integer':
+ case 'int':
+ case 'i4':
+ case 'i8':
+ $value = (int)$child->nodeValue;
+ break;
+
+ case 'array':
+ $value = array();
+
+ $xpath = new DOMXPath($document);
+ $entries = $xpath->query('.//array/data/value', $child);
+
+ for ($i = 0; $i < $entries->length; $i++) {
+ $value[] = $this->parseResponse($entries->item($i)->firstChild, $document);
+ }
+
+ break;
+
+ default:
+ $value = null;
+ }
+
+ return $value;
+ }
+
+ public function clear() {
+ $this->load->language('extension/payment/klarna_invoice');
+
+ $file = DIR_LOGS . 'klarna_invoice.log';
+
+ $handle = fopen($file, 'w+');
+
+ fclose($handle);
+
+ $this->session->data['success'] = $this->language->get('text_success');
+
+ $this->response->redirect($this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true));
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/laybuy.php b/public/admin/controller/extension/payment/laybuy.php
new file mode 100644
index 0000000..5c9cd86
--- /dev/null
+++ b/public/admin/controller/extension/payment/laybuy.php
@@ -0,0 +1,1121 @@
+<?php
+class ControllerExtensionPaymentLaybuy extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->model('setting/setting');
+
+ $this->load->model('extension/payment/laybuy');
+
+ $this->load->language('extension/payment/laybuy');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ unset($this->request->post['laybuy_cron_url'], $this->request->post['laybuy_cron_time']);
+
+ $this->model_setting_setting->editSetting('payment_laybuy', $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));
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true);
+
+ $data['fetch'] = $this->url->link('extension/payment/laybuy/fetch', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true);
+
+ $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true);
+
+ if (isset($this->request->post['payment_laybuys_membership_id'])) {
+ $data['payment_laybuys_membership_id'] = $this->request->post['payment_laybuys_membership_id'];
+ } else {
+ $data['payment_laybuys_membership_id'] = $this->config->get('payment_laybuys_membership_id');
+ }
+
+ if (isset($this->request->post['payment_laybuy_token'])) {
+ $data['payment_laybuy_token'] = $this->request->post['payment_laybuy_token'];
+ } elseif ($this->config->has('payment_laybuy_token')) {
+ $data['payment_laybuy_token'] = $this->config->get('payment_laybuy_token');
+ } else {
+ $data['payment_laybuy_token'] = md5(time());
+ }
+
+ if (isset($this->request->post['payment_laybuy_min_deposit'])) {
+ $data['payment_laybuy_min_deposit'] = $this->request->post['payment_laybuy_min_deposit'];
+ } elseif ($this->config->get('payment_laybuy_min_deposit')) {
+ $data['payment_laybuy_min_deposit'] = $this->config->get('payment_laybuy_min_deposit');
+ } else {
+ $data['payment_laybuy_min_deposit'] = '20';
+ }
+
+ if (isset($this->request->post['payment_laybuy_max_deposit'])) {
+ $data['payment_laybuy_max_deposit'] = $this->request->post['payment_laybuy_max_deposit'];
+ } elseif ($this->config->get('payment_laybuy_max_deposit')) {
+ $data['payment_laybuy_max_deposit'] = $this->config->get('payment_laybuy_max_deposit');
+ } else {
+ $data['payment_laybuy_max_deposit'] = '50';
+ }
+
+ if (isset($this->request->post['payment_laybuy_max_months'])) {
+ $data['payment_laybuy_max_months'] = $this->request->post['payment_laybuy_max_months'];
+ } elseif ($this->config->get('payment_laybuy_max_months')) {
+ $data['payment_laybuy_max_months'] = $this->config->get('payment_laybuy_max_months');
+ } else {
+ $data['payment_laybuy_max_months'] = '3';
+ }
+
+ if (isset($this->request->post['payment_laybuy_category'])) {
+ $data['payment_laybuy_category'] = $this->request->post['payment_laybuy_category'];
+ } elseif ($this->config->get('payment_laybuy_category')) {
+ $data['payment_laybuy_category'] = $this->config->get('payment_laybuy_category');
+ } else {
+ $data['payment_laybuy_category'] = array();
+ }
+
+ $data['categories'] = array();
+
+ $this->load->model('catalog/category');
+
+ foreach ($data['payment_laybuy_category'] as $category_id) {
+ $category_info = $this->model_catalog_category->getCategory($category_id);
+
+ if ($category_info) {
+ $data['categories'][] = array(
+ 'category_id' => $category_info['category_id'],
+ 'name' => ($category_info['path']) ? $category_info['path'] . ' &gt; ' . $category_info['name'] : $category_info['name']
+ );
+ }
+ }
+
+ if (isset($this->request->post['payment_laybuy_xproducts'])) {
+ $data['payment_laybuy_xproducts'] = $this->request->post['payment_laybuy_xproducts'];
+ } else {
+ $data['payment_laybuy_xproducts'] = $this->config->get('payment_laybuy_xproducts');
+ }
+
+ if (isset($this->request->post['payment_laybuy_customer_group'])) {
+ $data['payment_laybuy_customer_group'] = $this->request->post['payment_laybuy_customer_group'];
+ } elseif ($this->config->get('payment_laybuy_customer_group')) {
+ $data['payment_laybuy_customer_group'] = $this->config->get('payment_laybuy_customer_group');
+ } else {
+ $data['payment_laybuy_customer_group'] = array();
+ }
+
+ $data['customer_groups'] = array();
+
+ $this->load->model('customer/customer_group');
+
+ foreach ($data['payment_laybuy_customer_group'] as $customer_group_id) {
+ $customer_group_info = $this->model_customer_customer_group->getCustomerGroup($customer_group_id);
+
+ if ($customer_group_info) {
+ $data['customer_groups'][] = array(
+ 'customer_group_id' => $customer_group_info['customer_group_id'],
+ 'name' => $customer_group_info['name']
+ );
+ }
+ }
+
+ if (isset($this->request->post['payment_laybuy_logging'])) {
+ $data['payment_laybuy_logging'] = $this->request->post['payment_laybuy_logging'];
+ } else {
+ $data['payment_laybuy_logging'] = $this->config->get('payment_laybuy_logging');
+ }
+
+ if (isset($this->request->post['payment_laybuy_total'])) {
+ $data['payment_laybuy_total'] = $this->request->post['payment_laybuy_total'];
+ } else {
+ $data['payment_laybuy_total'] = $this->config->get('payment_laybuy_total');
+ }
+
+ if (isset($this->request->post['payment_laybuy_order_status_id_pending'])) {
+ $data['payment_laybuy_order_status_id_pending'] = $this->request->post['payment_laybuy_order_status_id_pending'];
+ } elseif ($this->config->get('payment_laybuy_order_status_id_pending')) {
+ $data['payment_laybuy_order_status_id_pending'] = $this->config->get('payment_laybuy_order_status_id_pending');
+ } else {
+ $data['payment_laybuy_order_status_id_pending'] = '1';
+ }
+
+ if (isset($this->request->post['payment_laybuy_order_status_id_canceled'])) {
+ $data['payment_laybuy_order_status_id_canceled'] = $this->request->post['payment_laybuy_order_status_id_canceled'];
+ } elseif ($this->config->get('payment_laybuy_order_status_id_canceled')) {
+ $data['payment_laybuy_order_status_id_canceled'] = $this->config->get('payment_laybuy_order_status_id_canceled');
+ } else {
+ $data['payment_laybuy_order_status_id_canceled'] = '7';
+ }
+
+ if (isset($this->request->post['payment_laybuy_order_status_id_processing'])) {
+ $data['payment_laybuy_order_status_id_processing'] = $this->request->post['payment_laybuy_order_status_id_processing'];
+ } elseif ($this->config->get('payment_laybuy_order_status_id_processing')) {
+ $data['payment_laybuy_order_status_id_processing'] = $this->config->get('payment_laybuy_order_status_id_processing');
+ } else {
+ $data['payment_laybuy_order_status_id_processing'] = '2';
+ }
+
+ if (isset($this->request->post['payment_laybuy_gateway_url'])) {
+ $data['payment_laybuy_gateway_url'] = $this->request->post['payment_laybuy_gateway_url'];
+ } elseif ($this->config->get('payment_laybuy_gateway_url')) {
+ $data['payment_laybuy_gateway_url'] = $this->config->get('payment_laybuy_gateway_url');
+ } else {
+ $data['payment_laybuy_gateway_url'] = 'http://lay-buys.com/gateway/';
+ }
+
+ if (isset($this->request->post['payment_laybuy_api_url'])) {
+ $data['payment_laybuy_api_url'] = $this->request->post['payment_laybuy_api_url'];
+ } elseif ($this->config->get('payment_laybuy_api_url')) {
+ $data['payment_laybuy_api_url'] = $this->config->get('payment_laybuy_api_url');
+ } else {
+ $data['payment_laybuy_api_url'] = 'https://lay-buys.com/report/';
+ }
+
+ if (isset($this->request->post['payment_laybuy_geo_zone_id'])) {
+ $data['payment_laybuy_geo_zone_id'] = $this->request->post['payment_laybuy_geo_zone_id'];
+ } else {
+ $data['payment_laybuy_geo_zone_id'] = $this->config->get('payment_laybuy_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_laybuy_status'])) {
+ $data['payment_laybuy_status'] = $this->request->post['payment_laybuy_status'];
+ } else {
+ $data['payment_laybuy_status'] = $this->config->get('payment_laybuy_status');
+ }
+
+ if (isset($this->request->post['payment_laybuy_sort_order'])) {
+ $data['payment_laybuy_sort_order'] = $this->request->post['payment_laybuy_sort_order'];
+ } else {
+ $data['payment_laybuy_sort_order'] = $this->config->get('payment_laybuy_sort_order');
+ }
+
+ $data['laybuy_cron_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/cron&token=' . $data['payment_laybuy_token'];
+
+ if ($this->config->get('laybuy_cron_time')) {
+ $data['laybuy_cron_time'] = date($this->language->get('datetime_format'), strtotime($this->config->get('laybuy_cron_time')));
+ } else {
+ $data['laybuy_cron_time'] = $this->language->get('text_no_cron_time');
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['laybuys_membership_id'])) {
+ $data['error_laybuys_membership_id'] = $this->error['laybuys_membership_id'];
+ } else {
+ $data['error_laybuys_membership_id'] = '';
+ }
+
+ if (isset($this->error['laybuy_token'])) {
+ $data['error_laybuy_token'] = $this->error['laybuy_token'];
+ } else {
+ $data['error_laybuy_token'] = '';
+ }
+
+ if (isset($this->error['laybuy_min_deposit'])) {
+ $data['error_laybuy_min_deposit'] = $this->error['laybuy_min_deposit'];
+ } else {
+ $data['error_laybuy_min_deposit'] = '';
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ /* Reports tab */
+ if (isset($this->request->get['filter_order_id'])) {
+ $filter_order_id = $this->request->get['filter_order_id'];
+ } else {
+ $filter_order_id = '';
+ }
+
+ if (isset($this->request->get['filter_customer'])) {
+ $filter_customer = $this->request->get['filter_customer'];
+ } else {
+ $filter_customer = '';
+ }
+
+ if (isset($this->request->get['filter_dp_percent'])) {
+ $filter_dp_percent = $this->request->get['filter_dp_percent'];
+ } else {
+ $filter_dp_percent = '';
+ }
+
+ if (isset($this->request->get['filter_months'])) {
+ $filter_months = $this->request->get['filter_months'];
+ } else {
+ $filter_months = '';
+ }
+
+ if (isset($this->request->get['filter_status'])) {
+ $filter_status = $this->request->get['filter_status'];
+ } else {
+ $filter_status = '';
+ }
+
+ if (isset($this->request->get['filter_date_added'])) {
+ $filter_date_added = $this->request->get['filter_date_added'];
+ } else {
+ $filter_date_added = '';
+ }
+
+ if (isset($this->request->get['sort'])) {
+ $sort = $this->request->get['sort'];
+ } else {
+ $sort = 'lt.order_id';
+ }
+
+ if (isset($this->request->get['order'])) {
+ $order = $this->request->get['order'];
+ } else {
+ $order = 'DESC';
+ }
+
+ if (isset($this->request->get['page'])) {
+ $page = $this->request->get['page'];
+ } else {
+ $page = 1;
+ }
+
+ $data['reports'] = array();
+
+ $filter_data = array(
+ 'filter_order_id' => $filter_order_id,
+ 'filter_customer' => $filter_customer,
+ 'filter_dp_percent' => $filter_dp_percent,
+ 'filter_months' => $filter_months,
+ 'filter_status' => $filter_status,
+ 'filter_date_added' => $filter_date_added,
+ 'sort' => $sort,
+ 'order' => $order,
+ 'start' => ($page - 1) * $this->config->get('config_limit_admin'),
+ 'limit' => $this->config->get('config_limit_admin')
+ );
+
+ $report_total = $this->model_extension_payment_laybuy->getTotalTransactions($filter_data);
+
+ $results = $this->model_extension_payment_laybuy->getTransactions($filter_data);
+
+ foreach ($results as $result) {
+ $customer_url = false;
+
+ $customer_id = $this->model_extension_payment_laybuy->getCustomerIdByOrderId($result['order_id']);
+
+ if ($customer_id) {
+ $customer_url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . (int)$customer_id, true);
+ }
+
+ $data['reports'][] = array(
+ 'id' => $result['laybuy_transaction_id'],
+ 'order_id' => $result['order_id'],
+ 'order_url' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$result['order_id'], true),
+ 'customer_name' => $result['firstname'] . ' ' . $result['lastname'],
+ 'customer_url' => $customer_url,
+ 'amount' => $this->currency->format($result['amount'], $result['currency']),
+ 'dp_percent' => $result['downpayment'],
+ 'months' => $result['months'],
+ 'dp_amount' => $this->currency->format($result['downpayment_amount'], $result['currency']),
+ 'first_payment' => date($this->language->get('date_format_short'), strtotime($result['first_payment_due'])),
+ 'last_payment' => date($this->language->get('date_format_short'), strtotime($result['last_payment_due'])),
+ 'status' => $this->model_extension_payment_laybuy->getStatusLabel($result['status']),
+ 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
+ 'view' => $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . (int)$result['laybuy_transaction_id'], true)
+ );
+ }
+
+ if (isset($this->request->post['selected'])) {
+ $data['selected'] = (array)$this->request->post['selected'];
+ } else {
+ $data['selected'] = array();
+ }
+
+ $url = '';
+
+ if (isset($this->request->get['filter_order_id'])) {
+ $url .= '&filter_order_id=' . urlencode(html_entity_decode($this->request->get['filter_order_id'], ENT_QUOTES, 'UTF-8'));
+ }
+
+ if (isset($this->request->get['filter_customer'])) {
+ $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
+ }
+
+ if (isset($this->request->get['filter_dp_percent'])) {
+ $url .= '&filter_dp_percent=' . urlencode(html_entity_decode($this->request->get['filter_dp_percent'], ENT_QUOTES, 'UTF-8'));
+ }
+
+ if (isset($this->request->get['filter_months'])) {
+ $url .= '&filter_months=' . $this->request->get['filter_months'];
+ }
+
+ if (isset($this->request->get['filter_status'])) {
+ $url .= '&filter_status=' . $this->request->get['filter_status'];
+ }
+
+ if (isset($this->request->get['filter_date_added'])) {
+ $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
+ }
+
+ if ($order == 'ASC') {
+ $url .= '&order=DESC';
+ } else {
+ $url .= '&order=ASC';
+ }
+
+ if (isset($this->request->get['page'])) {
+ $url .= '&page=' . $this->request->get['page'];
+ }
+
+ $data['sort_order_id'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.order_id' . $url . '#reportstab', true);
+ $data['sort_customer'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url . '#reportstab', true);
+ $data['sort_amount'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.amount' . $url . '#reportstab', true);
+ $data['sort_dp_percent'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.downpayment' . $url . '#reportstab', true);
+ $data['sort_months'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.months' . $url . '#reportstab', true);
+ $data['sort_dp_amount'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.downpayment_amount' . $url . '#reportstab', true);
+ $data['sort_first_payment'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.first_payment_due' . $url . '#reportstab', true);
+ $data['sort_last_payment'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.last_payment_due' . $url . '#reportstab', true);
+ $data['sort_status'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.status' . $url . '#reportstab', true);
+ $data['sort_date_added'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.date_added' . $url . '#reportstab', true);
+
+ $url = '';
+
+ if (isset($this->request->get['filter_order_id'])) {
+ $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
+ }
+
+ if (isset($this->request->get['filter_customer'])) {
+ $url .= '&filter_customer=' . $this->request->get['filter_customer'];
+ }
+
+ if (isset($this->request->get['filter_dp_percent'])) {
+ $url .= '&filter_dp_percent=' . $this->request->get['filter_dp_percent'];
+ }
+
+ if (isset($this->request->get['filter_months'])) {
+ $url .= '&filter_months=' . $this->request->get['filter_months'];
+ }
+
+ if (isset($this->request->get['filter_status'])) {
+ $url .= '&filter_status=' . $this->request->get['filter_status'];
+ }
+
+ if (isset($this->request->get['filter_date_added'])) {
+ $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
+ }
+
+ if (isset($this->request->get['sort'])) {
+ $url .= '&sort=' . $this->request->get['sort'];
+ }
+
+ if (isset($this->request->get['order'])) {
+ $url .= '&order=' . $this->request->get['order'];
+ }
+
+ $pagination = new Pagination();
+ $pagination->total = $report_total;
+ $pagination->page = $page;
+ $pagination->limit = $this->config->get('config_limit_admin');
+ $pagination->url = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}#reportstab', true);
+
+ $data['pagination'] = $pagination->render();
+
+ $data['results'] = sprintf($this->language->get('text_pagination'), ($report_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($report_total - $this->config->get('config_limit_admin'))) ? $report_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $report_total, ceil($report_total / $this->config->get('config_limit_admin')));
+
+ $data['filter_order_id'] = $filter_order_id;
+ $data['filter_customer'] = $filter_customer;
+ $data['filter_dp_percent'] = $filter_dp_percent;
+ $data['filter_months'] = $filter_months;
+ $data['filter_status'] = $filter_status;
+ $data['filter_date_added'] = $filter_date_added;
+
+ $data['sort'] = $sort;
+ $data['order'] = $order;
+
+ $data['transaction_statuses'] = $this->model_extension_payment_laybuy->getTransactionStatuses();
+ /* End of Reports Tab */
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->session->data['success'])) {
+ $data['success'] = $this->session->data['success'];
+
+ unset($this->session->data['success']);
+ } else {
+ $data['success'] = '';
+ }
+
+ $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/laybuy', $data));
+ }
+
+ public function fetch() {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->model_extension_payment_laybuy->log('Fetching transactions');
+
+ if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) {
+ $this->load->language('extension/payment/laybuy');
+
+ $json = array();
+
+ $fetched = 0;
+
+ $paypal_profile_id_array = $this->model_extension_payment_laybuy->getPayPalProfileIds();
+
+ if ($paypal_profile_id_array) {
+ $paypal_profile_ids = '';
+
+ foreach ($paypal_profile_id_array as $profile_id) {
+ $paypal_profile_ids .= $profile_id['paypal_profile_id'] . ',';
+ }
+
+ $paypal_profile_ids = rtrim($paypal_profile_ids, ',');
+
+ $data_string = 'mid=' . $this->config->get('payment_laybuys_membership_id') . '&' . 'profileIds=' . $paypal_profile_ids;
+
+ $this->model_extension_payment_laybuy->log('Data String: ' . $data_string);
+
+ $this->model_extension_payment_laybuy->log('API URL: ' . $this->config->get('payment_laybuy_api_url'));
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->config->get('payment_laybuy_api_url'));
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HEADER, false);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ $result = curl_exec($ch);
+ if (curl_errno($ch)) {
+ $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch));
+ }
+ curl_close($ch);
+
+ $results = json_decode($result, true);
+
+ $this->model_extension_payment_laybuy->log('Response: ' . print_r($results, true));
+
+ if ($results) {
+ foreach ($results as $laybuy_ref_id => $reports) {
+ $status = $reports['status'];
+
+ $report = $reports['report'];
+
+ $transaction = array();
+
+ $transaction = $this->model_extension_payment_laybuy->getTransactionByLayBuyRefId($laybuy_ref_id);
+
+ $order_id = $transaction['order_id'];
+
+ $paypal_profile_id = $transaction['paypal_profile_id'];
+
+ $months = $transaction['months'];
+
+ $report_content = array();
+
+ $pending_flag = false;
+
+ $next_payment_status = $this->language->get('text_status_1');
+
+ foreach ($report as $month => $payment) {
+ $payment['paymentDate'] = date('Y-m-d h:i:s', strtotime(str_replace('/', '-', $payment['paymentDate'])));
+ $date = date($this->language->get('date_format_short'), strtotime($payment['paymentDate']));
+ $next_payment_date = $payment['paymentDate'];
+
+ if ($payment['type'] == 'd') {
+ $report_content[] = array(
+ 'instalment' => 0,
+ 'amount' => $this->currency->format($payment['amount'], $transaction['currency']),
+ 'date' => $date,
+ 'pp_trans_id' => $payment['txnID'],
+ 'status' => $payment['paymentStatus']
+ );
+ } elseif ($payment['type'] == 'p') {
+ $pending_flag = true;
+
+ $report_content[] = array(
+ 'instalment' => $month,
+ 'amount' => $this->currency->format($payment['amount'], $transaction['currency']),
+ 'date' => $date,
+ 'pp_trans_id' => $payment['txnID'],
+ 'status' => $payment['paymentStatus']
+ );
+
+ $next_payment_status = $payment['paymentStatus'];
+ }
+ }
+
+ if ($pending_flag) {
+ $start_index = $month + 1;
+ } else {
+ $start_index = $month + 2;
+ }
+
+ if ($month < $months) {
+ for ($month = 1; $month <= $months; $month++) {
+ $next_payment_date = date("Y-m-d h:i:s", strtotime($next_payment_date . " +1 month"));
+ $date = date($this->language->get('date_format_short'), strtotime($next_payment_date));
+
+ $report_content[] = array(
+ 'instalment' => $month,
+ 'amount' => $this->currency->format($transaction['payment_amounts'], $transaction['currency']),
+ 'date' => $date,
+ 'pp_trans_id' => '',
+ 'status' => $next_payment_status
+ );
+ }
+ }
+
+ $report_content = json_encode($report_content);
+
+ switch ($status) {
+ case -1: // Cancel
+ $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' canceled');
+ $this->model_extension_payment_laybuy->updateOrderStatus($order_id, $this->config->get('payment_laybuy_order_status_id_canceled'), $this->language->get('text_comment'));
+ $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], '7', $report_content, $start_index);
+ $fetched++;
+ break;
+ case 0: // Pending
+ $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' still pending');
+ $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], $transaction['status'], $report_content, $start_index);
+ $fetched++;
+ break;
+ case 1: // Paid
+ $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' paid');
+ $this->model_extension_payment_laybuy->updateOrderStatus($order_id, $this->config->get('payment_laybuy_order_status_id_processing'), $this->language->get('text_comment'));
+ $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], '5', $report_content, $start_index);
+ $fetched++;
+ break;
+ }
+ }
+ }
+
+ if ($fetched) {
+ $this->session->data['success'] = sprintf($this->language->get('text_fetched_some'), $fetched);
+ } else {
+ $this->session->data['success'] = $this->language->get('text_fetched_none');
+ }
+
+ $this->response->redirect($this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true));
+ } else {
+ $this->model_extension_payment_laybuy->log('No PayPal Profile IDs to update');
+
+ $this->session->data['success'] = $this->language->get('text_fetched_none');
+
+ $this->response->redirect($this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true));
+ }
+ } else {
+ $this->model_extension_payment_laybuy->log('User does not have permission');
+ }
+ }
+
+ public function install() {
+ if ($this->user->hasPermission('modify', 'marketplace/extension')) {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->model_extension_payment_laybuy->install();
+ }
+ }
+
+ public function uninstall() {
+ if ($this->user->hasPermission('modify', 'marketplace/extension')) {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->model_extension_payment_laybuy->uninstall();
+ }
+ }
+
+ public function transaction($order_page = false) {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->load->language('extension/payment/laybuy');
+
+ if (isset($this->request->get['id'])) {
+ $id = (int)$this->request->get['id'];
+ } else {
+ $id = 0;
+ }
+
+ $data['id'] = $id;
+
+ if (!$order_page) {
+ $this->document->setTitle($this->language->get('heading_transaction_title'));
+ }
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_extension'),
+ 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_transaction_title'),
+ 'href' => $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true)
+ );
+
+ $data['heading_title'] = $this->language->get('heading_transaction_title');
+
+ $data['button_cancel'] = $this->language->get('button_cancel');
+
+ $data['cancel'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true);
+
+ $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id);
+
+ if ($transaction_info) {
+ $data['initial_payments'] = $this->model_extension_payment_laybuy->getInitialPayments();
+
+ $data['months'] = $this->model_extension_payment_laybuy->getMonths();
+
+ $data['currency_symbol_left'] = $this->currency->getSymbolLeft($transaction_info['currency']);
+
+ $data['currency_symbol_right'] = $this->currency->getSymbolRight($transaction_info['currency']);
+
+ $data['store_url'] = HTTPS_CATALOG;
+
+ $data['api_key'] = $this->getApiKey();
+
+ $this->load->model('sale/order');
+
+ $order = $this->model_sale_order->getOrder($transaction_info['order_id']);
+
+ $data['order_info'] = array(
+ 'currency_value' => $order['currency_value']
+ );
+
+ $data['total'] = $this->model_extension_payment_laybuy->getRemainingAmount($transaction_info['amount'], $transaction_info['downpayment_amount'], $transaction_info['payment_amounts'], $transaction_info['transaction']);
+
+ $data['transaction'] = array(
+ 'paypal_profile_id' => $transaction_info['paypal_profile_id'],
+ 'laybuy_ref_no' => $transaction_info['laybuy_ref_no'],
+ 'order_id' => $transaction_info['order_id'],
+ 'firstname' => $transaction_info['firstname'],
+ 'lastname' => $transaction_info['lastname'],
+ 'email' => $transaction_info['email'],
+ 'address' => $transaction_info['address'],
+ 'suburb' => $transaction_info['suburb'],
+ 'state' => $transaction_info['state'],
+ 'country' => $transaction_info['country'],
+ 'postcode' => $transaction_info['postcode'],
+ 'status_id' => $transaction_info['status'],
+ 'status' => $this->model_extension_payment_laybuy->getStatusLabel($transaction_info['status']),
+ 'amount' => $this->currency->format($transaction_info['amount'], $transaction_info['currency']),
+ 'remaining' => $this->currency->format($this->model_extension_payment_laybuy->getRemainingAmount($transaction_info['amount'], $transaction_info['downpayment_amount'], $transaction_info['payment_amounts'], $transaction_info['transaction']), $transaction_info['currency']),
+ 'downpayment' => $transaction_info['downpayment'],
+ 'months' => $transaction_info['months'],
+ 'downpayment_amount' => $this->currency->format($transaction_info['downpayment_amount'], $transaction_info['currency']),
+ 'payment_amounts' => $this->currency->format($transaction_info['payment_amounts'], $transaction_info['currency']),
+ 'first_payment_due' => date($this->language->get('date_format_short'), strtotime($transaction_info['first_payment_due'])),
+ 'last_payment_due' => date($this->language->get('date_format_short'), strtotime($transaction_info['last_payment_due'])),
+ 'report' => json_decode($transaction_info['report'], true)
+ );
+ } else {
+ $data['transaction'] = array();
+
+ $data['text_not_found'] = $this->language->get('text_not_found');
+ }
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ if (isset($this->session->data['success'])) {
+ $data['success'] = $this->session->data['success'];
+
+ unset($this->session->data['success']);
+ } else {
+ $data['success'] = '';
+ }
+
+ if (isset($this->session->data['error_warning'])) {
+ $data['error_warning'] = $this->session->data['error_warning'];
+
+ unset($this->session->data['error_warning']);
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ $data['header'] = $this->load->controller('common/header');
+ $data['column_left'] = $this->load->controller('common/column_left');
+ $data['footer'] = $this->load->controller('common/footer');
+
+ if ($order_page) {
+ return $data;
+ }
+
+ $this->response->setOutput($this->load->view('extension/payment/laybuy_transaction', $data));
+ }
+
+ public function cancel() {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->model_extension_payment_laybuy->log('Canceling transaction');
+
+ if ($this->request->get['source'] == 'order') {
+ $this->model_extension_payment_laybuy->log('Called from order page');
+ } else {
+ $this->model_extension_payment_laybuy->log('Called from extension page');
+ }
+
+ if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) {
+ $this->load->language('extension/payment/laybuy');
+
+ $json = array();
+
+ $id = (int)$this->request->get['id'];
+
+ $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id);
+
+ $cancel = false;
+
+ if (!$transaction_info['paypal_profile_id']) {
+ $this->model_extension_payment_laybuy->log('Transaction has no paypal_profile_id');
+
+ $cancel = true;
+ }
+
+ if (!$cancel) {
+ $data_string = 'mid=' . $this->config->get('payment_laybuys_membership_id') . '&' . 'paypal_profile_id=' . $transaction_info['paypal_profile_id'];
+
+ $this->model_extension_payment_laybuy->log('Data String: ' . $data_string);
+
+ $ch = curl_init();
+ $url = 'https://lay-buys.com/vtmob/deal5cancel.php';
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HEADER, false);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ $result = curl_exec($ch);
+ if (curl_errno($ch)) {
+ $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch));
+ }
+ curl_close($ch);
+
+ $this->model_extension_payment_laybuy->log('Response: ' . $result);
+
+ if ($result == 'success') {
+ $this->model_extension_payment_laybuy->log('Success');
+
+ $cancel = true;
+ } else {
+ $this->model_extension_payment_laybuy->log('Failure');
+ }
+ }
+
+ if ($cancel) {
+ $this->model_extension_payment_laybuy->log('Transaction canceled');
+
+ $report_content = json_decode($transaction_info['report'], true);
+
+ foreach ($report_content as &$array) {
+ $array['status'] = str_replace('Pending', 'Canceled', $array['status']);
+ }
+
+ $report_content = json_encode($report_content);
+
+ $this->model_extension_payment_laybuy->updateTransaction($transaction_info['laybuy_transaction_id'], '7', $report_content, $transaction_info['transaction']);
+
+ $json['success'] = $this->language->get('text_cancel_success');
+
+ $json['order_id'] = $transaction_info['order_id'];
+
+ $json['order_status_id'] = $this->config->get('payment_laybuy_order_status_id_canceled');
+
+ $json['comment'] = sprintf($this->language->get('text_comment_canceled'), $transaction_info['paypal_profile_id']);
+ } else {
+ $json['error'] = $this->language->get('text_cancel_failure');
+ }
+
+ if ($this->request->get['source'] == 'order') {
+ $json['reload'] = $this->url->link('sale/order/info', 'order_id=' . (int)$transaction_info['order_id'] . '&user_token=' . $this->session->data['user_token'], true);
+ } else {
+ $json['reload'] = $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true);
+ }
+
+ $this->response->setOutput(json_encode($json));
+ } else {
+ $this->model_extension_payment_laybuy->log('User does not have permission');
+ }
+ }
+
+ public function revise() {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->model_extension_payment_laybuy->log('Revising transaction');
+
+ if ($this->request->get['source'] == 'order') {
+ $this->model_extension_payment_laybuy->log('Called from order page');
+ } else {
+ $this->model_extension_payment_laybuy->log('Called from extension page');
+ }
+
+ if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) {
+ if ($this->request->server['REQUEST_METHOD'] == 'POST') {
+ $this->load->language('extension/payment/laybuy');
+
+ $json = array();
+
+ $payment_type = $this->request->post['payment_type'];
+
+ $amount = $this->request->post['amount'];
+
+ $initial = $this->request->post['INIT'];
+
+ $months = $this->request->post['MONTHS'];
+
+ $id = $this->request->get['id'];
+
+ $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id);
+
+ $original = $new = $transaction_info;
+
+ $original['transaction_id'] = $new['transaction_id'] = $transaction_info['laybuy_transaction_id'];
+
+ $original['payment_type'] = $new['payment_type'] = $payment_type;
+
+ $original['type'] = 'Original';
+
+ $new['type'] = 'New';
+ $new['status'] = '50';
+ $new['amount'] = $amount;
+ $new['downpayment'] = $initial;
+ $new['months'] = $months;
+
+ $collection = $this->model_extension_payment_laybuy->getRevisedTransactions($id);
+
+ $this->model_extension_payment_laybuy->log('Collection: ' . print_r($collection, true));
+
+ if (count($collection) == 2) {
+ $this->model_extension_payment_laybuy->log('Collection == 2');
+
+ foreach ($collection as $request) {
+ $this->model_extension_payment_laybuy->log('request: ' . print_r($request, true));
+
+ if ($request['type'] == 'Original') {
+ $this->model_extension_payment_laybuy->log('Original: ' . print_r($original, true));
+
+ $this->model_extension_payment_laybuy->updateRevisedTransaction($id, $original);
+ } elseif ($request['type'] == 'New') {
+ $this->model_extension_payment_laybuy->log('New: ' . print_r($new, true));
+
+ $this->model_extension_payment_laybuy->updateRevisedTransaction($id, $new);
+
+ $revised_transaction = $this->model_extension_payment_laybuy->getRevisedTransaction($id);
+ }
+ }
+ } else {
+ $this->model_extension_payment_laybuy->log('Collection != 2');
+
+ $this->model_extension_payment_laybuy->addRevisedTransaction($original);
+
+ $laybuy_revise_request_id = $this->model_extension_payment_laybuy->addRevisedTransaction($new);
+
+ $this->model_extension_payment_laybuy->log('$laybuy_revise_request_id: ' . $laybuy_revise_request_id);
+
+ $revised_transaction = $this->model_extension_payment_laybuy->getRevisedTransaction($laybuy_revise_request_id);
+ }
+
+ $this->model_extension_payment_laybuy->log('Revised transaction: ' . print_r($revised_transaction, true));
+
+ if ($revised_transaction['payment_type'] == '1') {
+ $pp = '1';
+ $pplan = '1';
+ } else {
+ $pp = '0';
+ $pplan = '0';
+ }
+
+ $data = array();
+
+ $data['mid'] = $this->config->get('payment_laybuys_membership_id');
+ $data['eml'] = $revised_transaction['email'];
+ $data['prc'] = $revised_transaction['amount'];
+ $data['curr'] = $revised_transaction['currency'];
+ $data['pp'] = $pp;
+ $data['pplan'] = $pplan;
+ $data['init'] = $initial;
+ $data['mnth'] = $months;
+ $data['convrate'] = '1';
+ $data['id'] = $revised_transaction['laybuy_revise_request_id'] . '-' . $revised_transaction['order_id'] . ':' . md5($this->config->get('payment_laybuy_token'));
+ $data['RETURNURL'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/reviseCallback';
+ $data['CANCELURL'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/reviseCancel';
+
+ $data_string = '';
+
+ foreach ($data as $param => $value) {
+ $data_string .= $param . '=' . $value . '&';
+ }
+
+ $data_string = rtrim($data_string, '&');
+
+ $this->model_extension_payment_laybuy->log('Data String: ' . $data_string);
+
+ $ch = curl_init();
+ $url = 'https://lay-buys.com/vtmob/deal5.php';
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HEADER, false);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ $result = curl_exec($ch);
+ if (curl_errno($ch)) {
+ $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch));
+ }
+ curl_close($ch);
+
+ if ($result == 'success') {
+ $this->model_extension_payment_laybuy->log('Success');
+
+ $this->model_extension_payment_laybuy->updateTransactionStatus($id, '50');
+
+ $json['success'] = $this->language->get('text_revise_success');
+ } else {
+ $this->model_extension_payment_laybuy->log('Failure');
+
+ $this->model_extension_payment_laybuy->log('Response: ' . print_r($result, true));
+
+ $json['error'] = $this->language->get('text_revise_failure');
+ }
+
+ if ($this->request->get['source'] == 'order') {
+ $json['reload'] = $this->url->link('sale/order/info', 'order_id=' . (int)$transaction_info['order_id'] . '&user_token=' . $this->session->data['user_token'], true);
+ } else {
+ $json['reload'] = $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true);
+ }
+
+ $this->response->setOutput(json_encode($json));
+ } else {
+ $this->model_extension_payment_laybuy->log('No $_POST data');
+ }
+ } else {
+ $this->model_extension_payment_laybuy->log('User does not have permission');
+ }
+ }
+
+ public function autocomplete() {
+ $json = array();
+
+ if (isset($this->request->get['filter_customer_group'])) {
+ $this->load->model('customer/customer_group');
+
+ $results = $this->model_customer_customer_group->getCustomerGroups();
+
+ foreach ($results as $result) {
+ $json[] = array(
+ 'customer_group_id' => $result['customer_group_id'],
+ 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
+ );
+ }
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function order() {
+ if ($this->config->get('payment_laybuy_status')) {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->load->language('extension/payment/laybuy');
+
+ $order_id = $this->request->get['order_id'];
+
+ $transaction_info = $this->model_extension_payment_laybuy->getTransactionByOrderId($order_id);
+
+ $laybuy_transaction_id = $transaction_info['laybuy_transaction_id'];
+
+ $this->request->get['id'] = $laybuy_transaction_id;
+
+ $data = $this->transaction(true);
+
+ $data['store_url'] = HTTPS_CATALOG;
+
+ $data['api_key'] = $this->getApiKey();
+
+ return $this->load->view('extension/payment/laybuy_order', $data);
+ }
+ }
+
+ private function getApiKey() {
+ $this->load->model('extension/payment/laybuy');
+
+ $this->model_extension_payment_laybuy->log('Getting API key');
+
+ $this->load->model('user/api');
+
+ $api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
+
+ if ($api_info) {
+ $this->model_extension_payment_laybuy->log('API key: ' . $api_info['key']);
+
+ return $api_info['key'];
+ } else {
+ $this->model_extension_payment_laybuy->log('No API info');
+
+ return;
+ }
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/laybuy')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_laybuys_membership_id']) {
+ $this->error['laybuys_membership_id'] = $this->language->get('error_membership_id');
+ }
+
+ if (!$this->request->post['payment_laybuy_token']) {
+ $this->error['laybuy_token'] = $this->language->get('error_token');
+ }
+
+ if ($this->request->post['payment_laybuy_min_deposit'] > $this->request->post['payment_laybuy_max_deposit']) {
+ $this->error['laybuy_min_deposit'] = $this->language->get('error_min_deposit');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/liqpay.php b/public/admin/controller/extension/payment/liqpay.php
new file mode 100644
index 0000000..7f0841c
--- /dev/null
+++ b/public/admin/controller/extension/payment/liqpay.php
@@ -0,0 +1,143 @@
+<?php
+class ControllerExtensionPaymentLiqPay extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/liqpay');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_liqpay', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['merchant'])) {
+ $data['error_merchant'] = $this->error['merchant'];
+ } else {
+ $data['error_merchant'] = '';
+ }
+
+ if (isset($this->error['signature'])) {
+ $data['error_signature'] = $this->error['signature'];
+ } else {
+ $data['error_signature'] = '';
+ }
+
+ if (isset($this->error['type'])) {
+ $data['error_type'] = $this->error['type'];
+ } else {
+ $data['error_type'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/liqpay', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/liqpay', '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_liqpay_merchant'])) {
+ $data['payment_liqpay_merchant'] = $this->request->post['payment_liqpay_merchant'];
+ } else {
+ $data['payment_liqpay_merchant'] = $this->config->get('payment_liqpay_merchant');
+ }
+
+ if (isset($this->request->post['payment_liqpay_signature'])) {
+ $data['payment_liqpay_signature'] = $this->request->post['payment_liqpay_signature'];
+ } else {
+ $data['payment_liqpay_signature'] = $this->config->get('payment_liqpay_signature');
+ }
+
+ if (isset($this->request->post['payment_liqpay_type'])) {
+ $data['payment_liqpay_type'] = $this->request->post['payment_liqpay_type'];
+ } else {
+ $data['payment_liqpay_type'] = $this->config->get('payment_liqpay_type');
+ }
+
+ if (isset($this->request->post['payment_liqpay_total'])) {
+ $data['payment_liqpay_total'] = $this->request->post['payment_liqpay_total'];
+ } else {
+ $data['payment_liqpay_total'] = $this->config->get('payment_liqpay_total');
+ }
+
+ if (isset($this->request->post['payment_liqpay_order_status_id'])) {
+ $data['payment_liqpay_order_status_id'] = $this->request->post['payment_liqpay_order_status_id'];
+ } else {
+ $data['payment_liqpay_order_status_id'] = $this->config->get('payment_liqpay_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_liqpay_geo_zone_id'])) {
+ $data['payment_liqpay_geo_zone_id'] = $this->request->post['payment_liqpay_geo_zone_id'];
+ } else {
+ $data['payment_liqpay_geo_zone_id'] = $this->config->get('payment_liqpay_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_liqpay_status'])) {
+ $data['payment_liqpay_status'] = $this->request->post['payment_liqpay_status'];
+ } else {
+ $data['payment_liqpay_status'] = $this->config->get('payment_liqpay_status');
+ }
+
+ if (isset($this->request->post['payment_liqpay_sort_order'])) {
+ $data['payment_liqpay_sort_order'] = $this->request->post['payment_liqpay_sort_order'];
+ } else {
+ $data['payment_liqpay_sort_order'] = $this->config->get('payment_liqpay_sort_order');
+ }
+
+ $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/liqpay', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/liqpay')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_liqpay_merchant']) {
+ $this->error['merchant'] = $this->language->get('error_merchant');
+ }
+
+ if (!$this->request->post['payment_liqpay_signature']) {
+ $this->error['signature'] = $this->language->get('error_signature');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/nochex.php b/public/admin/controller/extension/payment/nochex.php
new file mode 100644
index 0000000..08e0413
--- /dev/null
+++ b/public/admin/controller/extension/payment/nochex.php
@@ -0,0 +1,149 @@
+<?php
+class ControllerExtensionPaymentNOCHEX extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/nochex');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_nochex', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['email'])) {
+ $data['error_email'] = $this->error['email'];
+ } else {
+ $data['error_email'] = '';
+ }
+
+ if (isset($this->error['merchant'])) {
+ $data['error_merchant'] = $this->error['merchant'];
+ } else {
+ $data['error_merchant'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/nochex', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/nochex', '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_nochex_email'])) {
+ $data['payment_nochex_email'] = $this->request->post['payment_nochex_email'];
+ } else {
+ $data['payment_nochex_email'] = $this->config->get('payment_nochex_email');
+ }
+
+ if (isset($this->request->post['payment_nochex_account'])) {
+ $data['payment_nochex_account'] = $this->request->post['payment_nochex_account'];
+ } else {
+ $data['payment_nochex_account'] = $this->config->get('payment_nochex_account');
+ }
+
+ if (isset($this->request->post['payment_nochex_merchant'])) {
+ $data['payment_nochex_merchant'] = $this->request->post['payment_nochex_merchant'];
+ } else {
+ $data['payment_nochex_merchant'] = $this->config->get('payment_nochex_merchant');
+ }
+
+ if (isset($this->request->post['payment_nochex_template'])) {
+ $data['payment_nochex_template'] = $this->request->post['payment_nochex_template'];
+ } else {
+ $data['payment_nochex_template'] = $this->config->get('payment_nochex_template');
+ }
+
+ if (isset($this->request->post['payment_nochex_test'])) {
+ $data['payment_nochex_test'] = $this->request->post['payment_nochex_test'];
+ } else {
+ $data['payment_nochex_test'] = $this->config->get('payment_nochex_test');
+ }
+
+ if (isset($this->request->post['payment_nochex_total'])) {
+ $data['payment_nochex_total'] = $this->request->post['payment_nochex_total'];
+ } else {
+ $data['payment_nochex_total'] = $this->config->get('payment_nochex_total');
+ }
+
+ if (isset($this->request->post['payment_nochex_order_status_id'])) {
+ $data['payment_nochex_order_status_id'] = $this->request->post['payment_nochex_order_status_id'];
+ } else {
+ $data['payment_nochex_order_status_id'] = $this->config->get('payment_nochex_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_nochex_geo_zone_id'])) {
+ $data['payment_nochex_geo_zone_id'] = $this->request->post['payment_nochex_geo_zone_id'];
+ } else {
+ $data['payment_nochex_geo_zone_id'] = $this->config->get('payment_nochex_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_nochex_status'])) {
+ $data['payment_nochex_status'] = $this->request->post['payment_nochex_status'];
+ } else {
+ $data['payment_nochex_status'] = $this->config->get('payment_nochex_status');
+ }
+
+ if (isset($this->request->post['payment_nochex_sort_order'])) {
+ $data['payment_nochex_sort_order'] = $this->request->post['payment_nochex_sort_order'];
+ } else {
+ $data['payment_nochex_sort_order'] = $this->config->get('payment_nochex_sort_order');
+ }
+
+ $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/nochex', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/nochex')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_nochex_email']) {
+ $this->error['email'] = $this->language->get('error_email');
+ }
+
+ if (!$this->request->post['payment_nochex_merchant']) {
+ $this->error['merchant'] = $this->language->get('error_merchant');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/paymate.php b/public/admin/controller/extension/payment/paymate.php
new file mode 100644
index 0000000..4552e76
--- /dev/null
+++ b/public/admin/controller/extension/payment/paymate.php
@@ -0,0 +1,139 @@
+<?php
+class ControllerExtensionPaymentPayMate extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/paymate');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_paymate', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['username'])) {
+ $data['error_username'] = $this->error['username'];
+ } else {
+ $data['error_username'] = '';
+ }
+
+ if (isset($this->error['password'])) {
+ $data['error_password'] = $this->error['password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/paymate', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/paymate', '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_paymate_username'])) {
+ $data['payment_paymate_username'] = $this->request->post['payment_paymate_username'];
+ } else {
+ $data['payment_paymate_username'] = $this->config->get('payment_paymate_username');
+ }
+
+ if (isset($this->request->post['payment_paymate_password'])) {
+ $data['payment_paymate_username'] = $this->request->post['payment_paymate_password'];
+ } elseif ($this->config->get('payment_paymate_password')) {
+ $data['payment_paymate_password'] = $this->config->get('payment_paymate_password');
+ } else {
+ $data['payment_paymate_password'] = token(32);
+ }
+
+ if (isset($this->request->post['payment_paymate_test'])) {
+ $data['payment_paymate_test'] = $this->request->post['payment_paymate_test'];
+ } else {
+ $data['payment_paymate_test'] = $this->config->get('payment_paymate_test');
+ }
+
+ if (isset($this->request->post['payment_paymate_total'])) {
+ $data['payment_paymate_total'] = $this->request->post['payment_paymate_total'];
+ } else {
+ $data['payment_paymate_total'] = $this->config->get('payment_paymate_total');
+ }
+
+ if (isset($this->request->post['payment_paymate_order_status_id'])) {
+ $data['payment_paymate_order_status_id'] = $this->request->post['payment_paymate_order_status_id'];
+ } else {
+ $data['payment_paymate_order_status_id'] = $this->config->get('payment_paymate_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_paymate_geo_zone_id'])) {
+ $data['payment_paymate_geo_zone_id'] = $this->request->post['payment_paymate_geo_zone_id'];
+ } else {
+ $data['payment_paymate_geo_zone_id'] = $this->config->get('payment_paymate_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_paymate_status'])) {
+ $data['payment_paymate_status'] = $this->request->post['payment_paymate_status'];
+ } else {
+ $data['payment_paymate_status'] = $this->config->get('payment_paymate_status');
+ }
+
+ if (isset($this->request->post['payment_paymate_sort_order'])) {
+ $data['payment_paymate_sort_order'] = $this->request->post['payment_paymate_sort_order'];
+ } else {
+ $data['payment_paymate_sort_order'] = $this->config->get('payment_paymate_sort_order');
+ }
+
+ $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/paymate', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/paymate')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_paymate_username']) {
+ $this->error['username'] = $this->language->get('error_username');
+ }
+
+ if (!$this->request->post['payment_paymate_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/paypoint.php b/public/admin/controller/extension/payment/paypoint.php
new file mode 100644
index 0000000..c4948a2
--- /dev/null
+++ b/public/admin/controller/extension/payment/paypoint.php
@@ -0,0 +1,127 @@
+<?php
+class ControllerExtensionPaymentPayPoint extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/paypoint');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_paypoint', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['merchant'])) {
+ $data['error_merchant'] = $this->error['merchant'];
+ } else {
+ $data['error_merchant'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/paypoint', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/paypoint', '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_paypoint_merchant'])) {
+ $data['payment_paypoint_merchant'] = $this->request->post['payment_paypoint_merchant'];
+ } else {
+ $data['payment_paypoint_merchant'] = $this->config->get('payment_paypoint_merchant');
+ }
+
+ if (isset($this->request->post['payment_paypoint_password'])) {
+ $data['payment_paypoint_password'] = $this->request->post['payment_paypoint_password'];
+ } else {
+ $data['payment_paypoint_password'] = $this->config->get('payment_paypoint_password');
+ }
+
+ if (isset($this->request->post['payment_paypoint_test'])) {
+ $data['payment_paypoint_test'] = $this->request->post['payment_paypoint_test'];
+ } else {
+ $data['payment_paypoint_test'] = $this->config->get('payment_paypoint_test');
+ }
+
+ if (isset($this->request->post['payment_paypoint_total'])) {
+ $data['payment_paypoint_total'] = $this->request->post['payment_paypoint_total'];
+ } else {
+ $data['payment_paypoint_total'] = $this->config->get('payment_paypoint_total');
+ }
+
+ if (isset($this->request->post['payment_paypoint_order_status_id'])) {
+ $data['payment_paypoint_order_status_id'] = $this->request->post['payment_paypoint_order_status_id'];
+ } else {
+ $data['payment_paypoint_order_status_id'] = $this->config->get('payment_paypoint_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['paypoint_geo_zone_id'])) {
+ $data['paypoint_geo_zone_id'] = $this->request->post['paypoint_geo_zone_id'];
+ } else {
+ $data['paypoint_geo_zone_id'] = $this->config->get('paypoint_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['paypoint_status'])) {
+ $data['paypoint_status'] = $this->request->post['paypoint_status'];
+ } else {
+ $data['paypoint_status'] = $this->config->get('paypoint_status');
+ }
+
+ if (isset($this->request->post['paypoint_sort_order'])) {
+ $data['paypoint_sort_order'] = $this->request->post['paypoint_sort_order'];
+ } else {
+ $data['paypoint_sort_order'] = $this->config->get('paypoint_sort_order');
+ }
+
+ $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/paypoint', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/paypoint')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_paypoint_merchant']) {
+ $this->error['merchant'] = $this->language->get('error_merchant');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/payza.php b/public/admin/controller/extension/payment/payza.php
new file mode 100644
index 0000000..bb250dc
--- /dev/null
+++ b/public/admin/controller/extension/payment/payza.php
@@ -0,0 +1,133 @@
+<?php
+class ControllerExtensionPaymentPayza extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/payza');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_payza', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['merchant'])) {
+ $data['error_merchant'] = $this->error['merchant'];
+ } else {
+ $data['error_merchant'] = '';
+ }
+
+ if (isset($this->error['security'])) {
+ $data['error_security'] = $this->error['security'];
+ } else {
+ $data['error_security'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/payza', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/payza', '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_payza_merchant'])) {
+ $data['payment_payza_merchant'] = $this->request->post['payment_payza_merchant'];
+ } else {
+ $data['payment_payza_merchant'] = $this->config->get('payment_payza_merchant');
+ }
+
+ if (isset($this->request->post['payment_payza_security'])) {
+ $data['payment_payza_security'] = $this->request->post['payment_payza_security'];
+ } else {
+ $data['payment_payza_security'] = $this->config->get('payment_payza_security');
+ }
+
+ $data['callback'] = HTTP_CATALOG . 'index.php?route=extension/payment/payza/callback';
+
+ if (isset($this->request->post['payment_payza_total'])) {
+ $data['payment_payza_total'] = $this->request->post['payment_payza_total'];
+ } else {
+ $data['payment_payza_total'] = $this->config->get('payment_payza_total');
+ }
+
+ if (isset($this->request->post['payment_payza_order_status_id'])) {
+ $data['payment_payza_order_status_id'] = $this->request->post['payment_payza_order_status_id'];
+ } else {
+ $data['payment_payza_order_status_id'] = $this->config->get('payment_payza_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_payza_geo_zone_id'])) {
+ $data['payment_payza_geo_zone_id'] = $this->request->post['payment_payza_geo_zone_id'];
+ } else {
+ $data['payment_payza_geo_zone_id'] = $this->config->get('payment_payza_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_payza_status'])) {
+ $data['payment_payza_status'] = $this->request->post['payment_payza_status'];
+ } else {
+ $data['payment_payza_status'] = $this->config->get('payment_payza_status');
+ }
+
+ if (isset($this->request->post['payment_payza_sort_order'])) {
+ $data['payment_payza_sort_order'] = $this->request->post['payment_payza_sort_order'];
+ } else {
+ $data['payment_payza_sort_order'] = $this->config->get('payment_payza_sort_order');
+ }
+
+ $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/payza', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/payza')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_payza_merchant']) {
+ $this->error['merchant'] = $this->language->get('error_merchant');
+ }
+
+ if (!$this->request->post['payment_payza_security']) {
+ $this->error['security'] = $this->language->get('error_security');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/perpetual_payments.php b/public/admin/controller/extension/payment/perpetual_payments.php
new file mode 100644
index 0000000..f363b5f
--- /dev/null
+++ b/public/admin/controller/extension/payment/perpetual_payments.php
@@ -0,0 +1,137 @@
+<?php
+class ControllerExtensionPaymentPerpetualPayments extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/perpetual_payments');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_perpetual_payments', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['auth_id'])) {
+ $data['error_auth_id'] = $this->error['auth_id'];
+ } else {
+ $data['error_auth_id'] = '';
+ }
+
+ if (isset($this->error['auth_pass'])) {
+ $data['error_auth_pass'] = $this->error['auth_pass'];
+ } else {
+ $data['error_auth_pass'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/perpetual_payments', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/perpetual_payments', '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_perpetual_payments_auth_id'])) {
+ $data['payment_perpetual_payments_auth_id'] = $this->request->post['payment_perpetual_payments_auth_id'];
+ } else {
+ $data['payment_perpetual_payments_auth_id'] = $this->config->get('payment_perpetual_payments_auth_id');
+ }
+
+ if (isset($this->request->post['payment_perpetual_payments_auth_pass'])) {
+ $data['payment_perpetual_payments_auth_pass'] = $this->request->post['payment_perpetual_payments_auth_pass'];
+ } else {
+ $data['payment_perpetual_payments_auth_pass'] = $this->config->get('payment_perpetual_payments_auth_pass');
+ }
+
+ if (isset($this->request->post['payment_perpetual_payments_test'])) {
+ $data['payment_perpetual_payments_test'] = $this->request->post['payment_perpetual_payments_test'];
+ } else {
+ $data['payment_perpetual_payments_test'] = $this->config->get('payment_perpetual_payments_test');
+ }
+
+ if (isset($this->request->post['payment_perpetual_payments_total'])) {
+ $data['payment_perpetual_payments_total'] = $this->request->post['payment_perpetual_payments_total'];
+ } else {
+ $data['payment_perpetual_payments_total'] = $this->config->get('payment_perpetual_payments_total');
+ }
+
+ if (isset($this->request->post['payment_perpetual_payments_order_status_id'])) {
+ $data['payment_perpetual_payments_order_status_id'] = $this->request->post['payment_perpetual_payments_order_status_id'];
+ } else {
+ $data['payment_perpetual_payments_order_status_id'] = $this->config->get('payment_perpetual_payments_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_perpetual_payments_geo_zone_id'])) {
+ $data['payment_perpetual_payments_geo_zone_id'] = $this->request->post['payment_perpetual_payments_geo_zone_id'];
+ } else {
+ $data['payment_perpetual_payments_geo_zone_id'] = $this->config->get('payment_perpetual_payments_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_perpetual_payments_status'])) {
+ $data['payment_perpetual_payments_status'] = $this->request->post['payment_perpetual_payments_status'];
+ } else {
+ $data['payment_perpetual_payments_status'] = $this->config->get('payment_perpetual_payments_status');
+ }
+
+ if (isset($this->request->post['payment_perpetual_payments_sort_order'])) {
+ $data['payment_perpetual_payments_sort_order'] = $this->request->post['payment_perpetual_payments_sort_order'];
+ } else {
+ $data['payment_perpetual_payments_sort_order'] = $this->config->get('payment_perpetual_payments_sort_order');
+ }
+
+ $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/perpetual_payments', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/perpetual_payments')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_perpetual_payments_auth_id']) {
+ $this->error['auth_id'] = $this->language->get('error_auth_id');
+ }
+
+ if (!$this->request->post['payment_perpetual_payments_auth_pass']) {
+ $this->error['auth_pass'] = $this->language->get('error_auth_pass');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/pilibaba.php b/public/admin/controller/extension/payment/pilibaba.php
new file mode 100644
index 0000000..5f78593
--- /dev/null
+++ b/public/admin/controller/extension/payment/pilibaba.php
@@ -0,0 +1,343 @@
+<?php
+class ControllerExtensionPaymentPilibaba extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->model('setting/setting');
+
+ $this->load->model('extension/payment/pilibaba');
+
+ $this->load->language('extension/payment/pilibaba');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_pilibaba', $this->request->post);
+
+ if ($this->request->post['payment_pilibaba_status']) {
+ $this->model_extension_payment_pilibaba->enablePiliExpress();
+ } else {
+ $this->model_extension_payment_pilibaba->disablePiliExpress();
+ }
+
+ $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));
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pilibaba', '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_pilibaba_merchant_number'])) {
+ $data['payment_pilibaba_merchant_number'] = $this->request->post['payment_pilibaba_merchant_number'];
+ } else {
+ $data['payment_pilibaba_merchant_number'] = $this->config->get('payment_pilibaba_merchant_number');
+ }
+
+ if (isset($this->request->post['payment_pilibaba_secret_key'])) {
+ $data['payment_pilibaba_secret_key'] = $this->request->post['payment_pilibaba_secret_key'];
+ } else {
+ $data['payment_pilibaba_secret_key'] = $this->config->get('payment_pilibaba_secret_key');
+ }
+
+ if (isset($this->request->post['payment_pilibaba_environment'])) {
+ $data['payment_pilibaba_environment'] = $this->request->post['payment_pilibaba_environment'];
+ } else {
+ $data['payment_pilibaba_environment'] = $this->config->get('payment_pilibaba_environment');
+ }
+
+ if (isset($this->request->post['payment_pilibaba_shipping_fee'])) {
+ $data['payment_pilibaba_shipping_fee'] = $this->request->post['payment_pilibaba_shipping_fee'];
+ } else {
+ $data['payment_pilibaba_shipping_fee'] = $this->config->get('payment_pilibaba_shipping_fee');
+ }
+
+ if (isset($this->request->post['payment_pilibaba_order_status_id'])) {
+ $data['payment_pilibaba_order_status_id'] = $this->request->post['payment_pilibaba_order_status_id'];
+ } elseif ($this->config->has('payment_pilibaba_order_status_id')) {
+ $data['payment_pilibaba_order_status_id'] = $this->config->get('payment_pilibaba_order_status_id');
+ } else {
+ $data['payment_pilibaba_order_status_id'] = '2';
+ }
+
+ if (isset($this->request->post['payment_pilibaba_status'])) {
+ $data['payment_pilibaba_status'] = $this->request->post['payment_pilibaba_status'];
+ } else {
+ $data['payment_pilibaba_status'] = $this->config->get('payment_pilibaba_status');
+ }
+
+ if (isset($this->request->post['payment_pilibaba_logging'])) {
+ $data['payment_pilibaba_logging'] = $this->request->post['payment_pilibaba_logging'];
+ } else {
+ $data['payment_pilibaba_logging'] = $this->config->get('payment_pilibaba_logging');
+ }
+
+ if (isset($this->request->post['payment_pilibaba_sort_order'])) {
+ $data['payment_pilibaba_sort_order'] = $this->request->post['payment_pilibaba_sort_order'];
+ } else {
+ $data['payment_pilibaba_sort_order'] = $this->config->get('payment_pilibaba_sort_order');
+ }
+
+ if (isset($this->request->post['payment_pilibaba_email_address'])) {
+ $data['payment_pilibaba_email_address'] = $this->request->post['payment_pilibaba_email_address'];
+ } elseif ($this->config->has('payment_pilibaba_email_address')) {
+ $data['payment_pilibaba_email_address'] = $this->config->get('payment_pilibaba_email_address');
+ } else {
+ $data['payment_pilibaba_email_address'] = '';
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->session->data['success'])) {
+ $data['success'] = $this->session->data['success'];
+
+ unset($this->session->data['success']);
+ } else {
+ $data['success'] = '';
+ }
+
+ if (isset($this->error['pilibaba_merchant_number'])) {
+ $data['error_pilibaba_merchant_number'] = $this->error['pilibaba_merchant_number'];
+ } else {
+ $data['error_pilibaba_merchant_number'] = '';
+ }
+
+ if (isset($this->error['pilibaba_secret_key'])) {
+ $data['error_pilibaba_secret_key'] = $this->error['pilibaba_secret_key'];
+ } else {
+ $data['error_pilibaba_secret_key'] = '';
+ }
+
+ if (isset($this->error['pilibaba_shipping_fee'])) {
+ $data['error_pilibaba_shipping_fee'] = $this->error['pilibaba_shipping_fee'];
+ } else {
+ $data['error_pilibaba_shipping_fee'] = '';
+ }
+
+ if ($data['pilibaba_merchant_number'] && $data['payment_pilibaba_secret_key']) {
+ $data['show_register'] = false;
+
+ $data['currencies'] = $data['warehouses'] = $data['countries'] = array();
+ } else {
+ $data['show_register'] = true;
+
+ $data['currencies'] = $this->model_extension_payment_pilibaba->getCurrencies();
+
+ $data['warehouses'] = $this->model_extension_payment_pilibaba->getWarehouses();
+
+ $this->load->model('localisation/country');
+
+ $data['countries'] = $this->model_localisation_country->getCountries();
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if ($this->config->get('config_weight_class_id') != '2') {
+ $data['error_weight'] = sprintf($this->language->get('error_weight'), $this->url->link('setting/setting', 'user_token=' . $this->session->data['user_token'], true));
+ } else {
+ $data['error_weight'] = '';
+ }
+
+ if ($this->config->has('payment_pilibaba_email_address') && $this->config->get('payment_pilibaba_email_address')) {
+ $data['notice_email'] = sprintf($this->language->get('text_email'), $this->config->get('payment_pilibaba_email_address'));
+ } else {
+ $data['notice_email'] = '';
+ }
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $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/pilibaba', $data));
+ }
+
+ public function install() {
+ if ($this->user->hasPermission('modify', 'marketplace/extension')) {
+ $this->load->model('extension/payment/pilibaba');
+
+ $this->model_extension_payment_pilibaba->install();
+ }
+ }
+
+ public function uninstall() {
+ if ($this->user->hasPermission('modify', 'marketplace/extension')) {
+ $this->load->model('extension/payment/pilibaba');
+
+ $this->model_extension_payment_pilibaba->uninstall();
+ }
+ }
+
+ public function register() {
+ $this->load->language('extension/payment/pilibaba');
+
+ $json = array();
+
+ if (isset($this->request->post['email_address']) && isset($this->request->post['password']) && isset($this->request->post['currency']) && isset($this->request->post['warehouse']) && isset($this->request->post['country']) && isset($this->request->post['environment'])) {
+ if (utf8_strlen($this->request->post['email_address']) < 1) {
+ $json['error'] = $this->language->get('error_email_address');
+ } else if (!filter_var($this->request->post['email_address'], FILTER_VALIDATE_EMAIL)) {
+ $json['error'] = $this->language->get('error_email_invalid');
+ } else if (utf8_strlen($this->request->post['password']) < 8) {
+ $json['error'] = $this->language->get('error_password');
+ } else if (utf8_strlen($this->request->post['currency']) < 1) {
+ $json['error'] = $this->language->get('error_currency');
+ } else if (utf8_strlen($this->request->post['warehouse']) < 1) {
+ $json['error'] = $this->language->get('error_warehouse');
+ } else if ($this->request->post['warehouse'] == 'other' && utf8_strlen($this->request->post['country']) < 1) {
+ $json['error'] = $this->language->get('error_country');
+ } else {
+ $this->load->model('extension/payment/pilibaba');
+
+ $response = $this->model_extension_payment_pilibaba->register($this->request->post['email_address'], $this->request->post['password'], $this->request->post['currency'], $this->request->post['warehouse'], $this->request->post['country'], $this->request->post['environment']);
+
+ if (isset($response['code']) && isset($response['message'])) {
+ if ($response['code'] == '0') {
+ $this->load->model('setting/setting');
+
+ $this->model_setting_setting->editSetting('payment_pilibaba', array('pilibaba_merchant_number' => $response['data']['merchantNo'], 'pilibaba_secret_key' => $response['data']['privateKey'], 'pilibaba_email_address' => $this->request->post['email_address'], 'payment_pilibaba_environment' => $this->request->post['environment']), 0);
+
+ $this->session->data['success'] = $this->language->get('text_register_success');
+
+ $json['redirect'] = $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true);
+ } else {
+ $json['error'] = $response['message'];
+ }
+ } else {
+ $json['error'] = $this->language->get('error_bad_response');
+ }
+ }
+ } else {
+ $json['error'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function order() {
+ if ($this->config->get('payment_pilibaba_status')) {
+ $this->load->model('extension/payment/pilibaba');
+
+ $order_id = $this->request->get['order_id'];
+
+ $pilibaba_order = $this->model_extension_payment_pilibaba->getOrder($this->request->get['order_id']);
+
+ if ($pilibaba_order) {
+ $this->load->language('extension/payment/pilibaba');
+
+ $order_info['order_id'] = $pilibaba_order['order_id'];
+
+ $order_info['amount'] = '&yen;' . $pilibaba_order['amount'];
+
+ $order_info['fee'] = '&yen;' . $pilibaba_order['fee'];
+
+ $order_info['status'] = 'Success';
+
+ $order_info['date_added'] = date($this->language->get('datetime_format'), strtotime($pilibaba_order['date_added']));
+
+ $order_info['tracking'] = $pilibaba_order['tracking'];
+
+ $data['pilibaba_order'] = $order_info;
+
+ $data['barcode'] = $this->url->link('extension/payment/pilibaba/barcode', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true);
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/pilibaba_order', $data);
+ }
+ }
+ }
+
+ public function tracking() {
+ $this->load->language('extension/payment/pilibaba');
+
+ $json = array();
+
+ if ($this->config->get('payment_pilibaba_status')) {
+ if (isset($this->request->post['order_id']) && isset($this->request->post['tracking'])) {
+ if (utf8_strlen($this->request->post['tracking']) > 0 && utf8_strlen($this->request->post['tracking']) <= 50) {
+ $this->load->model('extension/payment/pilibaba');
+
+ $this->model_extension_payment_pilibaba->updateTrackingNumber($this->request->post['order_id'], $this->request->post['tracking'], $this->config->get('payment_pilibaba_merchant_number'));
+
+ $json['success'] = $this->language->get('text_tracking_success');
+ } else {
+ $json['error'] = $this->language->get('error_tracking_length');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_data_missing');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_enabled');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function barcode() {
+ if ($this->config->get('payment_pilibaba_status')) {
+ if (isset($this->request->get['order_id'])) {
+ if ($this->config->get('payment_pilibaba_environment') == 'live') {
+ $url = 'https://www.pilibaba.com/pilipay/barCode';
+ } else {
+ $url = 'http://pre.pilibaba.com/pilipay/barCode';
+ }
+
+ echo '<img src="' . $url . '?orderNo=' . $this->request->get['order_id'] . '&merchantNo=' . $this->config->get('payment_pilibaba_merchant_number') . '">';
+ }
+ }
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/pilibaba')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_pilibaba_merchant_number']) {
+ $this->error['pilibaba_merchant_number'] = $this->language->get('error_merchant_number');
+ }
+
+ if (!$this->request->post['payment_pilibaba_secret_key']) {
+ $this->error['pilibaba_secret_key'] = $this->language->get('error_secret_key');
+ }
+
+ if ($this->request->post['payment_pilibaba_shipping_fee'] != '' && strpos($this->request->post['payment_pilibaba_shipping_fee'], '.') === false) {
+ $this->error['pilibaba_shipping_fee'] = $this->language->get('error_shipping_fee');
+ }
+
+ if ($this->error && !isset($this->error['warning'])) {
+ $this->error['warning'] = $this->language->get('error_warning');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/pp_braintree.php b/public/admin/controller/extension/payment/pp_braintree.php
new file mode 100644
index 0000000..0bf83e8
--- /dev/null
+++ b/public/admin/controller/extension/payment/pp_braintree.php
@@ -0,0 +1,1132 @@
+<?php
+class ControllerExtensionPaymentPPBraintree extends Controller {
+ private $error = array();
+ private $gateway = null;
+ private $opencart_connect_url = 'https://www.opencart.com/index.php?route=external/braintree_auth/connect';
+ private $opencart_retrieve_url = 'https://www.opencart.com/index.php?route=external/braintree_auth/retrieve';
+
+ public function index() {
+ $this->load->language('extension/payment/pp_braintree');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ foreach ($this->request->post['payment_pp_braintree_account'] as $currency => $account) {
+ if (!isset($account['status'])) {
+ $this->request->post['payment_pp_braintree_account'][$currency]['status'] = 0;
+ }
+ }
+
+ $this->model_setting_setting->editSetting('payment_pp_braintree', $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));
+ }
+
+ $data['button_configure'] = $this->url->link('extension/module/pp_braintree_button/configure', 'user_token=' . $this->session->data['user_token'], true);
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $this->load->model('localisation/currency');
+
+ $data['currencies'] = $this->model_localisation_currency->getCurrencies();
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['account'])) {
+ $data['error_account'] = $this->error['account'];
+ } else {
+ $data['error_account'] = array();
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pp_braintree', '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_pp_braintree_merchant_id'])) {
+ $data['payment_pp_braintree_merchant_id'] = $this->request->post['payment_pp_braintree_merchant_id'];
+ } else {
+ $data['payment_pp_braintree_merchant_id'] = $this->config->get('payment_pp_braintree_merchant_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_public_key'])) {
+ $data['payment_pp_braintree_public_key'] = $this->request->post['payment_pp_braintree_public_key'];
+ } else {
+ $data['payment_pp_braintree_public_key'] = $this->config->get('payment_pp_braintree_public_key');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_private_key'])) {
+ $data['payment_pp_braintree_private_key'] = $this->request->post['payment_pp_braintree_private_key'];
+ } else {
+ $data['payment_pp_braintree_private_key'] = $this->config->get('payment_pp_braintree_private_key');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_access_token'])) {
+ $data['payment_pp_braintree_access_token'] = $this->request->post['payment_pp_braintree_access_token'];
+ } else {
+ $data['payment_pp_braintree_access_token'] = $this->config->get('payment_pp_braintree_access_token');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_refresh_token'])) {
+ $data['payment_pp_braintree_refresh_token'] = $this->request->post['payment_pp_braintree_refresh_token'];
+ } else {
+ $data['payment_pp_braintree_refresh_token'] = $this->config->get('payment_pp_braintree_refresh_token');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_environment'])) {
+ $data['payment_pp_braintree_environment'] = $this->request->post['payment_pp_braintree_environment'];
+ } else {
+ $data['payment_pp_braintree_environment'] = $this->config->get('payment_pp_braintree_environment');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_settlement_immediate'])) {
+ $data['payment_pp_braintree_settlement_immediate'] = $this->request->post['payment_pp_braintree_settlement_immediate'];
+ } else {
+ $data['payment_pp_braintree_settlement_immediate'] = $this->config->get('payment_pp_braintree_settlement_immediate');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_card_vault'])) {
+ $data['payment_pp_braintree_card_vault'] = $this->request->post['payment_pp_braintree_card_vault'];
+ } else {
+ $data['payment_pp_braintree_card_vault'] = $this->config->get('payment_pp_braintree_card_vault');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_card_check_vault'])) {
+ $data['payment_pp_braintree_card_check_vault'] = $this->request->post['payment_pp_braintree_card_check_vault'];
+ } else {
+ $data['payment_pp_braintree_card_check_vault'] = $this->config->get('payment_pp_braintree_card_check_vault');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_paypal_vault'])) {
+ $data['payment_pp_braintree_paypal_vault'] = $this->request->post['payment_pp_braintree_paypal_vault'];
+ } else {
+ $data['payment_pp_braintree_paypal_vault'] = $this->config->get('payment_pp_braintree_paypal_vault');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_paypal_check_vault'])) {
+ $data['payment_pp_braintree_paypal_check_vault'] = $this->request->post['payment_pp_braintree_paypal_check_vault'];
+ } else {
+ $data['payment_pp_braintree_paypal_check_vault'] = $this->config->get('payment_pp_braintree_paypal_check_vault');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_vault_cvv_3ds'])) {
+ $data['payment_pp_braintree_vault_cvv_3ds'] = $this->request->post['payment_pp_braintree_vault_cvv_3ds'];
+ } else {
+ $data['payment_pp_braintree_vault_cvv_3ds'] = $this->config->get('payment_pp_braintree_vault_cvv_3ds');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_debug'])) {
+ $data['payment_pp_braintree_debug'] = $this->request->post['payment_pp_braintree_debug'];
+ } else {
+ $data['payment_pp_braintree_debug'] = $this->config->get('payment_pp_braintree_debug');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_total'])) {
+ $data['payment_pp_braintree_total'] = $this->request->post['payment_pp_braintree_total'];
+ } else {
+ $data['payment_pp_braintree_total'] = $this->config->get('payment_pp_braintree_total');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_geo_zone_id'])) {
+ $data['payment_pp_braintree_geo_zone_id'] = $this->request->post['payment_pp_braintree_geo_zone_id'];
+ } else {
+ $data['payment_pp_braintree_geo_zone_id'] = $this->config->get('payment_pp_braintree_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_status'])) {
+ $data['payment_pp_braintree_status'] = $this->request->post['payment_pp_braintree_status'];
+ } else {
+ $data['payment_pp_braintree_status'] = $this->config->get('payment_pp_braintree_status');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_sort_order'])) {
+ $data['payment_pp_braintree_sort_order'] = $this->request->post['payment_pp_braintree_sort_order'];
+ } else {
+ $data['payment_pp_braintree_sort_order'] = $this->config->get('payment_pp_braintree_sort_order');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_account'])) {
+ $data['payment_pp_braintree_account'] = $this->request->post['payment_pp_braintree_account'];
+ } else {
+ $data['payment_pp_braintree_account'] = $this->config->get('payment_pp_braintree_account');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_authorization_expired_id'])) {
+ $data['payment_pp_braintree_authorization_expired_id'] = $this->request->post['payment_pp_braintree_authorization_expired_id'];
+ } else {
+ $data['payment_pp_braintree_authorization_expired_id'] = $this->config->get('payment_pp_braintree_authorization_expired_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_authorized_id'])) {
+ $data['payment_pp_braintree_authorized_id'] = $this->request->post['payment_pp_braintree_authorized_id'];
+ } else {
+ $data['payment_pp_braintree_authorized_id'] = $this->config->get('payment_pp_braintree_authorized_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_authorizing_id'])) {
+ $data['payment_pp_braintree_authorizing_id'] = $this->request->post['payment_pp_braintree_authorizing_id'];
+ } else {
+ $data['payment_pp_braintree_authorizing_id'] = $this->config->get('payment_pp_braintree_authorizing_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_settlement_pending_id'])) {
+ $data['payment_pp_braintree_settlement_pending_id'] = $this->request->post['payment_pp_braintree_settlement_pending_id'];
+ } else {
+ $data['payment_pp_braintree_settlement_pending_id'] = $this->config->get('payment_pp_braintree_settlement_pending_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_failed_id'])) {
+ $data['payment_pp_braintree_failed_id'] = $this->request->post['payment_pp_braintree_failed_id'];
+ } else {
+ $data['payment_pp_braintree_failed_id'] = $this->config->get('payment_pp_braintree_failed_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_gateway_rejected_id'])) {
+ $data['payment_pp_braintree_gateway_rejected_id'] = $this->request->post['payment_pp_braintree_gateway_rejected_id'];
+ } else {
+ $data['payment_pp_braintree_gateway_rejected_id'] = $this->config->get('payment_pp_braintree_gateway_rejected_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_processor_declined_id'])) {
+ $data['payment_pp_braintree_processor_declined_id'] = $this->request->post['payment_pp_braintree_processor_declined_id'];
+ } else {
+ $data['payment_pp_braintree_processor_declined_id'] = $this->config->get('payment_pp_braintree_processor_declined_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_settled_id'])) {
+ $data['payment_pp_braintree_settled_id'] = $this->request->post['payment_pp_braintree_settled_id'];
+ } else {
+ $data['payment_pp_braintree_settled_id'] = $this->config->get('payment_pp_braintree_settled_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_settling_id'])) {
+ $data['payment_pp_braintree_settling_id'] = $this->request->post['payment_pp_braintree_settling_id'];
+ } else {
+ $data['payment_pp_braintree_settling_id'] = $this->config->get('payment_pp_braintree_settling_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_submitted_for_settlement_id'])) {
+ $data['payment_pp_braintree_submitted_for_settlement_id'] = $this->request->post['payment_pp_braintree_submitted_for_settlement_id'];
+ } else {
+ $data['payment_pp_braintree_submitted_for_settlement_id'] = $this->config->get('payment_pp_braintree_submitted_for_settlement_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_voided_id'])) {
+ $data['payment_pp_braintree_voided_id'] = $this->request->post['payment_pp_braintree_voided_id'];
+ } else {
+ $data['payment_pp_braintree_voided_id'] = $this->config->get('payment_pp_braintree_voided_id');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_status'])) {
+ $data['payment_pp_braintree_3ds_status'] = $this->request->post['payment_pp_braintree_3ds_status'];
+ } else {
+ $data['payment_pp_braintree_3ds_status'] = $this->config->get('payment_pp_braintree_3ds_status');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_unsupported_card'])) {
+ $data['payment_pp_braintree_3ds_unsupported_card'] = $this->request->post['payment_pp_braintree_3ds_unsupported_card'];
+ } else {
+ $data['payment_pp_braintree_3ds_unsupported_card'] = $this->config->get('payment_pp_braintree_3ds_unsupported_card');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_lookup_error'])) {
+ $data['payment_pp_braintree_3ds_lookup_error'] = $this->request->post['payment_pp_braintree_3ds_lookup_error'];
+ } else {
+ $data['payment_pp_braintree_3ds_lookup_error'] = $this->config->get('payment_pp_braintree_3ds_lookup_error');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_lookup_enrolled'])) {
+ $data['payment_pp_braintree_3ds_lookup_enrolled'] = $this->request->post['payment_pp_braintree_3ds_lookup_enrolled'];
+ } else {
+ $data['payment_pp_braintree_3ds_lookup_enrolled'] = $this->config->get('payment_pp_braintree_3ds_lookup_enrolled');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_lookup_not_enrolled'])) {
+ $data['payment_pp_braintree_3ds_lookup_not_enrolled'] = $this->request->post['payment_pp_braintree_3ds_lookup_not_enrolled'];
+ } else {
+ $data['payment_pp_braintree_3ds_lookup_not_enrolled'] = $this->config->get('payment_pp_braintree_3ds_lookup_not_enrolled');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_not_participating'])) {
+ $data['payment_pp_braintree_3ds_not_participating'] = $this->request->post['payment_pp_braintree_3ds_not_participating'];
+ } else {
+ $data['payment_pp_braintree_3ds_not_participating'] = $this->config->get('payment_pp_braintree_3ds_not_participating');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_unavailable'])) {
+ $data['payment_pp_braintree_3ds_unavailable'] = $this->request->post['payment_pp_braintree_3ds_unavailable'];
+ } else {
+ $data['payment_pp_braintree_3ds_unavailable'] = $this->config->get('payment_pp_braintree_3ds_unavailable');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_signature_failed'])) {
+ $data['payment_pp_braintree_3ds_signature_failed'] = $this->request->post['payment_pp_braintree_3ds_signature_failed'];
+ } else {
+ $data['payment_pp_braintree_3ds_signature_failed'] = $this->config->get('payment_pp_braintree_3ds_signature_failed');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_successful'])) {
+ $data['payment_pp_braintree_3ds_successful'] = $this->request->post['payment_pp_braintree_3ds_successful'];
+ } else {
+ $data['payment_pp_braintree_3ds_successful'] = $this->config->get('payment_pp_braintree_3ds_successful');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_attempt_successful'])) {
+ $data['payment_pp_braintree_3ds_attempt_successful'] = $this->request->post['payment_pp_braintree_3ds_attempt_successful'];
+ } else {
+ $data['payment_pp_braintree_3ds_attempt_successful'] = $this->config->get('payment_pp_braintree_3ds_attempt_successful');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_failed'])) {
+ $data['payment_pp_braintree_3ds_failed'] = $this->request->post['payment_pp_braintree_3ds_failed'];
+ } else {
+ $data['payment_pp_braintree_3ds_failed'] = $this->config->get('payment_pp_braintree_3ds_failed');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_unable_to_auth'])) {
+ $data['payment_pp_braintree_3ds_unable_to_auth'] = $this->request->post['payment_pp_braintree_3ds_unable_to_auth'];
+ } else {
+ $data['payment_pp_braintree_3ds_unable_to_auth'] = $this->config->get('payment_pp_braintree_3ds_unable_to_auth');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_3ds_error'])) {
+ $data['payment_pp_braintree_3ds_error'] = $this->request->post['payment_pp_braintree_3ds_error'];
+ } else {
+ $data['payment_pp_braintree_3ds_error'] = $this->config->get('payment_pp_braintree_3ds_error');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_paypal_option'])) {
+ $data['payment_pp_braintree_paypal_option'] = $this->request->post['payment_pp_braintree_paypal_option'];
+ } else {
+ $data['payment_pp_braintree_paypal_option'] = $this->config->get('payment_pp_braintree_paypal_option');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_paypal_button_colour'])) {
+ $data['payment_pp_braintree_paypal_button_colour'] = $this->request->post['payment_pp_braintree_paypal_button_colour'];
+ } else {
+ $data['payment_pp_braintree_paypal_button_colour'] = $this->config->get('payment_pp_braintree_paypal_button_colour');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_paypal_button_size'])) {
+ $data['payment_pp_braintree_paypal_button_size'] = $this->request->post['payment_pp_braintree_paypal_button_size'];
+ } else {
+ $data['payment_pp_braintree_paypal_button_size'] = $this->config->get('payment_pp_braintree_paypal_button_size');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_paypal_button_shape'])) {
+ $data['payment_pp_braintree_paypal_button_shape'] = $this->request->post['payment_pp_braintree_paypal_button_shape'];
+ } else {
+ $data['payment_pp_braintree_paypal_button_shape'] = $this->config->get('payment_pp_braintree_paypal_button_shape');
+ }
+
+ if (isset($this->request->post['payment_pp_braintree_billing_agreement'])) {
+ $data['payment_pp_braintree_billing_agreement'] = $this->request->post['payment_pp_braintree_billing_agreement'];
+ } else {
+ $data['payment_pp_braintree_billing_agreement'] = $this->config->get('payment_pp_braintree_billing_agreement');
+ }
+
+ $data['transaction_statuses'] = array(
+ 'authorization_expired',
+ 'authorized',
+ 'authorizing',
+ 'settlement_pending',
+ 'failed',
+ 'gateway_rejected',
+ 'processor_declined',
+ 'settled',
+ 'settling',
+ 'submitted_for_settlement',
+ 'voided'
+ );
+
+ $data['card_types'] = array(
+ 'Visa',
+ 'MasterCard',
+ 'American Express',
+ 'Discover',
+ 'JCB',
+ 'Maestro'
+ );
+
+ if (isset($this->request->get['retrieve_code'])) {
+ $data['retrieve_code'] = $this->request->get['retrieve_code'];
+
+ $curl = curl_init($this->opencart_retrieve_url);
+
+ $post_data = array(
+ 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true),
+ 'retrieve_code' => $this->request->get['retrieve_code'],
+ 'store_version' => VERSION,
+ );
+
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
+ curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
+
+ $curl_response = curl_exec($curl);
+ $config_response = json_decode($curl_response, true);
+ curl_close($curl);
+
+ if (isset($config_response['merchant_id']) && isset($config_response['access_token']) && isset($config_response['refresh_token'])) {
+ $braintree_settings = $this->model_setting_setting->getSetting('payment_pp_braintree');
+ $braintree_settings['payment_pp_braintree_merchant_id'] = $config_response['merchant_id'];
+ $braintree_settings['payment_pp_braintree_access_token'] = $config_response['access_token'];
+ $braintree_settings['payment_pp_braintree_refresh_token'] = $config_response['refresh_token'];
+ $braintree_settings['payment_pp_braintree_environment'] = $config_response['environment'];
+ $braintree_settings['payment_pp_braintree_public_key'] = '';
+ $braintree_settings['payment_pp_braintree_private_key'] = '';
+
+ $this->model_setting_setting->editSetting('payment_pp_braintree', $braintree_settings);
+
+ $data['payment_pp_braintree_merchant_id'] = $config_response['merchant_id'];
+ $data['payment_pp_braintree_access_token'] = $config_response['access_token'];
+ $data['payment_pp_braintree_refresh_token'] = $config_response['refresh_token'];
+ $data['payment_pp_braintree_environment'] = $config_response['environment'];
+ $data['payment_pp_braintree_public_key'] = '';
+ $data['payment_pp_braintree_private_key'] = '';
+
+ $data['success'] = $this->language->get('text_success_connect');
+ }
+ }
+
+ $data['auth_connect_url'] = '';
+
+ // If Braintree is not setup yet, request auth token for merchant on-boarding flow
+ if ($data['payment_pp_braintree_merchant_id'] == '') {
+ $curl = curl_init($this->opencart_connect_url);
+
+ $this->load->model('localisation/country');
+ $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id'));
+
+ $post_data = array(
+ 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true),
+ 'store_url' => HTTPS_CATALOG,
+ 'store_version' => VERSION,
+ 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''),
+ );
+
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
+ curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
+
+ $curl_response = curl_exec($curl);
+
+ $curl_response = json_decode($curl_response, true);
+
+ curl_close($curl);
+
+ if ($curl_response['url']) {
+ $data['auth_connect_url'] = $curl_response['url'];
+ }
+ }
+
+ $data['braintree_config'] = array();
+ $data['braintree_config']['three_d_secure_enabled'] = 0;
+ $data['braintree_config']['paypal_enabled'] = 0;
+
+ $data['error_braintree_account_3ds'] = $this->language->get('error_braintree_account_3ds');
+ $data['error_braintree_account_paypal'] = $this->language->get('error_braintree_account_paypal');
+
+ // load the account info from braintree if the config has been added yet.
+ if (!empty($data['payment_pp_braintree_access_token']) || (!empty($data['payment_pp_braintree_environment']) && !empty($data['payment_pp_braintree_merchant_id']) && !empty($data['payment_pp_braintree_public_key']) && !empty($data['payment_pp_braintree_private_key']))) {
+ $this->initialise($data['payment_pp_braintree_access_token'], array(
+ 'payment_pp_braintree_environment' => $data['payment_pp_braintree_environment'],
+ 'payment_pp_braintree_merchant_id' => $data['payment_pp_braintree_merchant_id'],
+ 'payment_pp_braintree_public_key' => $data['payment_pp_braintree_public_key'],
+ 'payment_pp_braintree_private_key' => $data['payment_pp_braintree_private_key'],
+ ));
+
+ $verify_credentials = $this->model_extension_payment_pp_braintree->verifyCredentials($this->gateway);
+
+ if (!$verify_credentials) {
+ $this->error['warning'] = $this->language->get('error_connection');
+ } else {
+ $merchant_config = json_decode(base64_decode($verify_credentials), true);
+
+ if (isset($merchant_config['threeDSecureEnabled']) && $merchant_config['threeDSecureEnabled'] == 1) {
+ $data['braintree_config']['three_d_secure_enabled'] = 1;
+ }
+
+ if (isset($merchant_config['paypalEnabled']) && $merchant_config['paypalEnabled'] == 1) {
+ $data['braintree_config']['paypal_enabled'] = 1;
+ }
+ }
+ }
+
+ $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/pp_braintree', $data));
+ }
+
+ public function install() {
+ $this->load->model('setting/setting');
+
+ $defaults = array();
+
+ // 3D secure defaults
+ $defaults['payment_pp_braintree_3ds_unsupported_card'] = 1;
+ $defaults['payment_pp_braintree_3ds_lookup_error'] = 1;
+ $defaults['payment_pp_braintree_3ds_lookup_enrolled'] = 1;
+ $defaults['payment_pp_braintree_3ds_lookup_not_enrolled'] = 1;
+ $defaults['payment_pp_braintree_3ds_not_participating'] = 1;
+ $defaults['payment_pp_braintree_3ds_unavailable'] = 1;
+ $defaults['payment_pp_braintree_3ds_signature_failed'] = 0;
+ $defaults['payment_pp_braintree_3ds_successful'] = 1;
+ $defaults['payment_pp_braintree_3ds_attempt_successful'] = 1;
+ $defaults['payment_pp_braintree_3ds_failed'] = 0;
+ $defaults['payment_pp_braintree_3ds_unable_to_auth'] = 1;
+ $defaults['payment_pp_braintree_3ds_error'] = 1;
+
+ // Order Status defaults
+ $defaults['payment_pp_braintree_authorization_expired_id'] = 14;
+ $defaults['payment_pp_braintree_authorized_id'] = 2;
+ $defaults['payment_pp_braintree_authorizing_id'] = 1;
+ $defaults['payment_pp_braintree_failed_id'] = 10;
+ $defaults['payment_pp_braintree_gateway_rejected_id'] = 8;
+ $defaults['payment_pp_braintree_processor_declined_id'] = 8;
+ $defaults['payment_pp_braintree_settled_id'] = 2;
+ $defaults['payment_pp_braintree_settling_id'] = 2;
+ $defaults['payment_pp_braintree_settlement_pending_id'] = 2;
+ $defaults['payment_pp_braintree_submitted_for_settlement_id'] = 2;
+ $defaults['payment_pp_braintree_voided_id'] = 16;
+
+ $defaults['payment_pp_braintree_settlement_immediate'] = 1;
+
+ // PayPal options
+ $defaults['payment_pp_braintree_paypal_option'] = 1;
+ $defaults['payment_pp_braintree_paypal_button_size'] = 'small';
+ $defaults['payment_pp_braintree_paypal_button_shape'] = 'rect';
+
+ // Vault options
+ $defaults['payment_pp_braintree_card_vault'] = 1;
+ $defaults['payment_pp_braintree_paypal_vault'] = 0;
+ $defaults['payment_pp_braintree_card_check_vault'] = 1;
+ $defaults['payment_pp_braintree_paypal_check_vault'] = 0;
+
+ $this->model_setting_setting->editSetting('payment_pp_braintree', $defaults);
+ }
+
+ public function order() {
+ $this->load->language('extension/payment/pp_braintree');
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ return $this->load->view('extension/payment/pp_braintree_order', $data);
+ }
+
+ public function getTransaction() {
+ $this->load->language('extension/payment/pp_braintree');
+
+ $this->load->model('extension/payment/pp_braintree');
+ $this->load->model('sale/order');
+
+ if (!$this->config->get('payment_pp_braintree_status') || (!isset($this->request->get['order_id']) && !isset($this->request->get['transaction_id']))) {
+ return;
+ }
+
+ $this->initialise($this->config->get('payment_pp_braintree_access_token'), array(
+ 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'),
+ 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'),
+ 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'),
+ 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key')
+ ));
+
+ if (isset($this->request->get['order_id'])) {
+ $search = array(
+ Braintree_TransactionSearch::orderId()->is($this->request->get['order_id'])
+ );
+ } elseif (isset($this->request->get['transaction_id'])) {
+ $search = array(
+ Braintree_TransactionSearch::id()->is($this->request->get['transaction_id'])
+ );
+ }
+
+ $search_transactions = $this->model_extension_payment_pp_braintree->getTransactions($this->gateway, $search);
+
+ $transaction = array();
+
+ foreach ($search_transactions as $search_transaction) {
+ $transaction = $search_transaction;
+ }
+
+ $data['transaction'] = array();
+
+ if ($transaction) {
+ $data['transaction_id'] = $transaction->id;
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $data['void_action'] = $data['settle_action'] = $data['refund_action'] = false;
+
+ switch ($transaction->status) {
+ case 'authorized':
+ $data['void_action'] = true;
+ $data['settle_action'] = true;
+ break;
+ case 'submitted_for_settlement':
+ $data['void_action'] = true;
+ break;
+ case 'settling':
+ $data['refund_action'] = true;
+ break;
+ case 'settled':
+ $data['refund_action'] = true;
+ break;
+ }
+
+ $statuses = array();
+
+ foreach ($transaction->statusHistory as $status_history) {
+ $created_at = $status_history->timestamp;
+
+ $statuses[] = array(
+ 'status' => $status_history->status,
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e')))
+ );
+ }
+
+ $data['statuses'] = $statuses;
+
+ $max_settle_amount = $transaction->amount;
+
+ $max_refund_amount = $transaction->amount;
+
+ $data['refunds'] = array();
+
+ foreach (array_reverse($transaction->refundIds) as $refund_id) {
+ $refund = $this->model_extension_payment_pp_braintree->getTransaction($this->gateway, $refund_id);
+
+ $successful_statuses = array(
+ 'authorized',
+ 'authorizing',
+ 'settlement_pending',
+ 'settlement_confirmed',
+ 'settled',
+ 'settling',
+ 'submitted_for_settlement'
+ );
+
+ if (in_array($refund->status, $successful_statuses)) {
+ $max_refund_amount -= $refund->amount;
+ }
+
+ $created_at = $refund->createdAt;
+
+ $data['refunds'][] = array(
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))),
+ 'amount' => $this->currency->format($refund->amount, $refund->currencyIsoCode, '1.00000000', true),
+ 'status' => $refund->status
+ );
+ }
+
+ //If nothing left to refund, disable refund action
+ if (!$max_refund_amount) {
+ $data['refund_action'] = false;
+ }
+
+ $data['max_settle_amount'] = $this->currency->format($max_settle_amount, $transaction->currencyIsoCode, '1.00000000', false);
+
+ $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $transaction->currencyIsoCode, '1.00000000', false);
+
+ $amount = $this->currency->format($transaction->amount, $transaction->currencyIsoCode, '1.00000000', true);
+
+ $data['symbol_left'] = $this->currency->getSymbolLeft($transaction->currencyIsoCode);
+ $data['symbol_right'] = $this->currency->getSymbolRight($transaction->currencyIsoCode);
+
+ $created_at = $transaction->createdAt;
+
+ if ($transaction->threeDSecureInfo) {
+ if ($transaction->threeDSecureInfo->liabilityShifted) {
+ $liability_shifted = $this->language->get('text_yes');
+ } else {
+ $liability_shifted = $this->language->get('text_no');
+ }
+ }
+
+ if ($transaction->threeDSecureInfo) {
+ if ($transaction->threeDSecureInfo->liabilityShiftPossible) {
+ $liability_shift_possible = $this->language->get('text_yes');
+ } else {
+ $liability_shift_possible = $this->language->get('text_no');
+ }
+ }
+
+ $data['transaction'] = array(
+ 'status' => $transaction->status,
+ 'transaction_id' => $transaction->id,
+ 'type' => $transaction->type,
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))),
+ 'merchant_account_id' => $transaction->merchantAccountId,
+ 'payment_type' => $transaction->paymentInstrumentType,
+ 'currency' => $transaction->currencyIsoCode,
+ 'amount' => $amount,
+ 'order_id' => $transaction->orderId,
+ 'processor_code' => $transaction->processorAuthorizationCode,
+ 'cvv_response' => $transaction->cvvResponseCode,
+ 'avs_response' => sprintf($this->language->get('text_avs_response'), $transaction->avsStreetAddressResponseCode, $transaction->avsPostalCodeResponseCode),
+ 'threeds_enrolled' => ($transaction->threeDSecureInfo ? $transaction->threeDSecureInfo->enrolled : ''),
+ 'threeds_status' => ($transaction->threeDSecureInfo ? $transaction->threeDSecureInfo->status : ''),
+ 'threeds_shifted' => ($transaction->threeDSecureInfo ? $liability_shifted : ''),
+ 'threeds_shift_possible' => ($transaction->threeDSecureInfo ? $liability_shift_possible : '')
+ );
+
+ $data['text_confirm_void'] = $this->language->get('text_confirm_void');
+ $data['text_confirm_settle'] = $this->language->get('text_confirm_settle');
+ $data['text_confirm_refund'] = $this->language->get('text_confirm_refund');
+
+ $this->response->setOutput($this->load->view('extension/payment/pp_braintree_order_ajax', $data));
+ }
+ }
+
+ public function transactionCommand() {
+ $this->load->language('extension/payment/pp_braintree');
+
+ $this->load->model('extension/payment/pp_braintree');
+
+ $this->initialise($this->config->get('payment_pp_braintree_access_token'), array(
+ 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'),
+ 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'),
+ 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'),
+ 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key')
+ ));
+
+ $json = array();
+
+ $success = $error = '';
+
+ if ($this->request->post['type'] == 'void') {
+ $action = $this->model_extension_payment_pp_braintree->voidTransaction($this->gateway, $this->request->post['transaction_id']);
+ } elseif ($this->request->post['type'] == 'settle' && $this->request->post['amount']) {
+ $action = $this->model_extension_payment_pp_braintree->settleTransaction($this->gateway, $this->request->post['transaction_id'], $this->request->post['amount']);
+ } elseif ($this->request->post['type'] == 'refund' && $this->request->post['amount']) {
+ $action = $this->model_extension_payment_pp_braintree->refundTransaction($this->gateway, $this->request->post['transaction_id'], $this->request->post['amount']);
+ } else {
+ $error = true;
+ }
+
+ if (!$error && $action && $action->success) {
+ $success = $this->language->get('text_success_action');
+ } elseif (!$error && $action && isset($action->message)) {
+ $error = sprintf($this->language->get('text_error_settle'), $action->message);
+ } else {
+ $error = $this->language->get('text_error_generic');
+ }
+
+ $json['success'] = $success;
+ $json['error'] = $error;
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function search() {
+ $this->load->language('extension/payment/pp_braintree');
+
+ $this->load->model('extension/payment/pp_braintree');
+ $this->load->model('customer/customer');
+ $this->load->model('sale/order');
+
+ $this->initialise($this->config->get('payment_pp_braintree_access_token'), array(
+ 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'),
+ 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'),
+ 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'),
+ 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key')
+ ));
+
+ $json = array();
+
+ $success = $error = '';
+
+ if (isset($this->request->get['filter_transaction_id'])) {
+ $filter_transaction_id = $this->request->get['filter_transaction_id'];
+ } else {
+ $filter_transaction_id = null;
+ }
+
+ if (isset($this->request->get['filter_transaction_type'])) {
+ $filter_transaction_type = $this->request->get['filter_transaction_type'];
+ } else {
+ $filter_transaction_type = null;
+ }
+
+ if (isset($this->request->get['filter_payment_type'])) {
+ $filter_payment_type = $this->request->get['filter_payment_type'];
+ } else {
+ $filter_payment_type = null;
+ }
+
+ if (isset($this->request->get['filter_card_type'])) {
+ $filter_card_type = $this->request->get['filter_card_type'];
+ } else {
+ $filter_card_type = null;
+ }
+
+ if (isset($this->request->get['filter_merchant_account_id'])) {
+ $filter_merchant_account_id = $this->request->get['filter_merchant_account_id'];
+ } else {
+ $filter_merchant_account_id = null;
+ }
+
+ if (isset($this->request->get['filter_transaction_status'])) {
+ $filter_transaction_status = $this->request->get['filter_transaction_status'];
+ } else {
+ $filter_transaction_status = null;
+ }
+
+ if (isset($this->request->get['filter_date_from'])) {
+ $filter_date_from = $this->request->get['filter_date_from'];
+ } else {
+ $filter_date_from = null;
+ }
+
+ if (isset($this->request->get['filter_date_to'])) {
+ $filter_date_to = $this->request->get['filter_date_to'];
+ } else {
+ $filter_date_to = null;
+ }
+
+ if (isset($this->request->get['filter_amount_from'])) {
+ $filter_amount_from = $this->request->get['filter_amount_from'];
+ } else {
+ $filter_amount_from = null;
+ }
+
+ if (isset($this->request->get['filter_amount_to'])) {
+ $filter_amount_to = $this->request->get['filter_amount_to'];
+ } else {
+ $filter_amount_to = null;
+ }
+
+ $json['transactions'] = array();
+
+ $search = array();
+
+ if ($filter_transaction_id) {
+ $search[] = Braintree_TransactionSearch::id()->is($filter_transaction_id);
+ }
+
+ if ($filter_transaction_type) {
+ if ($filter_transaction_type == 'sale') {
+ $transaction_type = Braintree_Transaction::SALE;
+ } elseif ($filter_transaction_type == 'credit') {
+ $transaction_type = Braintree_Transaction::CREDIT;
+ }
+
+ $search[] = Braintree_TransactionSearch::type()->is($transaction_type);
+ }
+
+ if ($filter_payment_type) {
+ if ($filter_payment_type == 'Credit Card') {
+ $payment_type = 'CreditCardDetail';
+ } elseif ($filter_payment_type == 'PayPal') {
+ $payment_type = 'PayPalDetail';
+ }
+
+ $search[] = Braintree_TransactionSearch::paymentInstrumentType()->is($payment_type);
+ }
+
+ if ($filter_card_type) {
+ switch ($filter_card_type) {
+ case 'Visa':
+ $card_type = Braintree_CreditCard::VISA;
+ break;
+ case 'MasterCard':
+ $card_type = Braintree_CreditCard::MASTER_CARD;
+ break;
+ case 'American Express':
+ $card_type = Braintree_CreditCard::AMEX;
+ break;
+ case 'Discover':
+ $card_type = Braintree_CreditCard::DISCOVER;
+ break;
+ case 'JCB':
+ $card_type = Braintree_CreditCard::JCB;
+ break;
+ case 'Maestro':
+ $card_type = Braintree_CreditCard::MAESTRO;
+ break;
+ }
+
+ $search[] = Braintree_TransactionSearch::creditCardCardType()->is($card_type);
+ }
+
+ if ($filter_merchant_account_id) {
+ $search[] = Braintree_TransactionSearch::merchantAccountId()->is($filter_merchant_account_id);
+ }
+
+ if ($filter_transaction_status) {
+ $search[] = Braintree_TransactionSearch::status()->in($filter_transaction_status);
+ }
+
+ if ($filter_date_from || $filter_date_to) {
+ if ($filter_date_from) {
+ $date_from = new DateTime($filter_date_from);
+ } else {
+ $date_from = new DateTime('2012-01-01 00:00');
+ }
+
+ if ($filter_date_to) {
+ $date_to = new DateTime($filter_date_to . ' +1 day -1 minute');
+ } else {
+ $date_to = new DateTime('tomorrow -1 minute');
+ }
+
+ $search[] = Braintree_TransactionSearch::createdAt()->between($date_from, $date_to);
+ }
+
+ if ($filter_amount_from) {
+ $amount_from = $filter_amount_from;
+ } else {
+ $amount_from = 0;
+ }
+
+ if ($filter_amount_to) {
+ $amount_to = $filter_amount_to;
+ } else {
+ $amount_to = 9999999;
+ }
+
+ $search[] = Braintree_TransactionSearch::amount()->between((float)$amount_from, (float)$amount_to);
+
+ $transactions = $this->model_extension_payment_pp_braintree->getTransactions($this->gateway, $search);
+
+ if ($transactions) {
+ foreach ($transactions as $transaction) {
+ $customer_url = false;
+
+ if ($transaction->customer['id']) {
+ $braintree_customer_id = explode('_', $transaction->customer['id']);
+
+ if (isset($braintree_customer_id[2]) && is_numeric($braintree_customer_id[2])) {
+ $customer_info = $this->model_customer_customer->getCustomer($braintree_customer_id[2]);
+
+ if ($customer_info && $customer_info['email'] == $transaction->customer['email']) {
+ $customer_url = $this->url->link('sale/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . (int)$braintree_customer_id[2], true);
+ }
+ }
+ }
+
+ $order = false;
+
+ if ($transaction->orderId) {
+ $order_info = $this->model_sale_order->getOrder($transaction->orderId);
+
+ if ($order_info && $order_info['email'] == $transaction->customer['email']) {
+ $order = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$transaction->orderId, true);
+ }
+ }
+
+ $created_at = $transaction->createdAt;
+
+ $json['transactions'][] = array(
+ 'transaction_id' => $transaction->id,
+ 'amount' => $transaction->amount,
+ 'currency_iso' => $transaction->currencyIsoCode,
+ 'status' => $transaction->status,
+ 'type' => $transaction->type,
+ 'merchant_account_id' => $transaction->merchantAccountId,
+ 'customer' => $transaction->customer['firstName'] . ' ' . $transaction->customer['lastName'],
+ 'customer_url' => $customer_url,
+ 'order' => $order,
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e')))
+ );
+ }
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function connectRedirect() {
+ if ($this->user->hasPermission('modify', 'extension/extension/payment')) {
+ // Install the module before doing the redirect
+ $this->load->model('setting/extension');
+
+ $this->model_setting_extension->install('payment', 'pp_braintree');
+
+ $this->install();
+
+ $curl = curl_init($this->opencart_connect_url);
+
+ $this->load->model('localisation/country');
+ $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id'));
+
+ $post_data = array(
+ 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true),
+ 'store_url' => HTTPS_CATALOG,
+ 'store_version' => VERSION,
+ 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''),
+ );
+
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
+ curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
+
+ $curl_response = curl_exec($curl);
+
+ $curl_response = json_decode($curl_response, true);
+
+ curl_close($curl);
+
+ if ($curl_response['url']) {
+ $this->response->redirect($curl_response['url']);
+ } else {
+ $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true));
+ }
+ } else {
+ $this->response->redirect($this->url->link('error/permission', 'user_token=' . $this->session->data['user_token'], true));
+ }
+ }
+
+ public function promotion() {
+ $this->load->language('extension/payment/pp_braintree');
+
+ $data['connect_link'] = '';
+ $data['module_link'] = '';
+
+ if ($this->config->get('payment_pp_braintree_status') || $this->config->get('payment_pp_braintree_merchant_id') || $this->config->get('payment_pp_braintree_access_token')) {
+ $data['module_link'] = $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true);
+ } else {
+ if ($this->user->hasPermission('modify', 'extension/extension/payment')) {
+ $data['connect_link'] = $this->url->link('extension/payment/pp_braintree/connectRedirect', 'user_token=' . $this->session->data['user_token'], true);
+ }
+ }
+
+ if ($this->config->get("payment_pp_braintree_status") == 1) {
+ $data['payment_pp_braintree_status'] = "enabled";
+ } elseif ($this->config->get("payment_pp_braintree_status") == null) {
+ $data['payment_pp_braintree_status'] = "";
+ } else {
+ $data['payment_pp_braintree_status'] = "disabled";
+ }
+
+ return $this->load->view('extension/payment/pp_braintree_promotion', $data);
+ }
+
+ protected function validate() {
+ $this->load->model('extension/payment/pp_braintree');
+
+ $check_credentials = true;
+
+ if (version_compare(phpversion(), '5.4.0', '<')) {
+ $this->error['warning'] = $this->language->get('error_php_version');
+ }
+
+ if (!$this->user->hasPermission('modify', 'extension/payment/pp_braintree')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+
+ $check_credentials = false;
+ }
+
+ if ($check_credentials && $this->request->post['payment_pp_braintree_status'] == 1) {
+ $this->initialise($this->request->post['payment_pp_braintree_access_token'], array(
+ 'payment_pp_braintree_environment' => $this->request->post['payment_pp_braintree_environment'],
+ 'payment_pp_braintree_merchant_id' => $this->request->post['payment_pp_braintree_merchant_id'],
+ 'payment_pp_braintree_public_key' => $this->request->post['payment_pp_braintree_public_key'],
+ 'payment_pp_braintree_private_key' => $this->request->post['payment_pp_braintree_private_key'],
+ ));
+
+ $verify_credentials = $this->model_extension_payment_pp_braintree->verifyCredentials($this->gateway);
+
+ if (!$verify_credentials) {
+ $this->error['warning'] = $this->language->get('error_connection');
+ } else {
+ foreach ($this->request->post['payment_pp_braintree_account'] as $currency => $pp_braintree_account) {
+ if (!empty($pp_braintree_account['merchant_account_id'])) {
+ $verify_merchant_account_id = $this->model_extension_payment_pp_braintree->verifyMerchantAccount($this->gateway, $pp_braintree_account['merchant_account_id']);
+
+ if (!$verify_merchant_account_id) {
+ $this->error['account'][$currency] = $this->language->get('error_account');
+ }
+ }
+ }
+
+ $merchant_config = json_decode(base64_decode($verify_credentials), true);
+
+ // verify the Braintree account is ready to accept 3DS transactions
+ if (isset($merchant_config['threeDSecureEnabled']) && ($this->request->post['payment_pp_braintree_3ds_status'] == 1 && $merchant_config['threeDSecureEnabled'] != 1)) {
+ $this->error['warning'] = $this->language->get('error_3ds_not_ready');
+ }
+
+ // verify the Braintree account is ready to use PayPal Billing Agreements
+ if (isset($merchant_config['paypal']['billingAgreementEnabled']) && ($this->request->post['payment_pp_braintree_billing_agreement'] == 1 && $merchant_config['paypal']['billingAgreementEnabled'] != 1)) {
+ $this->error['warning'] = $this->language->get('error_paypal_billing_not_ready');
+ }
+
+ // verify the Braintree account is ready to accept PayPal transactions
+ if (isset($merchant_config['paypalEnabled']) && ($this->request->post['payment_pp_braintree_paypal_option'] == 1 && $merchant_config['paypalEnabled'] != 1)) {
+ $this->error['warning'] = $this->language->get('error_paypal_not_ready');
+ }
+
+ // verify the environment matches with the token the system is using
+ if (isset($merchant_config['environment']) && ($this->request->post['payment_pp_braintree_environment'] != $merchant_config['environment'])) {
+ $this->error['warning'] = sprintf($this->language->get('error_environment'), $this->request->post['payment_pp_braintree_environment'], $merchant_config['environment']);
+ }
+ }
+ }
+
+ if ($this->error && !isset($this->error['warning'])) {
+ $this->error['warning'] = $this->language->get('error_warning');
+ }
+
+ return !$this->error;
+ }
+
+ private function initialise($access_token = '', $credentials = array()) {
+ $this->load->model('extension/payment/pp_braintree');
+
+ if ($access_token != '') {
+ $this->gateway = $this->model_extension_payment_pp_braintree->setGateway($access_token);
+ } else {
+ Braintree_Configuration::environment(isset($credentials['payment_pp_braintree_environment']) ? $credentials['payment_pp_braintree_environment'] : '');
+ Braintree_Configuration::merchantId(isset($credentials['payment_pp_braintree_merchant_id']) ? $credentials['payment_pp_braintree_merchant_id'] : '');
+ Braintree_Configuration::publicKey(isset($credentials['payment_pp_braintree_public_key']) ? $credentials['payment_pp_braintree_public_key'] : '');
+ Braintree_Configuration::privateKey(isset($credentials['payment_pp_braintree_private_key']) ? $credentials['payment_pp_braintree_private_key'] : '');
+ }
+ }
+}
diff --git a/public/admin/controller/extension/payment/pp_express.php b/public/admin/controller/extension/payment/pp_express.php
new file mode 100644
index 0000000..aed25c0
--- /dev/null
+++ b/public/admin/controller/extension/payment/pp_express.php
@@ -0,0 +1,1347 @@
+<?php
+class ControllerExtensionPaymentPPExpress extends Controller {
+ private $error = array();
+ private $opencart_connect_url = 'https://www.opencart.com/index.php?route=external/paypal_auth/connect';
+ private $opencart_retrieve_url = 'https://www.opencart.com/index.php?route=external/paypal_auth/retrieve';
+
+ public function index() {
+ $this->load->language('extension/payment/pp_express');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_pp_express', $this->request->post);
+
+ // If OC has been upgraded, verify that the module has the new event registered.
+ $this->load->model('setting/event');
+
+ $pp_express_js_event = $this->model_setting_event->getEventByCode("extension_pp_express_checkout_js");
+
+ if (empty($pp_express_js_event)) {
+ // Event is missing, add it
+ $this->model_setting_event->addEvent('extension_pp_express_checkout_js', 'catalog/controller/checkout/checkout/before', 'extension/payment/pp_express/eventLoadCheckoutJs');
+ }
+
+ $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));
+ }
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $data['button_configure'] = $this->url->link('extension/module/pp_button/configure', 'user_token=' . $this->session->data['user_token'], true);
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['username'])) {
+ $data['error_username'] = $this->error['username'];
+ } else {
+ $data['error_username'] = '';
+ }
+
+ if (isset($this->error['password'])) {
+ $data['error_password'] = $this->error['password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ if (isset($this->error['signature'])) {
+ $data['error_signature'] = $this->error['signature'];
+ } else {
+ $data['error_signature'] = '';
+ }
+
+ if (isset($this->error['sandbox_username'])) {
+ $data['error_sandbox_username'] = $this->error['sandbox_username'];
+ } else {
+ $data['error_sandbox_username'] = '';
+ }
+
+ if (isset($this->error['sandbox_password'])) {
+ $data['error_sandbox_password'] = $this->error['sandbox_password'];
+ } else {
+ $data['error_sandbox_password'] = '';
+ }
+
+ if (isset($this->error['sandbox_signature'])) {
+ $data['error_sandbox_signature'] = $this->error['sandbox_signature'];
+ } else {
+ $data['error_sandbox_signature'] = '';
+ }
+
+ $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),
+ );
+
+ $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),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pp_express', '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);
+
+ $data['search'] = $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true);
+
+ if (isset($this->request->post['payment_pp_express_username'])) {
+ $data['payment_pp_express_username'] = $this->request->post['payment_pp_express_username'];
+ } else {
+ $data['payment_pp_express_username'] = $this->config->get('payment_pp_express_username');
+ }
+
+ if (isset($this->request->post['payment_pp_express_password'])) {
+ $data['payment_pp_express_password'] = $this->request->post['payment_pp_express_password'];
+ } else {
+ $data['payment_pp_express_password'] = $this->config->get('payment_pp_express_password');
+ }
+
+ if (isset($this->request->post['payment_pp_express_signature'])) {
+ $data['payment_pp_express_signature'] = $this->request->post['payment_pp_express_signature'];
+ } else {
+ $data['payment_pp_express_signature'] = $this->config->get('payment_pp_express_signature');
+ }
+
+ if (isset($this->request->post['payment_pp_express_sandbox_username'])) {
+ $data['payment_pp_express_sandbox_username'] = $this->request->post['payment_pp_express_sandbox_username'];
+ } else {
+ $data['payment_pp_express_sandbox_username'] = $this->config->get('payment_pp_express_sandbox_username');
+ }
+
+ if (isset($this->request->post['payment_pp_express_sandbox_password'])) {
+ $data['payment_pp_express_sandbox_password'] = $this->request->post['payment_pp_express_sandbox_password'];
+ } else {
+ $data['payment_pp_express_sandbox_password'] = $this->config->get('payment_pp_express_sandbox_password');
+ }
+
+ if (isset($this->request->post['payment_pp_express_sandbox_signature'])) {
+ $data['payment_pp_express_sandbox_signature'] = $this->request->post['payment_pp_express_sandbox_signature'];
+ } else {
+ $data['payment_pp_express_sandbox_signature'] = $this->config->get('payment_pp_express_sandbox_signature');
+ }
+
+ if (isset($this->request->post['payment_pp_express_test'])) {
+ $data['payment_pp_express_test'] = $this->request->post['payment_pp_express_test'];
+ } else {
+ $data['payment_pp_express_test'] = $this->config->get('payment_pp_express_test');
+ }
+
+ if (isset($this->request->post['payment_pp_express_debug'])) {
+ $data['payment_pp_express_debug'] = $this->request->post['payment_pp_express_debug'];
+ } else {
+ $data['payment_pp_express_debug'] = $this->config->get('payment_pp_express_debug');
+ }
+
+ if (isset($this->request->post['payment_pp_express_currency'])) {
+ $data['payment_pp_express_currency'] = $this->request->post['payment_pp_express_currency'];
+ } else {
+ $data['payment_pp_express_currency'] = $this->config->get('payment_pp_express_currency');
+ }
+
+ if (isset($this->request->post['payment_pp_express_recurring_cancel'])) {
+ $data['payment_pp_express_recurring_cancel'] = $this->request->post['payment_pp_express_recurring_cancel'];
+ } else {
+ $data['payment_pp_express_recurring_cancel'] = $this->config->get('payment_pp_express_recurring_cancel');
+ }
+
+ if (isset($this->request->post['payment_pp_express_transaction'])) {
+ $data['payment_pp_express_transaction'] = $this->request->post['payment_pp_express_transaction'];
+ } else {
+ $data['payment_pp_express_transaction'] = $this->config->get('payment_pp_express_transaction');
+ }
+
+ if (isset($this->request->post['payment_pp_express_total'])) {
+ $data['payment_pp_express_total'] = $this->request->post['payment_pp_express_total'];
+ } else {
+ $data['payment_pp_express_total'] = $this->config->get('payment_pp_express_total');
+ }
+
+ if (isset($this->request->post['payment_pp_express_geo_zone_id'])) {
+ $data['payment_pp_express_geo_zone_id'] = $this->request->post['payment_pp_express_geo_zone_id'];
+ } else {
+ $data['payment_pp_express_geo_zone_id'] = $this->config->get('payment_pp_express_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_status'])) {
+ $data['payment_pp_express_status'] = $this->request->post['payment_pp_express_status'];
+ } else {
+ $data['payment_pp_express_status'] = $this->config->get('payment_pp_express_status');
+ }
+
+ if (isset($this->request->post['payment_pp_express_sort_order'])) {
+ $data['payment_pp_express_sort_order'] = $this->request->post['payment_pp_express_sort_order'];
+ } else {
+ $data['payment_pp_express_sort_order'] = $this->config->get('payment_pp_express_sort_order');
+ }
+
+ if (isset($this->request->post['payment_pp_express_canceled_reversal_status_id'])) {
+ $data['payment_pp_express_canceled_reversal_status_id'] = $this->request->post['payment_pp_express_canceled_reversal_status_id'];
+ } else {
+ $data['payment_pp_express_canceled_reversal_status_id'] = $this->config->get('payment_pp_express_canceled_reversal_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_completed_status_id'])) {
+ $data['payment_pp_express_completed_status_id'] = $this->request->post['payment_pp_express_completed_status_id'];
+ } else {
+ $data['payment_pp_express_completed_status_id'] = $this->config->get('payment_pp_express_completed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_denied_status_id'])) {
+ $data['payment_pp_express_denied_status_id'] = $this->request->post['payment_pp_express_denied_status_id'];
+ } else {
+ $data['payment_pp_express_denied_status_id'] = $this->config->get('payment_pp_express_denied_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_expired_status_id'])) {
+ $data['payment_pp_express_expired_status_id'] = $this->request->post['payment_pp_express_expired_status_id'];
+ } else {
+ $data['payment_pp_express_expired_status_id'] = $this->config->get('payment_pp_express_expired_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_failed_status_id'])) {
+ $data['payment_pp_express_failed_status_id'] = $this->request->post['payment_pp_express_failed_status_id'];
+ } else {
+ $data['payment_pp_express_failed_status_id'] = $this->config->get('payment_pp_express_failed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_pending_status_id'])) {
+ $data['payment_pp_express_pending_status_id'] = $this->request->post['payment_pp_express_pending_status_id'];
+ } else {
+ $data['payment_pp_express_pending_status_id'] = $this->config->get('payment_pp_express_pending_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_processed_status_id'])) {
+ $data['payment_pp_express_processed_status_id'] = $this->request->post['payment_pp_express_processed_status_id'];
+ } else {
+ $data['payment_pp_express_processed_status_id'] = $this->config->get('payment_pp_express_processed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_refunded_status_id'])) {
+ $data['payment_pp_express_refunded_status_id'] = $this->request->post['payment_pp_express_refunded_status_id'];
+ } else {
+ $data['payment_pp_express_refunded_status_id'] = $this->config->get('payment_pp_express_refunded_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_reversed_status_id'])) {
+ $data['payment_pp_express_reversed_status_id'] = $this->request->post['payment_pp_express_reversed_status_id'];
+ } else {
+ $data['payment_pp_express_reversed_status_id'] = $this->config->get('payment_pp_express_reversed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_express_voided_status_id'])) {
+ $data['payment_pp_express_voided_status_id'] = $this->request->post['payment_pp_express_voided_status_id'];
+ } else {
+ $data['payment_pp_express_voided_status_id'] = $this->config->get('payment_pp_express_voided_status_id');
+ }
+
+
+
+
+
+
+
+ if (isset($this->request->post['payment_pp_express_style_layout'])) {
+ $data['payment_pp_express_style_layout'] = $this->request->post['payment_pp_express_style_layout'];
+ } else {
+ $data['payment_pp_express_style_layout'] = $this->config->get('payment_pp_express_style_layout');
+ }
+
+ if (isset($this->request->post['payment_pp_express_style_size'])) {
+ $data['payment_pp_express_style_size'] = $this->request->post['payment_pp_express_style_size'];
+ } else {
+ $data['payment_pp_express_style_size'] = $this->config->get('payment_pp_express_style_size');
+ }
+
+ if (isset($this->request->post['payment_pp_express_style_shape'])) {
+ $data['payment_pp_express_style_shape'] = $this->request->post['payment_pp_express_style_shape'];
+ } else {
+ $data['payment_pp_express_style_shape'] = $this->config->get('payment_pp_express_style_shape');
+ }
+
+ if (isset($this->request->post['payment_pp_express_style_color'])) {
+ $data['payment_pp_express_style_color'] = $this->request->post['payment_pp_express_style_color'];
+ } else {
+ $data['payment_pp_express_style_color'] = $this->config->get('payment_pp_express_style_color');
+ }
+
+ if (isset($this->request->post['payment_pp_express_pp_credit'])) {
+ $data['payment_pp_express_pp_credit'] = $this->request->post['payment_pp_express_pp_credit'];
+ } else {
+ // get the store country id from settings - if it is US then pp_credit is defaulted to on.
+ if ($this->config->get('payment_pp_express_pp_credit') == null) {
+ $this->load->model('localisation/country');
+
+ $store_country = $this->model_localisation_country->getCountry($this->config->get('config_country_id'));
+
+ if (!empty($store_country) && $store_country['iso_code_2'] == "US") {
+ $data['payment_pp_express_pp_credit'] = 1;
+ } else {
+ $data['payment_pp_express_pp_credit'] = 0;
+ }
+ } else {
+ $data['payment_pp_express_pp_credit'] = $this->config->get('payment_pp_express_pp_credit');
+ }
+ }
+
+ if (isset($this->request->post['payment_pp_express_pp_cards'])) {
+ $data['payment_pp_express_pp_cards'] = $this->request->post['payment_pp_express_pp_cards'];
+ } else {
+ $data['payment_pp_express_pp_cards'] = $this->config->get('payment_pp_express_pp_cards');
+ }
+
+ if (isset($this->request->post['payment_pp_express_pp_elv'])) {
+ $data['payment_pp_express_pp_elv'] = $this->request->post['payment_pp_express_pp_elv'];
+ } else {
+ $data['payment_pp_express_pp_elv'] = $this->config->get('payment_pp_express_pp_elv');
+ }
+
+ if (isset($this->request->post['payment_pp_express_logo'])) {
+ $data['payment_pp_express_logo'] = $this->request->post['payment_pp_express_logo'];
+ } else {
+ $data['payment_pp_express_logo'] = $this->config->get('payment_pp_express_logo');
+ }
+
+ $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_express/ipn';
+
+ $this->load->model('extension/payment/pp_express');
+ $this->load->model('tool/image');
+ $this->load->model('localisation/geo_zone');
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+ $data['currencies'] = $this->model_extension_payment_pp_express->getCurrencies();
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_pp_express_logo']) && is_file(DIR_IMAGE . $this->request->post['payment_pp_express_logo'])) {
+ $data['thumb'] = $this->model_tool_image->resize($this->request->post['payment_pp_express_logo'], 750, 90);
+ } elseif (is_file(DIR_IMAGE . $this->config->get('payment_pp_express_logo'))) {
+ $data['thumb'] = $this->model_tool_image->resize($this->config->get('payment_pp_express_logo'), 750, 90);
+ } else {
+ $data['thumb'] = $this->model_tool_image->resize('no_image.png', 750, 90);
+ }
+
+ $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 750, 90);
+
+ if (isset($this->request->get['retrieve_code']) && isset($this->request->get['merchant_id'])) {
+ $curl = curl_init($this->opencart_retrieve_url);
+
+ $post_data = array(
+ 'merchant_id' => $this->request->get['merchant_id'],
+ 'retrieve_code' => $this->request->get['retrieve_code'],
+ );
+
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
+ curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
+
+ $curl_response = curl_exec($curl);
+ $config_response = json_decode($curl_response, true);
+ curl_close($curl);
+
+ if (isset($config_response['api_user_name']) && isset($config_response['api_password']) && isset($config_response['signature'])) {
+ $pp_express_settings = $this->model_setting_setting->getSetting('payment_pp_express');
+
+ if ($config_response['environment'] == 'sandbox') {
+ $pp_express_settings['payment_pp_express_sandbox_username'] = $config_response['api_user_name'];
+ $pp_express_settings['payment_pp_express_sandbox_password'] = $config_response['api_password'];
+ $pp_express_settings['payment_pp_express_sandbox_signature'] = $config_response['signature'];
+ $pp_express_settings['payment_pp_express_test'] = 1;
+
+ $data['payment_pp_express_sandbox_username'] = $config_response['api_user_name'];
+ $data['payment_pp_express_sandbox_password'] = $config_response['api_password'];
+ $data['payment_pp_express_sandbox_signature'] = $config_response['signature'];
+ $data['payment_pp_express_test'] = 1;
+ } else {
+ $pp_express_settings['payment_pp_express_username'] = $config_response['api_user_name'];
+ $pp_express_settings['payment_pp_express_password'] = $config_response['api_password'];
+ $pp_express_settings['payment_pp_express_signature'] = $config_response['signature'];
+ $pp_express_settings['payment_pp_express_test'] = 0;
+
+ $data['payment_pp_express_username'] = $config_response['api_user_name'];
+ $data['payment_pp_express_password'] = $config_response['api_password'];
+ $data['payment_pp_express_signature'] = $config_response['signature'];
+ $data['payment_pp_express_test'] = 0;
+ }
+
+ $data['retrieve_success'] = 1;
+ $data['text_retrieve'] = $this->language->get('text_retrieve');
+
+ $this->model_setting_setting->editSetting('payment_pp_express', $pp_express_settings);
+ }
+ }
+
+ $this->load->model('localisation/country');
+
+ $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id'));
+
+ $post_data = array(
+ 'return_url' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true),
+ 'store_url' => HTTPS_CATALOG,
+ 'store_version' => VERSION,
+ 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''),
+ );
+
+ // Create sandbox link
+ $curl = curl_init($this->opencart_connect_url);
+
+ $post_data['environment'] = 'sandbox';
+
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
+ curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
+
+ $curl_response = curl_exec($curl);
+ $curl_response = json_decode($curl_response, true);
+
+ curl_close($curl);
+
+ $data['auth_connect_url_sandbox'] = '';
+ if (isset($curl_response['url']) && !empty($curl_response['url'])) {
+ $data['auth_connect_url_sandbox'] = $curl_response['url'];
+ }
+
+ // Create Live link
+ $curl = curl_init($this->opencart_connect_url);
+
+ $post_data['environment'] = 'live';
+
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
+ curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
+
+ $curl_response = curl_exec($curl);
+ $curl_response = json_decode($curl_response, true);
+
+ curl_close($curl);
+
+ $data['auth_connect_url_live'] = '';
+ if (isset($curl_response['url']) && !empty($curl_response['url'])) {
+ $data['auth_connect_url_live'] = $curl_response['url'];
+ }
+
+ $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/pp_express', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/pp_express')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if ($this->request->post['payment_pp_express_test']) {
+ if (!$this->request->post['payment_pp_express_sandbox_username']) {
+ $this->error['sandbox_username'] = $this->language->get('error_sandbox_username');
+ }
+
+ if (!$this->request->post['payment_pp_express_sandbox_password']) {
+ $this->error['sandbox_password'] = $this->language->get('error_sandbox_password');
+ }
+
+ if (!$this->request->post['payment_pp_express_sandbox_signature']) {
+ $this->error['sandbox_signature'] = $this->language->get('error_sandbox_signature');
+ }
+ } else {
+ if (!$this->request->post['payment_pp_express_username']) {
+ $this->error['username'] = $this->language->get('error_username');
+ }
+
+ if (!$this->request->post['payment_pp_express_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+
+ if (!$this->request->post['payment_pp_express_signature']) {
+ $this->error['signature'] = $this->language->get('error_signature');
+ }
+ }
+
+ return !$this->error;
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/pp_express');
+
+ $this->model_extension_payment_pp_express->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/pp_express');
+
+ $this->model_extension_payment_pp_express->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_pp_express_status')) {
+ $this->load->language('extension/payment/pp_express_order');
+
+ if (isset($this->request->get['order_id'])) {
+ $order_id = $this->request->get['order_id'];
+ } else {
+ $order_id = 0;
+ }
+
+ $this->load->model('extension/payment/pp_express');
+
+ $paypal_info = $this->model_extension_payment_pp_express->getPayPalOrder($order_id);
+
+ if ($paypal_info) {
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['capture_status'] = $paypal_info['capture_status'];
+
+ $data['total'] = $paypal_info['total'];
+
+ $captured = number_format($this->model_extension_payment_pp_express->getCapturedTotal($paypal_info['paypal_order_id']), 2);
+
+ $data['captured'] = $captured;
+
+ $data['capture_remaining'] = number_format($paypal_info['total'] - $captured, 2);
+
+ $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotal($paypal_info['paypal_order_id']), 2);
+
+ $data['refunded'] = $refunded;
+
+ return $this->load->view('extension/payment/pp_express_order', $data);
+ }
+ }
+ }
+
+ public function transaction() {
+ $this->load->language('extension/payment/pp_express_order');
+
+ $data['transactions'] = array();
+
+ if (isset($this->request->get['order_id'])) {
+ $order_id = $this->request->get['order_id'];
+ } else {
+ $order_id = 0;
+ }
+
+ $this->load->model('extension/payment/pp_express');
+
+ $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id);
+
+ if ($paypal_info) {
+ $results = $this->model_extension_payment_pp_express->getTransactions($paypal_info['paypal_order_id']);
+
+ foreach ($results as $result) {
+ $data['transactions'][] = array(
+ 'transaction_id' => $result['transaction_id'],
+ 'amount' => $result['amount'],
+ 'payment_type' => $result['payment_type'],
+ 'payment_status' => $result['payment_status'],
+ 'pending_reason' => $result['pending_reason'],
+ 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])),
+ 'view' => $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $result['transaction_id'], true),
+ 'refund' => $this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $result['transaction_id'], true),
+ 'resend' => $this->url->link('extension/payment/pp_express/resend', 'user_token=' . $this->session->data['user_token'] . '&paypal_order_transaction_id=' . $result['paypal_order_transaction_id'], true)
+ );
+ }
+ }
+
+ $this->response->setOutput($this->load->view('extension/payment/pp_express_transaction', $data));
+ }
+
+ public function capture() {
+ $json = array();
+
+ $this->load->language('extension/payment/pp_express_order');
+
+ if (!isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $json['error'] = $this->language->get('error_capture');
+ }
+
+ if (!$json) {
+ $this->load->model('extension/payment/pp_express');
+
+ if (isset($this->request->get['order_id'])) {
+ $order_id = $this->request->get['order_id'];
+ } else {
+ $order_id = 0;
+ }
+
+ $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id);
+
+ if ($paypal_info) {
+ // If this is the final amount to capture or not
+ if ($this->request->post['complete'] == 1) {
+ $complete = 'Complete';
+ } else {
+ $complete = 'NotComplete';
+ }
+
+ $request = array(
+ 'METHOD' => 'DoCapture',
+ 'AUTHORIZATIONID' => $paypal_info['authorization_id'],
+ 'AMT' => number_format($this->request->post['amount'], 2),
+ 'CURRENCYCODE' => $paypal_info['currency_code'],
+ 'COMPLETETYPE' => $complete,
+ 'MSGSUBID' => uniqid(mt_rand(), true)
+ );
+
+ $response = $this->model_extension_payment_pp_express->call($request);
+
+ if (isset($response['ACK']) && ($response['ACK'] != 'Failure') && ($response['ACK'] != 'FailureWithWarning')) {
+ $transaction_data = array(
+ 'paypal_order_id' => $paypal_info['paypal_order_id'],
+ 'transaction_id' => $response['TRANSACTIONID'],
+ 'parent_id' => $paypal_info['authorization_id'],
+ 'note' => '',
+ 'msgsubid' => $response['MSGSUBID'],
+ 'receipt_id' => '',
+ 'payment_type' => $response['PAYMENTTYPE'],
+ 'payment_status' => $response['PAYMENTSTATUS'],
+ 'pending_reason' => (isset($response['PENDINGREASON']) ? $response['PENDINGREASON'] : ''),
+ 'transaction_entity' => 'payment',
+ 'amount' => $response['AMT'],
+ 'debug_data' => json_encode($response)
+ );
+
+ $this->model_extension_payment_pp_express->addTransaction($transaction_data);
+
+ $captured = number_format($this->model_extension_payment_pp_express->getCapturedTotal($paypal_info['paypal_order_id']), 2);
+ $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotal($paypal_info['paypal_order_id']), 2);
+
+ $json['captured'] = $captured;
+ $json['refunded'] = $refunded;
+ $json['remaining'] = number_format($paypal_info['total'] - $captured, 2);
+
+ if ($this->request->post['complete'] == 1 || $json['remaining'] == 0.00) {
+ $json['capture_status'] = $this->language->get('text_complete');
+
+ $this->model_extension_payment_pp_express->editPayPalOrderStatus($order_id, 'Complete');
+ }
+
+ $json['success'] = $this->language->get('text_success');
+ } else {
+ $json['error'] = (isset($response['L_SHORTMESSAGE0']) ? $response['L_SHORTMESSAGE0'] : $this->language->get('error_transaction'));
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_found');
+ }
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/pp_express_refund');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $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),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_pp_express'),
+ 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ //button actions
+ $data['action'] = $this->url->link('extension/payment/pp_express/doRefund', 'user_token=' . $this->session->data['user_token'], true);
+ $data['cancel'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true);
+
+ $data['transaction_id'] = $this->request->get['transaction_id'];
+
+ $this->load->model('extension/payment/pp_express');
+ $pp_transaction = $this->model_extension_payment_pp_express->getTransaction($this->request->get['transaction_id']);
+
+ $data['amount_original'] = $pp_transaction['AMT'];
+ $data['currency_code'] = $pp_transaction['CURRENCYCODE'];
+
+ $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotalByParentId($this->request->get['transaction_id']), 2);
+
+ if ($refunded != 0.00) {
+ $data['refund_available'] = number_format($data['amount_original'] + $refunded, 2);
+ $data['attention'] = $this->language->get('text_current_refunds') . ': ' . $data['refund_available'];
+ } else {
+ $data['refund_available'] = '';
+ $data['attention'] = '';
+ }
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ if (isset($this->session->data['error'])) {
+ $data['error'] = $this->session->data['error'];
+ unset($this->session->data['error']);
+ } else {
+ $data['error'] = '';
+ }
+
+ $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/pp_express_refund', $data));
+ }
+
+ public function doRefund() {
+ /**
+ * used to issue a refund for a captured payment
+ *
+ * refund can be full or partial
+ */
+ if (isset($this->request->post['transaction_id']) && isset($this->request->post['refund_full'])) {
+
+ $this->load->model('extension/payment/pp_express');
+ $this->load->language('extension/payment/pp_express_refund');
+
+ if ($this->request->post['refund_full'] == 0 && $this->request->post['amount'] == 0) {
+ $this->session->data['error'] = $this->language->get('error_partial_amt');
+ } else {
+ $order_id = $this->model_extension_payment_pp_express->getOrderId($this->request->post['transaction_id']);
+ $paypal_order = $this->model_extension_payment_pp_express->getOrder($order_id);
+
+ if ($paypal_order) {
+ $call_data = array();
+ $call_data['METHOD'] = 'RefundTransaction';
+ $call_data['TRANSACTIONID'] = $this->request->post['transaction_id'];
+ $call_data['NOTE'] = urlencode($this->request->post['refund_message']);
+ $call_data['MSGSUBID'] = uniqid(mt_rand(), true);
+
+ $current_transaction = $this->model_extension_payment_pp_express->getLocalTransaction($this->request->post['transaction_id']);
+
+ if ($this->request->post['refund_full'] == 1) {
+ $call_data['REFUNDTYPE'] = 'Full';
+ } else {
+ $call_data['REFUNDTYPE'] = 'Partial';
+ $call_data['AMT'] = number_format($this->request->post['amount'], 2);
+ $call_data['CURRENCYCODE'] = $this->request->post['currency_code'];
+ }
+
+ $result = $this->model_extension_payment_pp_express->call($call_data);
+
+ $transaction = array(
+ 'paypal_order_id' => $paypal_order['paypal_order_id'],
+ 'transaction_id' => '',
+ 'parent_transaction_id' => $this->request->post['transaction_id'],
+ 'note' => $this->request->post['refund_message'],
+ 'msgsubid' => $call_data['MSGSUBID'],
+ 'receipt_id' => '',
+ 'payment_type' => 'refund',
+ 'payment_status' => 'Refunded',
+ 'transaction_entity' => 'payment',
+ 'pending_reason' => '',
+ 'amount' => '-' . (isset($call_data['AMT']) ? $call_data['AMT'] : $current_transaction['amount']),
+ 'debug_data' => json_encode($result)
+ );
+
+ if ($result == false) {
+ $transaction['payment_status'] = 'Failed';
+ $this->model_extension_payment_pp_express->addTransaction($transaction, $call_data);
+ $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true));
+ } else if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') {
+
+ $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID'];
+ $transaction['pending_reason'] = $result['PENDINGREASON'];
+ $transaction['amount'] = '-' . $result['GROSSREFUNDAMT'];
+
+ $this->model_extension_payment_pp_express->addTransaction($transaction);
+
+ //edit transaction to refunded status
+ if ($result['TOTALREFUNDEDAMOUNT'] == $this->request->post['amount_original']) {
+ $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Refunded' WHERE `transaction_id` = '" . $this->db->escape($this->request->post['transaction_id']) . "' LIMIT 1");
+ } else {
+ $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Partially-Refunded' WHERE `transaction_id` = '" . $this->db->escape($this->request->post['transaction_id']) . "' LIMIT 1");
+ }
+
+ //redirect back to the order
+ $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true));
+ } else {
+ $this->model_extension_payment_pp_express->log(json_encode($result));
+ $this->session->data['error'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error') . (isset($result['L_LONGMESSAGE0']) ? '<br />' . $result['L_LONGMESSAGE0'] : '');
+ $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true));
+ }
+ } else {
+ $this->session->data['error'] = $this->language->get('error_data_missing');
+ $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true));
+ }
+ }
+ } else {
+ $this->session->data['error'] = $this->language->get('error_data');
+ $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true));
+ }
+ }
+
+ /**
+ * used to void an authorised payment
+ */
+ public function void() {
+ $json = array();
+
+ $this->load->language('extension/payment/pp_express_order');
+
+ if (isset($this->request->get['order_id'])) {
+ $order_id = $this->request->get['order_id'];
+ } else {
+ $order_id = 0;
+ }
+
+ $this->load->model('extension/payment/pp_express');
+
+ $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id);
+
+ if ($paypal_info) {
+ $request = array(
+ 'METHOD' => 'DoVoid',
+ 'AUTHORIZATIONID' => $paypal_info['authorization_id'],
+ 'MSGSUBID' => uniqid(mt_rand(), true)
+ );
+
+ $response_info = $this->model_extension_payment_pp_express->call($request);
+
+ if (isset($response_info['ACK']) && ($response_info['ACK'] != 'Failure') && ($response_info['ACK'] != 'FailureWithWarning')) {
+ $transaction = array(
+ 'paypal_order_id' => $paypal_info['paypal_order_id'],
+ 'transaction_id' => '',
+ 'parent_id' => $paypal_info['authorization_id'],
+ 'note' => '',
+ 'msgsubid' => '',
+ 'receipt_id' => '',
+ 'payment_type' => 'void',
+ 'payment_status' => 'Void',
+ 'pending_reason' => '',
+ 'transaction_entity' => 'auth',
+ 'amount' => '',
+ 'debug_data' => json_encode($response_info)
+ );
+
+ $this->model_extension_payment_pp_express->addTransaction($transaction);
+
+ $this->model_extension_payment_pp_express->editPayPalOrderStatus($order_id, 'Complete');
+
+ $json['capture_status'] = 'Complete';
+
+ $json['success'] = $this->language->get('text_success');
+ } else {
+ $json['error'] = (isset($response_info['L_SHORTMESSAGE0']) ? $response_info['L_SHORTMESSAGE0'] : $this->language->get('error_transaction'));
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_found');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ // Cancel an active recurring
+ public function recurringCancel() {
+ $json = array();
+
+ $this->load->language('extension/recurring/pp_express');
+
+ //cancel an active recurring
+ $this->load->model('account/recurring');
+
+ if (isset($this->request->get['order_recurring_id'])) {
+ $order_recurring_id = $this->request->get['order_recurring_id'];
+ } else {
+ $order_recurring_id = 0;
+ }
+
+ $recurring_info = $this->model_account_recurring->getOrderRecurring($order_recurring_id);
+
+ if ($recurring_info && $recurring_info['reference']) {
+ if ($this->config->get('payment_pp_express_test')) {
+ $api_url = 'https://api-3t.sandbox.paypal.com/nvp';
+ $api_username = $this->config->get('payment_pp_express_sandbox_username');
+ $api_password = $this->config->get('payment_pp_express_sandbox_password');
+ $api_signature = $this->config->get('payment_pp_express_sandbox_signature');
+ } else {
+ $api_url = 'https://api-3t.paypal.com/nvp';
+ $api_username = $this->config->get('payment_pp_express_username');
+ $api_password = $this->config->get('payment_pp_express_password');
+ $api_signature = $this->config->get('payment_pp_express_signature');
+ }
+
+ $request = array(
+ 'USER' => $api_username,
+ 'PWD' => $api_password,
+ 'SIGNATURE' => $api_signature,
+ 'VERSION' => '109.0',
+ 'BUTTONSOURCE' => 'OpenCart_2.0_EC',
+ 'METHOD' => 'SetExpressCheckout',
+ 'METHOD' => 'ManageRecurringPaymentsProfileStatus',
+ 'PROFILEID' => $recurring_info['reference'],
+ 'ACTION' => 'Cancel'
+ );
+
+ $curl = curl_init($api_url);
+
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_HEADER, false);
+ curl_setopt($curl, CURLOPT_TIMEOUT, 30);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+
+ $response = curl_exec($curl);
+
+ if (!$response) {
+ $this->log(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl)));
+ }
+
+ curl_close($curl);
+
+ $response_info = array();
+
+ parse_str($response, $response_info);
+
+ if (isset($response_info['PROFILEID'])) {
+ $this->model_account_recurring->editOrderRecurringStatus($order_recurring_id, 4);
+ $this->model_account_recurring->addOrderRecurringTransaction($order_recurring_id, 5);
+
+ $json['success'] = $this->language->get('text_cancelled');
+ } else {
+ $json['error'] = sprintf($this->language->get('error_not_cancelled'), $response_info['L_LONGMESSAGE0']);
+ }
+ } else {
+ $json['error'] = $this->language->get('error_not_found');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function resend() {
+ $json = array();
+
+ $this->load->language('extension/payment/pp_express');
+
+ if (isset($this->request->get['paypal_order_transaction_id'])) {
+ $paypal_order_transaction_id = $this->request->get['paypal_order_transaction_id'];
+ } else {
+ $paypal_order_transaction_id = 0;
+ }
+
+ $this->load->model('extension/payment/pp_express');
+
+ $transaction = $this->model_extension_payment_pp_express->getFailedTransaction($paypal_order_transaction_id);
+
+ if ($transaction) {
+
+ $call_data = json_decode($transaction['call_data'], true);
+
+ $result = $this->model_extension_payment_pp_express->call($call_data);
+
+ if ($result) {
+
+ $parent_transaction = $this->model_extension_payment_pp_express->getLocalTransaction($transaction['parent_id']);
+
+ if ($parent_transaction['amount'] == abs($transaction['amount'])) {
+ $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Refunded' WHERE `transaction_id` = '" . $this->db->escape($transaction['parent_id']) . "' LIMIT 1");
+ } else {
+ $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Partially-Refunded' WHERE `transaction_id` = '" . $this->db->escape($transaction['parent_id']) . "' LIMIT 1");
+ }
+
+ if (isset($result['REFUNDTRANSACTIONID'])) {
+ $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID'];
+ } else {
+ $transaction['transaction_id'] = $result['TRANSACTIONID'];
+ }
+
+ if (isset($result['PAYMENTTYPE'])) {
+ $transaction['payment_type'] = $result['PAYMENTTYPE'];
+ } else {
+ $transaction['payment_type'] = $result['REFUNDSTATUS'];
+ }
+
+ if (isset($result['PAYMENTSTATUS'])) {
+ $transaction['payment_status'] = $result['PAYMENTSTATUS'];
+ } else {
+ $transaction['payment_status'] = 'Refunded';
+ }
+
+ if (isset($result['AMT'])) {
+ $transaction['amount'] = $result['AMT'];
+ } else {
+ $transaction['amount'] = $transaction['amount'];
+ }
+
+ $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : '');
+
+ $this->model_extension_payment_pp_express->updateTransaction($transaction);
+
+ $json['success'] = $this->language->get('success_transaction_resent');
+ } else {
+ $json['error'] = $this->language->get('error_timeout');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_transaction_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function search() {
+ $this->load->language('extension/payment/pp_express_search');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $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),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_pp_express'),
+ 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $this->load->model('extension/payment/pp_express');
+
+ $data['currency_codes'] = $this->model_extension_payment_pp_express->getCurrencies();
+
+ $data['default_currency'] = $this->config->get('payment_pp_express_currency');
+
+ $data['date_start'] = date("Y-m-d", strtotime('-30 days'));
+ $data['date_end'] = date("Y-m-d");
+ $data['view_link'] = $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'], true);
+
+ $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/pp_express_search', $data));
+ }
+
+ public function info() {
+ $this->load->language('extension/payment/pp_express_view');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $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),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_pp_express'),
+ 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->get['transaction_id'], true),
+ );
+
+ $this->load->model('extension/payment/pp_express');
+
+ $data['transaction'] = $this->model_extension_payment_pp_express->getTransaction($this->request->get['transaction_id']);
+ $data['lines'] = $this->formatRows($data['transaction']);
+ $data['view_link'] = $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'], true);
+ $data['cancel'] = $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true);
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $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/pp_express_view', $data));
+ }
+
+ public function doSearch() {
+ /**
+ * used to search for transactions from a user account
+ */
+ if (isset($this->request->post['date_start'])) {
+
+ $this->load->model('extension/payment/pp_express');
+
+ $call_data = array();
+ $call_data['METHOD'] = 'TransactionSearch';
+ $call_data['STARTDATE'] = gmdate($this->request->post['date_start'] . "\TH:i:s\Z");
+
+ if (!empty($this->request->post['date_end'])) {
+ $call_data['ENDDATE'] = gmdate($this->request->post['date_end'] . "\TH:i:s\Z");
+ }
+
+ if (!empty($this->request->post['transaction_class'])) {
+ $call_data['TRANSACTIONCLASS'] = $this->request->post['transaction_class'];
+ }
+
+ if (!empty($this->request->post['status'])) {
+ $call_data['STATUS'] = $this->request->post['status'];
+ }
+
+ if (!empty($this->request->post['buyer_email'])) {
+ $call_data['EMAIL'] = $this->request->post['buyer_email'];
+ }
+
+ if (!empty($this->request->post['merchant_email'])) {
+ $call_data['RECEIVER'] = $this->request->post['merchant_email'];
+ }
+
+ if (!empty($this->request->post['receipt_id'])) {
+ $call_data['RECEIPTID'] = $this->request->post['receipt_id'];
+ }
+
+ if (!empty($this->request->post['transaction_id'])) {
+ $call_data['TRANSACTIONID'] = $this->request->post['transaction_id'];
+ }
+
+ if (!empty($this->request->post['invoice_number'])) {
+ $call_data['INVNUM'] = $this->request->post['invoice_number'];
+ }
+
+ if (!empty($this->request->post['auction_item_number'])) {
+ $call_data['AUCTIONITEMNUMBER'] = $this->request->post['auction_item_number'];
+ }
+
+ if (!empty($this->request->post['amount'])) {
+ $call_data['AMT'] = number_format($this->request->post['amount'], 2);
+ $call_data['CURRENCYCODE'] = $this->request->post['currency_code'];
+ }
+
+ if (!empty($this->request->post['recurring_id'])) {
+ $call_data['PROFILEID'] = $this->request->post['recurring_id'];
+ }
+
+ if (!empty($this->request->post['name_salutation'])) {
+ $call_data['SALUTATION'] = $this->request->post['name_salutation'];
+ }
+
+ if (!empty($this->request->post['name_first'])) {
+ $call_data['FIRSTNAME'] = $this->request->post['name_first'];
+ }
+
+ if (!empty($this->request->post['name_middle'])) {
+ $call_data['MIDDLENAME'] = $this->request->post['name_middle'];
+ }
+
+ if (!empty($this->request->post['name_last'])) {
+ $call_data['LASTNAME'] = $this->request->post['name_last'];
+ }
+
+ if (!empty($this->request->post['name_suffix'])) {
+ $call_data['SUFFIX'] = $this->request->post['name_suffix'];
+ }
+
+ $result = $this->model_extension_payment_pp_express->call($call_data);
+
+ if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning' && $result['ACK'] != 'Warning') {
+ $response['error'] = false;
+ $response['result'] = $this->formatRows($result);
+ } else {
+ $response['error'] = true;
+ $response['error_msg'] = $result['L_LONGMESSAGE0'];
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($response));
+ } else {
+ $response['error'] = true;
+ $response['error_msg'] = 'Enter a start date';
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($response));
+ }
+ }
+
+ public function live() {
+ if (isset($this->request->get['merchantId'])) {
+ $this->load->language('extension/payment/pp_express');
+
+ $this->load->model('extension/payment/pp_express');
+ $this->load->model('setting/setting');
+
+ $token = $this->model_extension_payment_pp_express->getTokens('live');
+
+ if (isset($token->access_token)) {
+ $user_info = $this->model_extension_payment_pp_express->getUserInfo($this->request->get['merchantId'], 'live', $token->access_token);
+ } else {
+ $this->session->data['error_api'] = $this->language->get('error_api');
+ }
+
+ if (isset($user_info->api_user_name)) {
+ $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_username', $user_info->api_user_name);
+ $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_password', $user_info->api_password);
+ $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_signature', $user_info->signature);
+ } else {
+ $this->session->data['error_api'] = $this->language->get('error_api');
+ }
+ }
+
+ $this->response->redirect($this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ public function sandbox() {
+ if (isset($this->request->get['merchantId'])) {
+ $this->load->language('extension/payment/pp_express');
+
+ $this->load->model('extension/payment/pp_express');
+ $this->load->model('setting/setting');
+
+ $token = $this->model_extension_payment_pp_express->getTokens('sandbox');
+
+ if (isset($token->access_token)) {
+ $user_info = $this->model_extension_payment_pp_express->getUserInfo($this->request->get['merchantId'], 'sandbox', $token->access_token);
+ } else {
+ $this->session->data['error_api'] = $this->language->get('error_api_sandbox');
+ }
+
+ if (isset($user_info->api_user_name)) {
+ $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_username', $user_info->api_user_name);
+ $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_password', $user_info->api_password);
+ $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_signature', $user_info->signature);
+ } else {
+ $this->session->data['error_api'] = $this->language->get('error_api_sandbox');
+ }
+ }
+ $this->response->redirect($this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ private function formatRows($data) {
+ $return = array();
+
+ foreach ($data as $k => $v) {
+ $elements = preg_split("/(\d+)/", $k, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
+ if (isset($elements[1]) && isset($elements[0])) {
+ if ($elements[0] == 'L_TIMESTAMP') {
+ $v = str_replace('T', ' ', $v);
+ $v = str_replace('Z', '', $v);
+ }
+ $return[$elements[1]][$elements[0]] = $v;
+ }
+ }
+
+ return $return;
+ }
+
+ public function recurringButtons() {
+ $this->load->model('sale/recurring');
+
+ $recurring = $this->model_sale_recurring->getRecurring($this->request->get['order_recurring_id']);
+
+ $data['buttons'] = array();
+
+ if ($recurring['status'] == 2 || $recurring['status'] == 3) {
+ $data['buttons'][] = array(
+ 'text' => $this->language->get('button_cancel_recurring'),
+ 'link' => $this->url->link('extension/payment/pp_express/recurringCancel', 'order_recurring_id=' . $this->request->get['order_recurring_id'] . '&user_token=' . $this->request->get['user_token'], true)
+ );
+ }
+
+ return $this->load->view('sale/recurring_button', $data);
+ }
+
+ public function connectRedirect() {
+ if ($this->user->hasPermission('modify', 'extension/extension/payment') && $this->user->hasPermission('modify', 'extension/payment/pp_express')) {
+ // Install the module before doing the redirect
+ $this->load->model('setting/extension');
+
+ $this->model_setting_extension->install('payment', 'pp_express');
+
+ $this->install();
+
+ $this->load->model('localisation/country');
+
+ $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id'));
+
+ $post_data = array(
+ 'return_url' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true),
+ 'store_url' => HTTPS_CATALOG,
+ 'store_version' => VERSION,
+ 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''),
+ );
+
+ // Create Live link
+ $curl = curl_init($this->opencart_connect_url);
+
+ $post_data['environment'] = 'live';
+
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
+ curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
+
+ $curl_response = curl_exec($curl);
+ $curl_response = json_decode($curl_response, true);
+
+ curl_close($curl);
+
+ if (isset($curl_response['url']) && !empty($curl_response['url'])) {
+ $this->response->redirect($curl_response['url']);
+ } else {
+ $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true));
+ }
+ } else {
+ $this->response->redirect($this->url->link('error/permission', 'user_token=' . $this->session->data['user_token'], true));
+ }
+ }
+
+ public function promotion() {
+ $this->load->language('extension/payment/pp_express');
+
+ $data['connect_link'] = '';
+ $data['module_link'] = '';
+
+ if ($this->config->get('payment_pp_express_username') || $this->config->get('payment_pp_express_sandbox_username')) {
+ $data['module_link'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true);
+ } else {
+ if ($this->user->hasPermission('modify', 'extension/extension/payment')) {
+ $data['connect_link'] = $this->url->link('extension/payment/pp_express/connectRedirect', 'user_token=' . $this->session->data['user_token'], true);
+ }
+ }
+
+ if ($this->config->get("payment_pp_express_status") == 1) {
+ $data['payment_pp_express_status'] = "enabled";
+ } elseif ($this->config->get("payment_pp_express_status") == null) {
+ $data['payment_pp_express_status'] = "";
+ } else {
+ $data['payment_pp_express_status'] = "disabled";
+ }
+
+ return $this->load->view('extension/payment/pp_express_promotion', $data);
+ }
+}
diff --git a/public/admin/controller/extension/payment/pp_payflow.php b/public/admin/controller/extension/payment/pp_payflow.php
new file mode 100644
index 0000000..92ca1a0
--- /dev/null
+++ b/public/admin/controller/extension/payment/pp_payflow.php
@@ -0,0 +1,177 @@
+<?php
+class ControllerExtensionPaymentPPPayflow extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/pp_payflow');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_pp_payflow', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['vendor'])) {
+ $data['error_vendor'] = $this->error['vendor'];
+ } else {
+ $data['error_vendor'] = '';
+ }
+
+ if (isset($this->error['user'])) {
+ $data['error_user'] = $this->error['user'];
+ } else {
+ $data['error_user'] = '';
+ }
+
+ if (isset($this->error['password'])) {
+ $data['error_password'] = $this->error['password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ if (isset($this->error['partner'])) {
+ $data['error_partner'] = $this->error['partner'];
+ } else {
+ $data['error_partner'] = '';
+ }
+
+ $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),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_pp_express'),
+ 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_payflow', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pp_payflow', '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_pp_payflow_vendor'])) {
+ $data['payment_pp_payflow_vendor'] = $this->request->post['payment_pp_payflow_vendor'];
+ } else {
+ $data['payment_pp_payflow_vendor'] = $this->config->get('payment_pp_payflow_vendor');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_user'])) {
+ $data['payment_pp_payflow_user'] = $this->request->post['payment_pp_payflow_user'];
+ } else {
+ $data['payment_pp_payflow_user'] = $this->config->get('payment_pp_payflow_user');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_password'])) {
+ $data['payment_pp_payflow_password'] = $this->request->post['payment_pp_payflow_password'];
+ } else {
+ $data['payment_pp_payflow_password'] = $this->config->get('payment_pp_payflow_password');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_partner'])) {
+ $data['payment_pp_payflow_partner'] = $this->request->post['payment_pp_payflow_partner'];
+ } elseif ($this->config->has('payment_pp_payflow_partner')) {
+ $data['payment_pp_payflow_partner'] = $this->config->get('payment_pp_payflow_partner');
+ } else {
+ $data['payment_pp_payflow_partner'] = 'PayPal';
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_test'])) {
+ $data['payment_pp_payflow_test'] = $this->request->post['payment_pp_payflow_test'];
+ } else {
+ $data['payment_pp_payflow_test'] = $this->config->get('payment_pp_payflow_test');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_transaction'])) {
+ $data['payment_pp_payflow_transaction'] = $this->request->post['payment_pp_payflow_transaction'];
+ } else {
+ $data['payment_pp_payflow_transaction'] = $this->config->get('payment_pp_payflow_transaction');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_total'])) {
+ $data['payment_pp_payflow_total'] = $this->request->post['payment_pp_payflow_total'];
+ } else {
+ $data['payment_pp_payflow_total'] = $this->config->get('payment_pp_payflow_total');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_order_status_id'])) {
+ $data['payment_pp_payflow_order_status_id'] = $this->request->post['payment_pp_payflow_order_status_id'];
+ } else {
+ $data['payment_pp_payflow_order_status_id'] = $this->config->get('payment_pp_payflow_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_pp_payflow_geo_zone_id'])) {
+ $data['payment_pp_payflow_geo_zone_id'] = $this->request->post['payment_pp_payflow_geo_zone_id'];
+ } else {
+ $data['payment_pp_payflow_geo_zone_id'] = $this->config->get('payment_pp_payflow_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_pp_payflow_status'])) {
+ $data['payment_pp_payflow_status'] = $this->request->post['payment_pp_payflow_status'];
+ } else {
+ $data['payment_pp_payflow_status'] = $this->config->get('payment_pp_payflow_status');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_sort_order'])) {
+ $data['payment_pp_payflow_sort_order'] = $this->request->post['payment_pp_payflow_sort_order'];
+ } else {
+ $data['payment_pp_payflow_sort_order'] = $this->config->get('payment_pp_payflow_sort_order');
+ }
+
+ $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/pp_payflow', $data));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/pp_payflow')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_vendor']) {
+ $this->error['vendor'] = $this->language->get('error_vendor');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_user']) {
+ $this->error['user'] = $this->language->get('error_user');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_partner']) {
+ $this->error['partner'] = $this->language->get('error_partner');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/pp_payflow_iframe.php b/public/admin/controller/extension/payment/pp_payflow_iframe.php
new file mode 100644
index 0000000..635751a
--- /dev/null
+++ b/public/admin/controller/extension/payment/pp_payflow_iframe.php
@@ -0,0 +1,483 @@
+<?php
+class ControllerExtensionPaymentPPPayflowIframe extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/pp_payflow_iframe');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_pp_payflow_iframe', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['vendor'])) {
+ $data['error_vendor'] = $this->error['vendor'];
+ } else {
+ $data['error_vendor'] = '';
+ }
+
+ if (isset($this->error['user'])) {
+ $data['error_user'] = $this->error['user'];
+ } else {
+ $data['error_user'] = '';
+ }
+
+ if (isset($this->error['password'])) {
+ $data['error_password'] = $this->error['password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ if (isset($this->error['partner'])) {
+ $data['error_partner'] = $this->error['partner'];
+ } else {
+ $data['error_partner'] = '';
+ }
+
+ $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),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_pp_express'),
+ 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true),
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pp_payflow_iframe', '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_pp_payflow_iframe_vendor'])) {
+ $data['payment_pp_payflow_iframe_vendor'] = $this->request->post['payment_pp_payflow_iframe_vendor'];
+ } else {
+ $data['payment_pp_payflow_iframe_vendor'] = $this->config->get('payment_pp_payflow_iframe_vendor');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_user'])) {
+ $data['payment_pp_payflow_iframe_user'] = $this->request->post['payment_pp_payflow_iframe_user'];
+ } else {
+ $data['payment_pp_payflow_iframe_user'] = $this->config->get('payment_pp_payflow_iframe_user');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_password'])) {
+ $data['payment_pp_payflow_iframe_password'] = $this->request->post['payment_pp_payflow_iframe_password'];
+ } else {
+ $data['payment_pp_payflow_iframe_password'] = $this->config->get('payment_pp_payflow_iframe_password');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_partner'])) {
+ $data['payment_pp_payflow_iframe_partner'] = $this->request->post['payment_pp_payflow_iframe_partner'];
+ } else {
+ $data['payment_pp_payflow_iframe_partner'] = $this->config->get('payment_pp_payflow_iframe_partner');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_transaction_method'])) {
+ $data['payment_pp_payflow_iframe_transaction_method'] = $this->request->post['payment_pp_payflow_iframe_transaction_method'];
+ } else {
+ $data['payment_pp_payflow_iframe_transaction_method'] = $this->config->get('payment_pp_payflow_iframe_transaction_method');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_test'])) {
+ $data['payment_pp_payflow_iframe_test'] = $this->request->post['payment_pp_payflow_iframe_test'];
+ } else {
+ $data['payment_pp_payflow_iframe_test'] = $this->config->get('payment_pp_payflow_iframe_test');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_total'])) {
+ $data['payment_pp_payflow_iframe_total'] = $this->request->post['payment_pp_payflow_iframe_total'];
+ } else {
+ $data['payment_pp_payflow_iframe_total'] = $this->config->get('payment_pp_payflow_iframe_total');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_order_status_id'])) {
+ $data['payment_pp_payflow_iframe_order_status_id'] = $this->request->post['payment_pp_payflow_iframe_order_status_id'];
+ } else {
+ $data['payment_pp_payflow_iframe_order_status_id'] = $this->config->get('payment_pp_payflow_iframe_order_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_geo_zone_id'])) {
+ $data['payment_pp_payflow_iframe_geo_zone_id'] = $this->request->post['payment_pp_payflow_iframe_geo_zone_id'];
+ } else {
+ $data['payment_pp_payflow_iframe_geo_zone_id'] = $this->config->get('payment_pp_payflow_iframe_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_status'])) {
+ $data['payment_pp_payflow_iframe_status'] = $this->request->post['payment_pp_payflow_iframe_status'];
+ } else {
+ $data['payment_pp_payflow_iframe_status'] = $this->config->get('payment_pp_payflow_iframe_status');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_sort_order'])) {
+ $data['payment_pp_payflow_iframe_sort_order'] = $this->request->post['payment_pp_payflow_iframe_sort_order'];
+ } else {
+ $data['payment_pp_payflow_iframe_sort_order'] = $this->config->get('payment_pp_payflow_iframe_sort_order');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_checkout_method'])) {
+ $data['payment_pp_payflow_iframe_checkout_method'] = $this->request->post['payment_pp_payflow_iframe_checkout_method'];
+ } else {
+ $data['payment_pp_payflow_iframe_checkout_method'] = $this->config->get('payment_pp_payflow_iframe_checkout_method');
+ }
+
+ if (isset($this->request->post['payment_pp_payflow_iframe_debug'])) {
+ $data['payment_pp_payflow_iframe_debug'] = $this->request->post['payment_pp_payflow_iframe_debug'];
+ } else {
+ $data['payment_pp_payflow_iframe_debug'] = $this->config->get('payment_pp_payflow_iframe_debug');
+ }
+
+ $data['post_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentipn';
+ $data['cancel_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentcancel';
+ $data['error_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymenterror';
+ $data['return_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentreturn';
+
+ $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/pp_payflow_iframe', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/pp_payflow_iframe');
+
+ $this->model_extension_payment_pp_payflow_iframe->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/pp_payflow_iframe');
+
+ $this->model_extension_payment_pp_payflow_iframe->uninstall();
+ }
+
+ public function refund() {
+ $this->load->model('extension/payment/pp_payflow_iframe');
+ $this->load->model('sale/order');
+ $this->load->language('extension/payment/pp_payflow_iframe');
+
+ $transaction = $this->model_extension_payment_pp_payflow_iframe->getTransaction($this->request->get['transaction_reference']);
+
+ if ($transaction) {
+ $this->document->setTitle($this->language->get('heading_refund'));
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_extension'),
+ 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_refund'),
+ 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $this->request->get['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['transaction_reference'] = $transaction['transaction_reference'];
+ $data['transaction_amount'] = number_format($transaction['amount'], 2);
+ $data['cancel'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction['order_id'], true);
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $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/pp_payflow_iframe_refund', $data));
+ } else {
+ return $this->forward('error/not_found');
+ }
+ }
+
+ public function doRefund() {
+ $this->load->model('extension/payment/pp_payflow_iframe');
+ $this->load->language('extension/payment/pp_payflow_iframe');
+ $json = array();
+
+ if (isset($this->request->post['transaction_reference']) && isset($this->request->post['amount'])) {
+
+ $transaction = $this->model_extension_payment_pp_payflow_iframe->getTransaction($this->request->post['transaction_reference']);
+
+ if ($transaction) {
+ $call_data = array(
+ 'TRXTYPE' => 'C',
+ 'TENDER' => 'C',
+ 'ORIGID' => $transaction['transaction_reference'],
+ 'AMT' => $this->request->post['amount'],
+ );
+
+ $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data);
+
+ if ($result['RESULT'] == 0) {
+ $json['success'] = $this->language->get('text_refund_issued');
+
+ $data = array(
+ 'order_id' => $transaction['order_id'],
+ 'type' => 'C',
+ 'transaction_reference' => $result['PNREF'],
+ 'amount' => $this->request->post['amount'],
+ );
+
+ $this->model_extension_payment_pp_payflow_iframe->addTransaction($data);
+ } else {
+ $json['error'] = $result['RESPMSG'];
+ }
+ } else {
+ $json['error'] = $this->language->get('error_missing_order');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_missing_data');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->model('extension/payment/pp_payflow_iframe');
+ $this->load->model('sale/order');
+ $this->load->language('extension/payment/pp_payflow_iframe');
+
+ if (isset($this->request->post['order_id']) && isset($this->request->post['amount']) && isset($this->request->post['complete'])) {
+ $order_id = $this->request->post['order_id'];
+ $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id);
+ $paypal_transactions = $this->model_extension_payment_pp_payflow_iframe->getTransactions($order_id);
+ $order_info = $this->model_sale_order->getOrder($order_id);
+
+ if ($paypal_order && $order_info) {
+ if ($this->request->post['complete'] == 1) {
+ $complete = 'Y';
+ } else {
+ $complete = 'N';
+ }
+
+ $call_data = array(
+ 'TRXTYPE' => 'D',
+ 'TENDER' => 'C',
+ 'ORIGID' => $paypal_order['transaction_reference'],
+ 'AMT' => $this->request->post['amount'],
+ 'CAPTURECOMPLETE' => $complete
+ );
+
+ $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data);
+
+ if ($result['RESULT'] == 0) {
+
+ $data = array(
+ 'order_id' => $order_id,
+ 'type' => 'D',
+ 'transaction_reference' => $result['PNREF'],
+ 'amount' => $this->request->post['amount']
+ );
+
+ $this->model_extension_payment_pp_payflow_iframe->addTransaction($data);
+ $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, $this->request->post['complete']);
+
+ $actions = array();
+
+ $actions[] = array(
+ 'title' => $this->language->get('text_capture'),
+ 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $result['PNREF'] . '&user_token=' . $this->session->data['user_token'], true),
+ );
+
+ $json['success'] = array(
+ 'transaction_type' => $this->language->get('text_capture'),
+ 'transaction_reference' => $result['PNREF'],
+ 'time' => date('Y-m-d H:i:s'),
+ 'amount' => number_format($this->request->post['amount'], 2),
+ 'actions' => $actions,
+ );
+ } else {
+ $json['error'] = $result['RESPMSG'];
+ }
+ } else {
+ $json['error'] = $this->language->get('error_missing_order');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_missing_data');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function void() {
+ $this->load->model('extension/payment/pp_payflow_iframe');
+ $this->load->language('extension/payment/pp_payflow_iframe');
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $order_id = $this->request->post['order_id'];
+ $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id);
+
+ if ($paypal_order) {
+ $call_data = array(
+ 'TRXTYPE' => 'V',
+ 'TENDER' => 'C',
+ 'ORIGID' => $paypal_order['transaction_reference'],
+ );
+
+ $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data);
+
+ if ($result['RESULT'] == 0) {
+ $json['success'] = $this->language->get('text_void_success');
+ $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, 1);
+
+ $data = array(
+ 'order_id' => $order_id,
+ 'type' => 'V',
+ 'transaction_reference' => $result['PNREF'],
+ 'amount' => '',
+ );
+
+ $this->model_extension_payment_pp_payflow_iframe->addTransaction($data);
+ $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, 1);
+
+ $json['success'] = array(
+ 'transaction_type' => $this->language->get('text_void'),
+ 'transaction_reference' => $result['PNREF'],
+ 'time' => date('Y-m-d H:i:s'),
+ 'amount' => '0.00',
+ );
+ } else {
+ $json['error'] = $result['RESPMSG'];
+ }
+ } else {
+ $json['error'] = $this->language->get('error_missing_order');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_missing_data');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function order() {
+ $this->load->model('extension/payment/pp_payflow_iframe');
+ $this->load->language('extension/payment/pp_payflow_iframe');
+
+ $order_id = $this->request->get['order_id'];
+
+ $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id);
+
+ if ($paypal_order) {
+ $data['complete'] = $paypal_order['complete'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ $data['transactions'] = array();
+
+ $transactions = $this->model_extension_payment_pp_payflow_iframe->getTransactions($order_id);
+
+ foreach ($transactions as $transaction) {
+ $actions = array();
+
+ switch ($transaction['transaction_type']) {
+ case 'V':
+ $transaction_type = $this->language->get('text_void');
+ break;
+ case 'S':
+ $transaction_type = $this->language->get('text_sale');
+
+ $actions[] = array(
+ 'title' => $this->language->get('text_refund'),
+ 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $transaction['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true),
+ );
+ break;
+ case 'D':
+ $transaction_type = $this->language->get('text_capture');
+
+ $actions[] = array(
+ 'title' => $this->language->get('text_refund'),
+ 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $transaction['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true),
+ );
+ break;
+ case 'A':
+ $transaction_type = $this->language->get('text_authorise');
+ break;
+
+ case 'C':
+ $transaction_type = $this->language->get('text_refund');#
+ break;
+
+ default:
+ $transaction_type = '';
+ break;
+ }
+
+ $data['transactions'][] = array(
+ 'transaction_reference' => $transaction['transaction_reference'],
+ 'transaction_type' => $transaction_type,
+ 'time' => $transaction['time'],
+ 'amount' => $transaction['amount'],
+ 'actions' => $actions
+ );
+ }
+
+ return $this->load->view('extension/payment/pp_payflow_iframe_order', $data);
+ }
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/pp_payflow_iframe')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_iframe_vendor']) {
+ $this->error['vendor'] = $this->language->get('error_vendor');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_iframe_user']) {
+ $this->error['user'] = $this->language->get('error_user');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_iframe_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+
+ if (!$this->request->post['payment_pp_payflow_iframe_partner']) {
+ $this->error['partner'] = $this->language->get('error_partner');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/pp_pro.php b/public/admin/controller/extension/payment/pp_pro.php
new file mode 100644
index 0000000..77ab2d7
--- /dev/null
+++ b/public/admin/controller/extension/payment/pp_pro.php
@@ -0,0 +1,159 @@
+<?php
+class ControllerExtensionPaymentPPPro extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/pp_pro');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_pp_pro', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['username'])) {
+ $data['error_username'] = $this->error['username'];
+ } else {
+ $data['error_username'] = '';
+ }
+
+ if (isset($this->error['password'])) {
+ $data['error_password'] = $this->error['password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ if (isset($this->error['signature'])) {
+ $data['error_signature'] = $this->error['signature'];
+ } else {
+ $data['error_signature'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_pro', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pp_pro', '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_pp_pro_username'])) {
+ $data['payment_pp_pro_username'] = $this->request->post['payment_pp_pro_username'];
+ } else {
+ $data['payment_pp_pro_username'] = $this->config->get('payment_pp_pro_username');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_password'])) {
+ $data['payment_pp_pro_password'] = $this->request->post['payment_pp_pro_password'];
+ } else {
+ $data['payment_pp_pro_password'] = $this->config->get('payment_pp_pro_password');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_signature'])) {
+ $data['payment_pp_pro_signature'] = $this->request->post['payment_pp_pro_signature'];
+ } else {
+ $data['payment_pp_pro_signature'] = $this->config->get('payment_pp_pro_signature');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_test'])) {
+ $data['payment_pp_pro_test'] = $this->request->post['payment_pp_pro_test'];
+ } else {
+ $data['payment_pp_pro_test'] = $this->config->get('payment_pp_pro_test');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_transaction'])) {
+ $data['payment_pp_pro_transaction'] = $this->request->post['payment_pp_pro_transaction'];
+ } else {
+ $data['payment_pp_pro_transaction'] = $this->config->get('payment_pp_pro_transaction');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_total'])) {
+ $data['payment_pp_pro_total'] = $this->request->post['payment_pp_pro_total'];
+ } else {
+ $data['payment_pp_pro_total'] = $this->config->get('payment_pp_pro_total');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_order_status_id'])) {
+ $data['payment_pp_pro_order_status_id'] = $this->request->post['payment_pp_pro_order_status_id'];
+ } else {
+ $data['payment_pp_pro_order_status_id'] = $this->config->get('payment_pp_pro_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_pp_pro_geo_zone_id'])) {
+ $data['payment_pp_pro_geo_zone_id'] = $this->request->post['payment_pp_pro_geo_zone_id'];
+ } else {
+ $data['payment_pp_pro_geo_zone_id'] = $this->config->get('payment_pp_pro_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_pp_pro_status'])) {
+ $data['payment_pp_pro_status'] = $this->request->post['payment_pp_pro_status'];
+ } else {
+ $data['payment_pp_pro_status'] = $this->config->get('payment_pp_pro_status');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_sort_order'])) {
+ $data['payment_pp_pro_sort_order'] = $this->request->post['payment_pp_pro_sort_order'];
+ } else {
+ $data['payment_pp_pro_sort_order'] = $this->config->get('payment_pp_pro_sort_order');
+ }
+
+ $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/pp_pro', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/pp_pro')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_pp_pro_username']) {
+ $this->error['username'] = $this->language->get('error_username');
+ }
+
+ if (!$this->request->post['payment_pp_pro_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+
+ if (!$this->request->post['payment_pp_pro_signature']) {
+ $this->error['signature'] = $this->language->get('error_signature');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/pp_pro_iframe.php b/public/admin/controller/extension/payment/pp_pro_iframe.php
new file mode 100644
index 0000000..489b017
--- /dev/null
+++ b/public/admin/controller/extension/payment/pp_pro_iframe.php
@@ -0,0 +1,771 @@
+<?php
+class ControllerExtensionPaymentPPProIframe extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/pp_pro_iframe');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_pp_pro_iframe', $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));
+ } else {
+ $data['error'] = @$this->error;
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pp_pro_iframe', '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_pp_pro_iframe_sig'])) {
+ $data['payment_pp_pro_iframe_sig'] = $this->request->post['payment_pp_pro_iframe_sig'];
+ } else {
+ $data['payment_pp_pro_iframe_sig'] = $this->config->get('payment_pp_pro_iframe_sig');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_user'])) {
+ $data['payment_pp_pro_iframe_user'] = $this->request->post['payment_pp_pro_iframe_user'];
+ } else {
+ $data['payment_pp_pro_iframe_user'] = $this->config->get('payment_pp_pro_iframe_user');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_password'])) {
+ $data['payment_pp_pro_iframe_password'] = $this->request->post['payment_pp_pro_iframe_password'];
+ } else {
+ $data['payment_pp_pro_iframe_password'] = $this->config->get('payment_pp_pro_iframe_password');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_transaction_method'])) {
+ $data['payment_pp_pro_iframe_transaction_method'] = $this->request->post['payment_pp_pro_iframe_transaction_method'];
+ } else {
+ $data['payment_pp_pro_iframe_transaction_method'] = $this->config->get('payment_pp_pro_iframe_transaction_method');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_test'])) {
+ $data['payment_pp_pro_iframe_test'] = $this->request->post['payment_pp_pro_iframe_test'];
+ } else {
+ $data['payment_pp_pro_iframe_test'] = $this->config->get('payment_pp_pro_iframe_test');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_total'])) {
+ $data['payment_pp_pro_iframe_total'] = $this->request->post['payment_pp_pro_iframe_total'];
+ } else {
+ $data['payment_pp_pro_iframe_total'] = $this->config->get('payment_pp_pro_iframe_total');
+ }
+
+ $this->load->model('localisation/order_status');
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_pp_pro_iframe_canceled_reversal_status_id'])) {
+ $data['payment_pp_pro_iframe_canceled_reversal_status_id'] = $this->request->post['payment_pp_pro_iframe_canceled_reversal_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_canceled_reversal_status_id'] = $this->config->get('payment_pp_pro_iframe_canceled_reversal_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_completed_status_id'])) {
+ $data['payment_pp_pro_iframe_completed_status_id'] = $this->request->post['payment_pp_pro_iframe_completed_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_completed_status_id'] = $this->config->get('payment_pp_pro_iframe_completed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_denied_status_id'])) {
+ $data['payment_pp_pro_iframe_denied_status_id'] = $this->request->post['payment_pp_pro_iframe_denied_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_denied_status_id'] = $this->config->get('payment_pp_pro_iframe_denied_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_expired_status_id'])) {
+ $data['payment_pp_pro_iframe_expired_status_id'] = $this->request->post['payment_pp_pro_iframe_expired_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_expired_status_id'] = $this->config->get('payment_pp_pro_iframe_expired_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_failed_status_id'])) {
+ $data['payment_pp_pro_iframe_failed_status_id'] = $this->request->post['payment_pp_pro_iframe_failed_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_failed_status_id'] = $this->config->get('payment_pp_pro_iframe_failed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_pending_status_id'])) {
+ $data['payment_pp_pro_iframe_pending_status_id'] = $this->request->post['payment_pp_pro_iframe_pending_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_pending_status_id'] = $this->config->get('payment_pp_pro_iframe_pending_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_processed_status_id'])) {
+ $data['payment_pp_pro_iframe_processed_status_id'] = $this->request->post['payment_pp_pro_iframe_processed_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_processed_status_id'] = $this->config->get('payment_pp_pro_iframe_processed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_processed_status_id'])) {
+ $data['payment_pp_pro_iframe_processed_status_id'] = $this->request->post['payment_pp_pro_iframe_processed_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_processed_status_id'] = $this->config->get('payment_pp_pro_iframe_processed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_reversed_status_id'])) {
+ $data['payment_pp_pro_iframe_reversed_status_id'] = $this->request->post['payment_pp_pro_iframe_reversed_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_reversed_status_id'] = $this->config->get('payment_pp_pro_iframe_reversed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_voided_status_id'])) {
+ $data['payment_pp_pro_iframe_voided_status_id'] = $this->request->post['payment_pp_pro_iframe_voided_status_id'];
+ } else {
+ $data['payment_pp_pro_iframe_voided_status_id'] = $this->config->get('payment_pp_pro_iframe_voided_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_geo_zone_id'])) {
+ $data['payment_pp_pro_iframe_geo_zone_id'] = $this->request->post['payment_pp_pro_iframe_geo_zone_id'];
+ } else {
+ $data['payment_pp_pro_iframe_geo_zone_id'] = $this->config->get('payment_pp_pro_iframe_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_pp_pro_iframe_status'])) {
+ $data['payment_pp_pro_iframe_status'] = $this->request->post['payment_pp_pro_iframe_status'];
+ } else {
+ $data['payment_pp_pro_iframe_status'] = $this->config->get('payment_pp_pro_iframe_status');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_sort_order'])) {
+ $data['payment_pp_pro_iframe_sort_order'] = $this->request->post['payment_pp_pro_iframe_sort_order'];
+ } else {
+ $data['payment_pp_pro_iframe_sort_order'] = $this->config->get('payment_pp_pro_iframe_sort_order');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_checkout_method'])) {
+ $data['payment_pp_pro_iframe_checkout_method'] = $this->request->post['payment_pp_pro_iframe_checkout_method'];
+ } else {
+ $data['payment_pp_pro_iframe_checkout_method'] = $this->config->get('payment_pp_pro_iframe_checkout_method');
+ }
+
+ if (isset($this->request->post['payment_pp_pro_iframe_debug'])) {
+ $data['payment_pp_pro_iframe_debug'] = $this->request->post['payment_pp_pro_iframe_debug'];
+ } else {
+ $data['payment_pp_pro_iframe_debug'] = $this->config->get('payment_pp_pro_iframe_debug');
+ }
+
+ $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_pro_iframe/notify';
+
+ $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/pp_pro_iframe', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/pp_pro_iframe');
+
+ $this->model_extension_payment_pp_pro_iframe->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/pp_pro_iframe');
+
+ $this->model_extension_payment_pp_pro_iframe->uninstall();
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/pp_pro_iframe')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_pp_pro_iframe_sig']) {
+ $this->error['sig'] = $this->language->get('error_sig');
+ }
+
+ if (!$this->request->post['payment_pp_pro_iframe_user']) {
+ $this->error['user'] = $this->language->get('error_user');
+ }
+
+ if (!$this->request->post['payment_pp_pro_iframe_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+
+ return !$this->error;
+ }
+
+ public function order() {
+ $this->load->model('extension/payment/pp_pro_iframe');
+ $this->load->language('extension/payment/pp_pro_iframe');
+
+ $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->get['order_id']);
+
+ if ($paypal_order) {
+ $data['paypal_order'] = $paypal_order;
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($data['paypal_order']['paypal_iframe_order_id']), 2);
+ $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($data['paypal_order']['paypal_iframe_order_id']), 2);
+
+ $data['paypal_order']['captured'] = $captured;
+ $data['paypal_order']['refunded'] = $refunded;
+ $data['paypal_order']['remaining'] = number_format($data['paypal_order']['total'] - $captured, 2);
+
+ $data['transactions'] = array();
+
+ $data['view_link'] = $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'], true);
+ $data['refund_link'] = $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'], true);
+ $data['resend_link'] = $this->url->link('extension/payment/pp_pro_iframe/resend', 'user_token=' . $this->session->data['user_token'], true);
+
+ $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($paypal_order['paypal_iframe_order_id']), 2);
+ $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($paypal_order['paypal_iframe_order_id']), 2);
+
+ $data['paypal_order'] = $paypal_order;
+
+ $data['paypal_order']['captured'] = $captured;
+ $data['paypal_order']['refunded'] = $refunded;
+ $data['paypal_order']['remaining'] = number_format($paypal_order['total'] - $captured, 2);
+
+ foreach ($paypal_order['transactions'] as $transaction) {
+ $data['transactions'][] = array(
+ 'paypal_iframe_order_transaction_id' => $transaction['paypal_iframe_order_transaction_id'],
+ 'transaction_id' => $transaction['transaction_id'],
+ 'amount' => $transaction['amount'],
+ 'date_added' => $transaction['date_added'],
+ 'payment_type' => $transaction['payment_type'],
+ 'payment_status' => $transaction['payment_status'],
+ 'pending_reason' => $transaction['pending_reason'],
+ 'view' => $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'] . "&transaction_id=" . $transaction['transaction_id'] . '&order_id=' . $this->request->get['order_id'], true),
+ 'refund' => $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . "&transaction_id=" . $transaction['transaction_id'] . "&order_id=" . $this->request->get['order_id'], true),
+ 'resend' => $this->url->link('extension/payment/pp_pro_iframe/resend', 'user_token=' . $this->session->data['user_token'] . "&paypal_iframe_order_transaction_id=" . $transaction['paypal_iframe_order_transaction_id'], true),
+ );
+ }
+
+ $data['reauthorise_link'] = $this->url->link('extension/payment/pp_pro_iframe/reauthorise', 'user_token=' . $this->session->data['user_token'], true);
+
+ return $this->load->view('extension/payment/pp_pro_iframe_order', $data);
+ }
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/pp_pro_iframe');
+ $this->load->model('extension/payment/pp_pro_iframe');
+
+ $this->document->setTitle($this->language->get('text_refund'));
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_refund'),
+ 'href' => $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ //button actions
+ $data['action'] = $this->url->link('extension/payment/pp_pro_iframe/doRefund', 'user_token=' . $this->session->data['user_token'], true);
+
+ if (isset($this->request->get['order_id'])) {
+ $data['cancel'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true);
+ } else {
+ $data['cancel'] = '';
+ }
+
+ $data['transaction_id'] = $this->request->get['transaction_id'];
+
+ $pp_transaction = $this->model_extension_payment_pp_pro_iframe->getTransaction($this->request->get['transaction_id']);
+
+ $data['amount_original'] = $pp_transaction['AMT'];
+ $data['currency_code'] = $pp_transaction['CURRENCYCODE'];
+
+ $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefundedTransaction($this->request->get['transaction_id']), 2);
+
+ if ($refunded != 0.00) {
+ $data['refund_available'] = number_format($data['amount_original'] + $refunded, 2);
+ $data['attention'] = $this->language->get('text_current_refunds') . ': ' . $data['refund_available'];
+ } else {
+ $data['refund_available'] = '';
+ $data['attention'] = '';
+ }
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ if (isset($this->session->data['error'])) {
+ $data['error'] = $this->session->data['error'];
+ unset($this->session->data['error']);
+ } else {
+ $data['error'] = '';
+ }
+
+ $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/pp_pro_iframe_refund', $data));
+ }
+
+ public function doRefund() {
+ /**
+ * used to issue a refund for a captured payment
+ *
+ * refund can be full or partial
+ */
+ if (isset($this->request->post['transaction_id']) && isset($this->request->post['refund_full'])) {
+
+ $this->load->model('extension/payment/pp_pro_iframe');
+ $this->load->language('extension/payment/pp_pro_iframe');
+
+ if ($this->request->post['refund_full'] == 0 && $this->request->post['amount'] == 0) {
+ $this->session->data['error'] = $this->language->get('error_capture');
+ $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true));
+ } else {
+ $order_id = $this->model_extension_payment_pp_pro_iframe->getOrderId($this->request->post['transaction_id']);
+ $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($order_id);
+
+ if ($paypal_order) {
+ $call_data = array();
+ $call_data['METHOD'] = 'RefundTransaction';
+ $call_data['TRANSACTIONID'] = $this->request->post['transaction_id'];
+ $call_data['NOTE'] = urlencode($this->request->post['refund_message']);
+ $call_data['MSGSUBID'] = uniqid(mt_rand(), true);
+
+ $current_transaction = $this->model_extension_payment_pp_pro_iframe->getLocalTransaction($this->request->post['transaction_id']);
+
+ if ($this->request->post['refund_full'] == 1) {
+ $call_data['REFUNDTYPE'] = 'Full';
+ } else {
+ $call_data['REFUNDTYPE'] = 'Partial';
+ $call_data['AMT'] = number_format($this->request->post['amount'], 2);
+ $call_data['CURRENCYCODE'] = $this->request->post['currency_code'];
+ }
+
+ $result = $this->model_extension_payment_pp_pro_iframe->call($call_data);
+
+ $transaction = array(
+ 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'],
+ 'transaction_id' => '',
+ 'parent_id' => $this->request->post['transaction_id'],
+ 'note' => $this->request->post['refund_message'],
+ 'msgsubid' => $call_data['MSGSUBID'],
+ 'receipt_id' => '',
+ 'payment_type' => '',
+ 'payment_status' => 'Refunded',
+ 'transaction_entity' => 'payment',
+ 'pending_reason' => '',
+ 'amount' => '-' . (isset($call_data['AMT']) ? $call_data['AMT'] : $current_transaction['amount']),
+ 'debug_data' => json_encode($result)
+ );
+
+ if ($result == false) {
+ $transaction['payment_status'] = 'Failed';
+ $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction, $call_data);
+ $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true));
+ } else if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') {
+
+ $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID'];
+ $transaction['payment_type'] = $result['REFUNDSTATUS'];
+ $transaction['pending_reason'] = $result['PENDINGREASON'];
+ $transaction['amount'] = '-' . $result['GROSSREFUNDAMT'];
+
+ $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction);
+
+ if ($result['TOTALREFUNDEDAMOUNT'] == $this->request->post['amount_original']) {
+ $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($this->request->post['transaction_id'], 'Refunded');
+ } else {
+ $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($this->request->post['transaction_id'], 'Partially-Refunded');
+ }
+
+ //redirect back to the order
+ $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true));
+ } else {
+ if ($this->config->get('payment_pp_pro_iframe_debug')) {
+ $log = new Log('pp_pro_iframe.log');
+ $log->write(json_encode($result));
+ }
+
+ $this->session->data['error'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error') . (isset($result['L_LONGMESSAGE0']) ? '<br />' . $result['L_LONGMESSAGE0'] : '');
+ $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true));
+ }
+ } else {
+ $this->session->data['error'] = $this->language->get('error_data_missing');
+ $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true));
+ }
+ }
+ } else {
+ $this->session->data['error'] = $this->language->get('error_data');
+ $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true));
+ }
+ }
+
+ public function reauthorise() {
+ $this->load->language('extension/payment/pp_pro_iframe');
+ $this->load->model('extension/payment/pp_pro_iframe');
+
+ $json = array();
+
+ if (isset($this->request->post['order_id'])) {
+ $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']);
+
+ $call_data = array();
+ $call_data['METHOD'] = 'DoReauthorization';
+ $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id'];
+ $call_data['AMT'] = number_format($paypal_order['total'], 2);
+ $call_data['CURRENCYCODE'] = $paypal_order['currency_code'];
+
+ $result = $this->model_extension_payment_pp_pro_iframe->call($call_data);
+
+ if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') {
+ $this->model_extension_payment_pp_pro_iframe->updateAuthorizationId($paypal_order['paypal_iframe_order_id'], $result['AUTHORIZATIONID']);
+
+ $transaction = array(
+ 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'],
+ 'transaction_id' => '',
+ 'parent_id' => $paypal_order['authorization_id'],
+ 'note' => '',
+ 'msgsubid' => '',
+ 'receipt_id' => '',
+ 'payment_type' => 'instant',
+ 'payment_status' => $result['PAYMENTSTATUS'],
+ 'transaction_entity' => 'auth',
+ 'pending_reason' => $result['PENDINGREASON'],
+ 'amount' => '-' . '',
+ 'debug_data' => json_encode($result)
+ );
+
+ $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction);
+
+ $transaction['date_added'] = date("Y-m-d H:i:s");
+
+ $json['data'] = $transaction;
+ $json['error'] = false;
+ $json['msg'] = 'Ok';
+ } else {
+ $json['error'] = true;
+ $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : $this->language->get('error_general'));
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_missing_data');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function info() {
+ $this->load->model('extension/payment/pp_pro_iframe');
+ $this->load->language('extension/payment/pp_pro_iframe');
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('text_transaction'),
+ 'href' => $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->get['transaction_id'], true)
+ );
+
+ $transaction = $this->model_extension_payment_pp_pro_iframe->getTransaction($this->request->get['transaction_id']);
+ $transaction = array_map('urldecode', $transaction);
+
+ $data['transaction'] = $transaction;
+ $data['view_link'] = $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'], true);
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $this->document->setTitle($this->language->get('text_transaction'));
+
+ if (isset($this->request->get['order_id'])) {
+ $data['back'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true);
+ } else {
+ $data['back'] = '';
+ }
+
+ $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/pp_pro_iframe_transaction', $data));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/pp_pro_iframe');
+ /*
+ * used to capture authorised payments
+ * capture can be full or partial amounts
+ */
+ if (isset($this->request->post['order_id']) && $this->request->post['amount'] > 0 && isset($this->request->post['order_id']) && isset($this->request->post['complete'])) {
+
+ $this->load->model('extension/payment/pp_pro_iframe');
+
+ $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']);
+
+ if ($this->request->post['complete'] == 1) {
+ $complete = 'Complete';
+ } else {
+ $complete = 'NotComplete';
+ }
+
+ $call_data = array();
+ $call_data['METHOD'] = 'DoCapture';
+ $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id'];
+ $call_data['AMT'] = number_format($this->request->post['amount'], 2);
+ $call_data['CURRENCYCODE'] = $paypal_order['currency_code'];
+ $call_data['COMPLETETYPE'] = $complete;
+ $call_data['MSGSUBID'] = uniqid(mt_rand(), true);
+
+ $result = $this->model_extension_payment_pp_pro_iframe->call($call_data);
+
+ $transaction = array(
+ 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'],
+ 'transaction_id' => '',
+ 'parent_id' => $paypal_order['authorization_id'],
+ 'note' => '',
+ 'msgsubid' => $call_data['MSGSUBID'],
+ 'receipt_id' => '',
+ 'payment_type' => '',
+ 'payment_status' => '',
+ 'pending_reason' => '',
+ 'transaction_entity' => 'payment',
+ 'amount' => '',
+ 'debug_data' => json_encode($result)
+ );
+
+ if ($result == false) {
+ $transaction['amount'] = number_format($this->request->post['amount'], 2);
+ $paypal_iframe_order_transaction_id = $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction, $call_data);
+
+ $json['error'] = true;
+
+ $json['failed_transaction']['paypal_iframe_order_transaction_id'] = $paypal_iframe_order_transaction_id;
+ $json['failed_transaction']['amount'] = $transaction['amount'];
+ $json['failed_transaction']['date_added'] = date("Y-m-d H:i:s");
+
+ $json['msg'] = $this->language->get('error_timeout');
+ } else if (isset($result['ACK']) && $result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') {
+ $transaction['transaction_id'] = $result['TRANSACTIONID'];
+ $transaction['payment_type'] = $result['PAYMENTTYPE'];
+ $transaction['payment_status'] = $result['PAYMENTSTATUS'];
+ $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : '');
+ $transaction['amount'] = $result['AMT'];
+
+ $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction);
+
+ unset($transaction['debug_data']);
+ $transaction['date_added'] = date("Y-m-d H:i:s");
+
+ $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($paypal_order['paypal_iframe_order_id']), 2);
+ $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($paypal_order['paypal_iframe_order_id']), 2);
+
+ $transaction['captured'] = $captured;
+ $transaction['refunded'] = $refunded;
+ $transaction['remaining'] = number_format($paypal_order['total'] - $captured, 2);
+
+ $transaction['status'] = 0;
+ if ($transaction['remaining'] == 0.00) {
+ $transaction['status'] = 1;
+ $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']);
+ }
+
+ $transaction['void'] = '';
+
+ if ($this->request->post['complete'] == 1 && $transaction['remaining'] > 0) {
+ $transaction['void'] = array(
+ 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'],
+ 'transaction_id' => '',
+ 'parent_id' => $paypal_order['authorization_id'],
+ 'note' => '',
+ 'msgsubid' => '',
+ 'receipt_id' => '',
+ 'payment_type' => '',
+ 'payment_status' => 'Void',
+ 'pending_reason' => '',
+ 'amount' => '',
+ 'debug_data' => 'Voided after capture',
+ 'transaction_entity' => 'auth',
+ );
+
+ $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction['void']);
+ $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']);
+ $transaction['void']['date_added'] = date("Y-m-d H:i:s");
+ $transaction['status'] = 1;
+ }
+
+ $json['data'] = $transaction;
+ $json['error'] = false;
+ $json['msg'] = 'Ok';
+ } else {
+ $json['error'] = true;
+ $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error');
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/pp_pro_iframe');
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/pp_pro_iframe');
+
+ $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']);
+
+ $call_data = array();
+ $call_data['METHOD'] = 'DoVoid';
+ $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id'];
+
+ $result = $this->model_extension_payment_pp_pro_iframe->call($call_data);
+
+ if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') {
+ $transaction = array(
+ 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'],
+ 'transaction_id' => '',
+ 'parent_id' => $paypal_order['authorization_id'],
+ 'note' => '',
+ 'msgsubid' => '',
+ 'receipt_id' => '',
+ 'payment_type' => 'void',
+ 'payment_status' => 'Void',
+ 'pending_reason' => '',
+ 'transaction_entity' => 'auth',
+ 'amount' => '',
+ 'debug_data' => json_encode($result)
+ );
+
+ $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction);
+ $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']);
+
+ unset($transaction['debug_data']);
+ $transaction['date_added'] = date("Y-m-d H:i:s");
+
+ $json['data'] = $transaction;
+ $json['error'] = false;
+ $json['msg'] = 'Transaction void';
+ } else {
+ $json['error'] = true;
+ $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : $this->language->get('error_general'));
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_missing_data');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function resend() {
+ $this->load->model('extension/payment/pp_pro_iframe');
+ $this->load->language('extension/payment/pp_pro_iframe');
+
+ $json = array();
+
+ if (isset($this->request->get['paypal_iframe_order_transaction_id'])) {
+ $transaction = $this->model_extension_payment_pp_pro_iframe->getFailedTransaction($this->request->get['paypal_iframe_order_transaction_id']);
+
+ if ($transaction) {
+ $call_data = json_decode($transaction['call_data'], true);
+
+ $result = $this->model_extension_payment_pp_pro_iframe->call($call_data);
+
+ if ($result) {
+ $parent_transaction = $this->model_extension_payment_pp_pro_iframe->getLocalTransaction($transaction['parent_id']);
+
+ if ($parent_transaction['amount'] == abs($transaction['amount'])) {
+ $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($transaction['parent_id'], 'Refunded');
+ } else {
+ $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($transaction['parent_id'], 'Partially-Refunded');
+ }
+
+ if (isset($result['REFUNDTRANSACTIONID'])) {
+ $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID'];
+ } else {
+ $transaction['transaction_id'] = $result['TRANSACTIONID'];
+ }
+
+ if (isset($result['PAYMENTTYPE'])) {
+ $transaction['payment_type'] = $result['PAYMENTTYPE'];
+ } else {
+ $transaction['payment_type'] = $result['REFUNDSTATUS'];
+ }
+
+ if (isset($result['PAYMENTSTATUS'])) {
+ $transaction['payment_status'] = $result['PAYMENTSTATUS'];
+ } else {
+ $transaction['payment_status'] = 'Refunded';
+ }
+
+ if (isset($result['AMT'])) {
+ $transaction['amount'] = $result['AMT'];
+ } else {
+ $transaction['amount'] = $transaction['amount'];
+ }
+
+ $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : '');
+
+ $this->model_extension_payment_pp_pro_iframe->updateTransaction($transaction);
+
+ $json['success'] = $this->language->get('success_transaction_resent');
+ } else {
+ $json['error'] = $this->language->get('error_timeout');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_transaction_missing');
+ }
+ } else {
+ $json['error'] = $this->language->get('error_missing_data');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/pp_standard.php b/public/admin/controller/extension/payment/pp_standard.php
new file mode 100644
index 0000000..ba9acd8
--- /dev/null
+++ b/public/admin/controller/extension/payment/pp_standard.php
@@ -0,0 +1,187 @@
+<?php
+class ControllerExtensionPaymentPPStandard extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/pp_standard');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_pp_standard', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['email'])) {
+ $data['error_email'] = $this->error['email'];
+ } else {
+ $data['error_email'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/pp_standard', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/pp_standard', '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_pp_standard_email'])) {
+ $data['payment_pp_standard_email'] = $this->request->post['payment_pp_standard_email'];
+ } else {
+ $data['payment_pp_standard_email'] = $this->config->get('payment_pp_standard_email');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_test'])) {
+ $data['payment_pp_standard_test'] = $this->request->post['payment_pp_standard_test'];
+ } else {
+ $data['payment_pp_standard_test'] = $this->config->get('payment_pp_standard_test');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_transaction'])) {
+ $data['payment_pp_standard_transaction'] = $this->request->post['payment_pp_standard_transaction'];
+ } else {
+ $data['payment_pp_standard_transaction'] = $this->config->get('payment_pp_standard_transaction');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_debug'])) {
+ $data['payment_pp_standard_debug'] = $this->request->post['payment_pp_standard_debug'];
+ } else {
+ $data['payment_pp_standard_debug'] = $this->config->get('payment_pp_standard_debug');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_total'])) {
+ $data['payment_pp_standard_total'] = $this->request->post['payment_pp_standard_total'];
+ } else {
+ $data['payment_pp_standard_total'] = $this->config->get('payment_pp_standard_total');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_canceled_reversal_status_id'])) {
+ $data['payment_pp_standard_canceled_reversal_status_id'] = $this->request->post['payment_pp_standard_canceled_reversal_status_id'];
+ } else {
+ $data['payment_pp_standard_canceled_reversal_status_id'] = $this->config->get('payment_pp_standard_canceled_reversal_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_completed_status_id'])) {
+ $data['payment_pp_standard_completed_status_id'] = $this->request->post['payment_pp_standard_completed_status_id'];
+ } else {
+ $data['payment_pp_standard_completed_status_id'] = $this->config->get('payment_pp_standard_completed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_denied_status_id'])) {
+ $data['payment_pp_standard_denied_status_id'] = $this->request->post['payment_pp_standard_denied_status_id'];
+ } else {
+ $data['payment_pp_standard_denied_status_id'] = $this->config->get('payment_pp_standard_denied_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_expired_status_id'])) {
+ $data['payment_pp_standard_expired_status_id'] = $this->request->post['payment_pp_standard_expired_status_id'];
+ } else {
+ $data['payment_pp_standard_expired_status_id'] = $this->config->get('payment_pp_standard_expired_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_failed_status_id'])) {
+ $data['payment_pp_standard_failed_status_id'] = $this->request->post['payment_pp_standard_failed_status_id'];
+ } else {
+ $data['payment_pp_standard_failed_status_id'] = $this->config->get('payment_pp_standard_failed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_pending_status_id'])) {
+ $data['payment_pp_standard_pending_status_id'] = $this->request->post['payment_pp_standard_pending_status_id'];
+ } else {
+ $data['payment_pp_standard_pending_status_id'] = $this->config->get('payment_pp_standard_pending_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_processed_status_id'])) {
+ $data['payment_pp_standard_processed_status_id'] = $this->request->post['payment_pp_standard_processed_status_id'];
+ } else {
+ $data['payment_pp_standard_processed_status_id'] = $this->config->get('payment_pp_standard_processed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_refunded_status_id'])) {
+ $data['payment_pp_standard_refunded_status_id'] = $this->request->post['payment_pp_standard_refunded_status_id'];
+ } else {
+ $data['payment_pp_standard_refunded_status_id'] = $this->config->get('payment_pp_standard_refunded_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_reversed_status_id'])) {
+ $data['payment_pp_standard_reversed_status_id'] = $this->request->post['payment_pp_standard_reversed_status_id'];
+ } else {
+ $data['payment_pp_standard_reversed_status_id'] = $this->config->get('payment_pp_standard_reversed_status_id');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_voided_status_id'])) {
+ $data['payment_pp_standard_voided_status_id'] = $this->request->post['payment_pp_standard_voided_status_id'];
+ } else {
+ $data['payment_pp_standard_voided_status_id'] = $this->config->get('payment_pp_standard_voided_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_pp_standard_geo_zone_id'])) {
+ $data['payment_pp_standard_geo_zone_id'] = $this->request->post['payment_pp_standard_geo_zone_id'];
+ } else {
+ $data['payment_pp_standard_geo_zone_id'] = $this->config->get('payment_pp_standard_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_pp_standard_status'])) {
+ $data['payment_pp_standard_status'] = $this->request->post['payment_pp_standard_status'];
+ } else {
+ $data['payment_pp_standard_status'] = $this->config->get('payment_pp_standard_status');
+ }
+
+ if (isset($this->request->post['payment_pp_standard_sort_order'])) {
+ $data['payment_pp_standard_sort_order'] = $this->request->post['payment_pp_standard_sort_order'];
+ } else {
+ $data['payment_pp_standard_sort_order'] = $this->config->get('payment_pp_standard_sort_order');
+ }
+
+ $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/pp_standard', $data));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/pp_standard')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_pp_standard_email']) {
+ $this->error['email'] = $this->language->get('error_email');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/realex.php b/public/admin/controller/extension/payment/realex.php
new file mode 100644
index 0000000..e9c7547
--- /dev/null
+++ b/public/admin/controller/extension/payment/realex.php
@@ -0,0 +1,408 @@
+<?php
+class ControllerExtensionPaymentRealex extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/realex');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_realex', $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));
+ }
+
+ $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/realex/notify';
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['error_merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['error_merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['error_secret'])) {
+ $data['error_secret'] = $this->error['error_secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ if (isset($this->error['error_live_url'])) {
+ $data['error_live_url'] = $this->error['error_live_url'];
+ } else {
+ $data['error_live_url'] = '';
+ }
+
+ if (isset($this->error['error_demo_url'])) {
+ $data['error_demo_url'] = $this->error['error_demo_url'];
+ } else {
+ $data['error_demo_url'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/realex', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/realex', '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_realex_merchant_id'])) {
+ $data['payment_realex_merchant_id'] = $this->request->post['payment_realex_merchant_id'];
+ } else {
+ $data['payment_realex_merchant_id'] = $this->config->get('payment_realex_merchant_id');
+ }
+
+ if (isset($this->request->post['payment_realex_secret'])) {
+ $data['payment_realex_secret'] = $this->request->post['payment_realex_secret'];
+ } else {
+ $data['payment_realex_secret'] = $this->config->get('payment_realex_secret');
+ }
+
+ if (isset($this->request->post['payment_realex_rebate_password'])) {
+ $data['payment_realex_rebate_password'] = $this->request->post['payment_realex_rebate_password'];
+ } else {
+ $data['payment_realex_rebate_password'] = $this->config->get('payment_realex_rebate_password');
+ }
+
+ if (isset($this->request->post['payment_realex_live_demo'])) {
+ $data['payment_realex_live_demo'] = $this->request->post['payment_realex_live_demo'];
+ } else {
+ $data['payment_realex_live_demo'] = $this->config->get('payment_realex_live_demo');
+ }
+
+ if (isset($this->request->post['payment_realex_geo_zone_id'])) {
+ $data['payment_realex_geo_zone_id'] = $this->request->post['payment_realex_geo_zone_id'];
+ } else {
+ $data['payment_realex_geo_zone_id'] = $this->config->get('payment_realex_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_realex_total'])) {
+ $data['payment_realex_total'] = $this->request->post['payment_realex_total'];
+ } else {
+ $data['payment_realex_total'] = $this->config->get('payment_realex_total');
+ }
+
+ if (isset($this->request->post['payment_realex_sort_order'])) {
+ $data['payment_realex_sort_order'] = $this->request->post['payment_realex_sort_order'];
+ } else {
+ $data['payment_realex_sort_order'] = $this->config->get('payment_realex_sort_order');
+ }
+
+ if (isset($this->request->post['payment_realex_status'])) {
+ $data['payment_realex_status'] = $this->request->post['payment_realex_status'];
+ } else {
+ $data['payment_realex_status'] = $this->config->get('payment_realex_status');
+ }
+
+ if (isset($this->request->post['payment_realex_debug'])) {
+ $data['payment_realex_debug'] = $this->request->post['payment_realex_debug'];
+ } else {
+ $data['payment_realex_debug'] = $this->config->get('payment_realex_debug');
+ }
+
+ if (isset($this->request->post['payment_realex_account'])) {
+ $data['payment_realex_account'] = $this->request->post['payment_realex_account'];
+ } else {
+ $data['payment_realex_account'] = $this->config->get('payment_realex_account');
+ }
+
+ if (isset($this->request->post['payment_realex_auto_settle'])) {
+ $data['payment_realex_auto_settle'] = $this->request->post['payment_realex_auto_settle'];
+ } else {
+ $data['payment_realex_auto_settle'] = $this->config->get('payment_realex_auto_settle');
+ }
+
+ if (isset($this->request->post['payment_realex_card_select'])) {
+ $data['payment_realex_card_select'] = $this->request->post['payment_realex_card_select'];
+ } else {
+ $data['payment_realex_card_select'] = $this->config->get('payment_realex_card_select');
+ }
+
+ if (isset($this->request->post['payment_realex_tss_check'])) {
+ $data['payment_realex_tss_check'] = $this->request->post['payment_realex_tss_check'];
+ } else {
+ $data['payment_realex_tss_check'] = $this->config->get('payment_realex_tss_check');
+ }
+
+ if (isset($this->request->post['payment_realex_order_status_success_settled_id'])) {
+ $data['payment_realex_order_status_success_settled_id'] = $this->request->post['payment_realex_order_status_success_settled_id'];
+ } else {
+ $data['payment_realex_order_status_success_settled_id'] = $this->config->get('payment_realex_order_status_success_settled_id');
+ }
+
+ if (isset($this->request->post['payment_realex_order_status_success_unsettled_id'])) {
+ $data['payment_realex_order_status_success_unsettled_id'] = $this->request->post['payment_realex_order_status_success_unsettled_id'];
+ } else {
+ $data['payment_realex_order_status_success_unsettled_id'] = $this->config->get('payment_realex_order_status_success_unsettled_id');
+ }
+
+ if (isset($this->request->post['payment_realex_order_status_decline_id'])) {
+ $data['payment_realex_order_status_decline_id'] = $this->request->post['payment_realex_order_status_decline_id'];
+ } else {
+ $data['payment_realex_order_status_decline_id'] = $this->config->get('payment_realex_order_status_decline_id');
+ }
+
+ if (isset($this->request->post['payment_realex_order_status_decline_pending_id'])) {
+ $data['payment_realex_order_status_decline_pending_id'] = $this->request->post['payment_realex_order_status_decline_pending_id'];
+ } else {
+ $data['payment_realex_order_status_decline_pending_id'] = $this->config->get('payment_realex_order_status_decline_pending_id');
+ }
+
+ if (isset($this->request->post['payment_realex_order_status_decline_stolen_id'])) {
+ $data['payment_realex_order_status_decline_stolen_id'] = $this->request->post['payment_realex_order_status_decline_stolen_id'];
+ } else {
+ $data['payment_realex_order_status_decline_stolen_id'] = $this->config->get('payment_realex_order_status_decline_stolen_id');
+ }
+
+ if (isset($this->request->post['payment_realex_order_status_decline_bank_id'])) {
+ $data['payment_realex_order_status_decline_bank_id'] = $this->request->post['payment_realex_order_status_decline_bank_id'];
+ } else {
+ $data['payment_realex_order_status_decline_bank_id'] = $this->config->get('payment_realex_order_status_decline_bank_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_realex_live_url'])) {
+ $data['payment_realex_live_url'] = $this->request->post['payment_realex_live_url'];
+ } else {
+ $data['payment_realex_live_url'] = $this->config->get('payment_realex_live_url');
+ }
+
+ if (empty($data['payment_realex_live_url'])) {
+ $data['payment_realex_live_url'] = 'https://hpp.realexpayments.com/pay';
+ }
+
+ if (isset($this->request->post['payment_realex_demo_url'])) {
+ $data['payment_realex_demo_url'] = $this->request->post['payment_realex_demo_url'];
+ } else {
+ $data['payment_realex_demo_url'] = $this->config->get('payment_realex_demo_url');
+ }
+
+ if (empty($data['payment_realex_demo_url'])) {
+ $data['payment_realex_demo_url'] = 'https://hpp.sandbox.realexpayments.com/pay';
+ }
+
+ $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/realex', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/realex');
+
+ $this->model_extension_payment_realex->install();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_realex_status')) {
+ $this->load->model('extension/payment/realex');
+
+ $realex_order = $this->model_extension_payment_realex->getOrder($this->request->get['order_id']);
+
+ if (!empty($realex_order)) {
+ $this->load->language('extension/payment/realex');
+
+ $realex_order['total_captured'] = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']);
+
+ $realex_order['total_formatted'] = $this->currency->format($realex_order['total'], $realex_order['currency_code'], 1, true);
+ $realex_order['total_captured_formatted'] = $this->currency->format($realex_order['total_captured'], $realex_order['currency_code'], 1, true);
+
+ $data['realex_order'] = $realex_order;
+
+ $data['auto_settle'] = $realex_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/realex_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/realex');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/realex');
+
+ $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_realex->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_realex->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if (isset($void_response->result) && $void_response->result == '00') {
+ $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'void', 0.00);
+ $this->model_extension_payment_realex->updateVoidStatus($realex_order['realex_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/realex');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/realex');
+
+ $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']);
+
+ $capture_response = $this->model_extension_payment_realex->capture($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_realex->logger('Settle result:\r\n' . print_r($capture_response, 1));
+
+ if (isset($capture_response->result) && $capture_response->result == '00') {
+ $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'payment', $this->request->post['amount']);
+
+ $total_captured = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']);
+
+ if ($total_captured >= $realex_order['total'] || $realex_order['settle_type'] == 0) {
+ $this->model_extension_payment_realex->updateCaptureStatus($realex_order['realex_order_id'], 1);
+ $capture_status = 1;
+ $json['msg'] = $this->language->get('text_capture_ok_order');
+ } else {
+ $capture_status = 0;
+ $json['msg'] = $this->language->get('text_capture_ok');
+ }
+
+ $this->model_extension_payment_realex->updateForRebate($realex_order['realex_order_id'], $capture_response->pasref, $capture_response->orderid);
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'];
+ $json['data']['capture_status'] = $capture_status;
+ $json['data']['total'] = (float)$total_captured;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/realex');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/realex');
+
+ $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_realex->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_realex->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if (isset($rebate_response->result) && $rebate_response->result == '00') {
+ $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'rebate', $this->request->post['amount']*-1);
+
+ $total_rebated = $this->model_extension_payment_realex->getTotalRebated($realex_order['realex_order_id']);
+ $total_captured = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']);
+
+ if ($total_captured <= 0 && $realex_order['capture_status'] == 1) {
+ $this->model_extension_payment_realex->updateRebateStatus($realex_order['realex_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount']*-1;
+ $json['data']['total_captured'] = (float)$total_captured;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/realex')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_realex_merchant_id']) {
+ $this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['payment_realex_secret']) {
+ $this->error['error_secret'] = $this->language->get('error_secret');
+ }
+
+ if (!$this->request->post['payment_realex_live_url']) {
+ $this->error['error_live_url'] = $this->language->get('error_live_url');
+ }
+
+ if (!$this->request->post['payment_realex_demo_url']) {
+ $this->error['error_demo_url'] = $this->language->get('error_demo_url');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/realex_remote.php b/public/admin/controller/extension/payment/realex_remote.php
new file mode 100644
index 0000000..43e9e5a
--- /dev/null
+++ b/public/admin/controller/extension/payment/realex_remote.php
@@ -0,0 +1,371 @@
+<?php
+class ControllerExtensionPaymentRealexRemote extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/realex_remote');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_realex_remote', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['error_merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['error_merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['error_secret'])) {
+ $data['error_secret'] = $this->error['error_secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/realex_remote', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/realex_remote', '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_realex_remote_merchant_id'])) {
+ $data['payment_realex_remote_merchant_id'] = $this->request->post['payment_realex_remote_merchant_id'];
+ } else {
+ $data['payment_realex_remote_merchant_id'] = $this->config->get('payment_realex_remote_merchant_id');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_secret'])) {
+ $data['payment_realex_remote_secret'] = $this->request->post['payment_realex_remote_secret'];
+ } else {
+ $data['payment_realex_remote_secret'] = $this->config->get('payment_realex_remote_secret');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_rebate_password'])) {
+ $data['payment_realex_remote_rebate_password'] = $this->request->post['payment_realex_remote_rebate_password'];
+ } else {
+ $data['payment_realex_remote_rebate_password'] = $this->config->get('payment_realex_remote_rebate_password');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_geo_zone_id'])) {
+ $data['payment_realex_remote_geo_zone_id'] = $this->request->post['payment_realex_remote_geo_zone_id'];
+ } else {
+ $data['payment_realex_remote_geo_zone_id'] = $this->config->get('payment_realex_remote_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_realex_remote_total'])) {
+ $data['payment_realex_remote_total'] = $this->request->post['payment_realex_remote_total'];
+ } else {
+ $data['payment_realex_remote_total'] = $this->config->get('payment_realex_remote_total');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_sort_order'])) {
+ $data['payment_realex_remote_sort_order'] = $this->request->post['payment_realex_remote_sort_order'];
+ } else {
+ $data['payment_realex_remote_sort_order'] = $this->config->get('payment_realex_remote_sort_order');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_status'])) {
+ $data['payment_realex_remote_status'] = $this->request->post['payment_realex_remote_status'];
+ } else {
+ $data['payment_realex_remote_status'] = $this->config->get('payment_realex_remote_status');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_card_data_status'])) {
+ $data['payment_realex_remote_card_data_status'] = $this->request->post['payment_realex_remote_card_data_status'];
+ } else {
+ $data['payment_realex_remote_card_data_status'] = $this->config->get('payment_realex_remote_card_data_status');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_debug'])) {
+ $data['payment_realex_remote_debug'] = $this->request->post['payment_realex_remote_debug'];
+ } else {
+ $data['payment_realex_remote_debug'] = $this->config->get('payment_realex_remote_debug');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_account'])) {
+ $data['payment_realex_remote_account'] = $this->request->post['payment_realex_remote_account'];
+ } else {
+ $data['payment_realex_remote_account'] = $this->config->get('payment_realex_remote_account');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_auto_settle'])) {
+ $data['payment_realex_remote_auto_settle'] = $this->request->post['payment_realex_remote_auto_settle'];
+ } else {
+ $data['payment_realex_remote_auto_settle'] = $this->config->get('payment_realex_remote_auto_settle');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_tss_check'])) {
+ $data['payment_realex_remote_tss_check'] = $this->request->post['payment_realex_remote_tss_check'];
+ } else {
+ $data['payment_realex_remote_tss_check'] = $this->config->get('payment_realex_remote_tss_check');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_3d'])) {
+ $data['payment_realex_remote_3d'] = $this->request->post['payment_realex_remote_3d'];
+ } else {
+ $data['payment_realex_remote_3d'] = $this->config->get('payment_realex_remote_3d');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_liability'])) {
+ $data['payment_realex_remote_liability'] = $this->request->post['payment_realex_remote_liability'];
+ } else {
+ $data['payment_realex_remote_liability'] = $this->config->get('payment_realex_remote_liability');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_order_status_success_settled_id'])) {
+ $data['payment_realex_remote_order_status_success_settled_id'] = $this->request->post['payment_realex_remote_order_status_success_settled_id'];
+ } else {
+ $data['payment_realex_remote_order_status_success_settled_id'] = $this->config->get('payment_realex_remote_order_status_success_settled_id');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_order_status_success_unsettled_id'])) {
+ $data['payment_realex_remote_order_status_success_unsettled_id'] = $this->request->post['payment_realex_remote_order_status_success_unsettled_id'];
+ } else {
+ $data['payment_realex_remote_order_status_success_unsettled_id'] = $this->config->get('payment_realex_remote_order_status_success_unsettled_id');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_order_status_decline_id'])) {
+ $data['payment_realex_remote_order_status_decline_id'] = $this->request->post['payment_realex_remote_order_status_decline_id'];
+ } else {
+ $data['payment_realex_remote_order_status_decline_id'] = $this->config->get('payment_realex_remote_order_status_decline_id');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_order_status_decline_pending_id'])) {
+ $data['payment_realex_remote_order_status_decline_pending_id'] = $this->request->post['payment_realex_remote_order_status_decline_pending_id'];
+ } else {
+ $data['payment_realex_remote_order_status_decline_pending_id'] = $this->config->get('payment_realex_remote_order_status_decline_pending_id');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_order_status_decline_stolen_id'])) {
+ $data['payment_realex_remote_order_status_decline_stolen_id'] = $this->request->post['payment_realex_remote_order_status_decline_stolen_id'];
+ } else {
+ $data['payment_realex_remote_order_status_decline_stolen_id'] = $this->config->get('payment_realex_remote_order_status_decline_stolen_id');
+ }
+
+ if (isset($this->request->post['payment_realex_remote_order_status_decline_bank_id'])) {
+ $data['payment_realex_remote_order_status_decline_bank_id'] = $this->request->post['payment_realex_remote_order_status_decline_bank_id'];
+ } else {
+ $data['payment_realex_remote_order_status_decline_bank_id'] = $this->config->get('payment_realex_remote_order_status_decline_bank_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $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/realex_remote', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/realex_remote');
+ $this->model_extension_payment_realex_remote->install();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_realex_remote_status')) {
+ $this->load->model('extension/payment/realex_remote');
+
+ $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->get['order_id']);
+
+ if (!empty($realex_order)) {
+ $this->load->language('extension/payment/realex_remote');
+
+ $realex_order['total_captured'] = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']);
+
+ $realex_order['total_formatted'] = $this->currency->format($realex_order['total'], $realex_order['currency_code'], 1, true);
+ $realex_order['total_captured_formatted'] = $this->currency->format($realex_order['total_captured'], $realex_order['currency_code'], 1, true);
+
+ $data['realex_order'] = $realex_order;
+
+ $data['auto_settle'] = $realex_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/realex_remote_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/realex_remote');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/realex_remote');
+
+ $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_realex_remote->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_realex_remote->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if (isset($void_response->result) && $void_response->result == '00') {
+ $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'void', 0.00);
+ $this->model_extension_payment_realex_remote->updateVoidStatus($realex_order['realex_remote_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function capture() {
+ $this->load->language('extension/payment/realex');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/realex_remote');
+
+ $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']);
+
+ $capture_response = $this->model_extension_payment_realex_remote->capture($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_realex_remote->logger('Settle result:\r\n' . print_r($capture_response, 1));
+
+ if (isset($capture_response->result) && $capture_response->result == '00') {
+ $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'payment', $this->request->post['amount']);
+ $total_captured = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']);
+
+ if ($total_captured >= $realex_order['total'] || $realex_order['settle_type'] == 0) {
+ $this->model_extension_payment_realex_remote->updateCaptureStatus($realex_order['realex_remote_order_id'], 1);
+ $capture_status = 1;
+ $json['msg'] = $this->language->get('text_capture_ok_order');
+ } else {
+ $capture_status = 0;
+ $json['msg'] = $this->language->get('text_capture_ok');
+ }
+
+ $this->model_extension_payment_realex_remote->updateForRebate($realex_order['realex_remote_order_id'], $capture_response->pasref, $capture_response->orderid);
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = (float)$this->request->post['amount'];
+ $json['data']['capture_status'] = $capture_status;
+ $json['data']['total'] = (float)$total_captured;
+ $json['data']['total_formatted'] = $this->currency->format($total_captured, $realex_order['currency_code'], 1, true);
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture';
+
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/realex_remote');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/realex_remote');
+
+ $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_realex_remote->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_realex_remote->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if (isset($rebate_response->result) && $rebate_response->result == '00') {
+ $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'rebate', $this->request->post['amount']*-1);
+
+ $total_rebated = $this->model_extension_payment_realex_remote->getTotalRebated($realex_order['realex_remote_order_id']);
+ $total_captured = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']);
+
+ if ($total_captured <= 0 && $realex_order['capture_status'] == 1) {
+ $this->model_extension_payment_realex_remote->updateRebateStatus($realex_order['realex_remote_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'] * -1;
+ $json['data']['total_captured'] = (float)$total_captured;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/realex_remote')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_realex_remote_merchant_id']) {
+ $this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['payment_realex_remote_secret']) {
+ $this->error['error_secret'] = $this->language->get('error_secret');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/sagepay_direct.php b/public/admin/controller/extension/payment/sagepay_direct.php
new file mode 100644
index 0000000..22c5bbe
--- /dev/null
+++ b/public/admin/controller/extension/payment/sagepay_direct.php
@@ -0,0 +1,327 @@
+<?php
+class ControllerExtensionPaymentSagepayDirect extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/sagepay_direct');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_sagepay_direct', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['vendor'])) {
+ $data['error_vendor'] = $this->error['vendor'];
+ } else {
+ $data['error_vendor'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/sagepay_direct', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/sagepay_direct', '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_sagepay_direct_vendor'])) {
+ $data['payment_sagepay_direct_vendor'] = $this->request->post['payment_sagepay_direct_vendor'];
+ } else {
+ $data['payment_sagepay_direct_vendor'] = $this->config->get('payment_sagepay_direct_vendor');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_password'])) {
+ $data['payment_sagepay_direct_password'] = $this->request->post['payment_sagepay_direct_password'];
+ } else {
+ $data['payment_sagepay_direct_password'] = $this->config->get('payment_sagepay_direct_password');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_test'])) {
+ $data['payment_sagepay_direct_test'] = $this->request->post['payment_sagepay_direct_test'];
+ } else {
+ $data['payment_sagepay_direct_test'] = $this->config->get('payment_sagepay_direct_test');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_transaction'])) {
+ $data['payment_sagepay_direct_transaction'] = $this->request->post['payment_sagepay_direct_transaction'];
+ } else {
+ $data['payment_sagepay_direct_transaction'] = $this->config->get('payment_sagepay_direct_transaction');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_total'])) {
+ $data['payment_sagepay_direct_total'] = $this->request->post['payment_sagepay_direct_total'];
+ } else {
+ $data['payment_sagepay_direct_total'] = $this->config->get('payment_sagepay_direct_total');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_card'])) {
+ $data['payment_sagepay_direct_card'] = $this->request->post['payment_sagepay_direct_card'];
+ } else {
+ $data['payment_sagepay_direct_card'] = $this->config->get('payment_sagepay_direct_card');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_order_status_id'])) {
+ $data['payment_sagepay_direct_order_status_id'] = $this->request->post['payment_sagepay_direct_order_status_id'];
+ } else {
+ $data['payment_sagepay_direct_order_status_id'] = $this->config->get('payment_sagepay_direct_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_sagepay_direct_geo_zone_id'])) {
+ $data['payment_sagepay_direct_geo_zone_id'] = $this->request->post['payment_sagepay_direct_geo_zone_id'];
+ } else {
+ $data['payment_sagepay_direct_geo_zone_id'] = $this->config->get('payment_sagepay_direct_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_sagepay_direct_status'])) {
+ $data['payment_sagepay_direct_status'] = $this->request->post['payment_sagepay_direct_status'];
+ } else {
+ $data['payment_sagepay_direct_status'] = $this->config->get('payment_sagepay_direct_status');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_debug'])) {
+ $data['payment_sagepay_direct_debug'] = $this->request->post['payment_sagepay_direct_debug'];
+ } else {
+ $data['payment_sagepay_direct_debug'] = $this->config->get('payment_sagepay_direct_debug');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_sort_order'])) {
+ $data['payment_sagepay_direct_sort_order'] = $this->request->post['payment_sagepay_direct_sort_order'];
+ } else {
+ $data['payment_sagepay_direct_sort_order'] = $this->config->get('payment_sagepay_direct_sort_order');
+ }
+
+ if (isset($this->request->post['payment_sagepay_direct_cron_job_token'])) {
+ $data['payment_sagepay_direct_cron_job_token'] = $this->request->post['payment_sagepay_direct_cron_job_token'];
+ } elseif ($this->config->get('payment_sagepay_direct_cron_job_token')) {
+ $data['payment_sagepay_direct_cron_job_token'] = $this->config->get('payment_sagepay_direct_cron_job_token');
+ } else {
+ $data['payment_sagepay_direct_cron_job_token'] = sha1(uniqid(mt_rand(), 1));
+ }
+
+ $data['sagepay_direct_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/sagepay_direct/cron&token=' . $data['payment_sagepay_direct_cron_job_token'];
+
+ if ($this->config->get('payment_sagepay_direct_last_cron_job_run')) {
+ $data['payment_sagepay_direct_last_cron_job_run'] = $this->config->get('payment_sagepay_direct_last_cron_job_run');
+ } else {
+ $data['payment_sagepay_direct_last_cron_job_run'] = '';
+ }
+
+ $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/sagepay_direct', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/sagepay_direct');
+ $this->model_extension_payment_sagepay_direct->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/sagepay_direct');
+ $this->model_extension_payment_sagepay_direct->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_sagepay_direct_status')) {
+ $this->load->model('extension/payment/sagepay_direct');
+
+ $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->get['order_id']);
+
+ if (!empty($sagepay_direct_order)) {
+ $this->load->language('extension/payment/sagepay_direct');
+
+ $sagepay_direct_order['total_released'] = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']);
+
+ $sagepay_direct_order['total_formatted'] = $this->currency->format($sagepay_direct_order['total'], $sagepay_direct_order['currency_code'], false, false);
+ $sagepay_direct_order['total_released_formatted'] = $this->currency->format($sagepay_direct_order['total_released'], $sagepay_direct_order['currency_code'], false, false);
+
+ $data['sagepay_direct_order'] = $sagepay_direct_order;
+
+ $data['auto_settle'] = $sagepay_direct_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/sagepay_direct_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/sagepay_direct');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/sagepay_direct');
+
+ $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_sagepay_direct->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_sagepay_direct->logger('Void result', $void_response);
+
+ if ($void_response['Status'] == 'OK') {
+ $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'void', 0.00);
+ $this->model_extension_payment_sagepay_direct->updateVoidStatus($sagepay_direct_order['sagepay_direct_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response['StatuesDetail']) && !empty($void_response['StatuesDetail']) ? (string)$void_response['StatuesDetail'] : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function release() {
+ $this->load->language('extension/payment/sagepay_direct');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/sagepay_direct');
+
+ $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']);
+
+ $release_response = $this->model_extension_payment_sagepay_direct->release($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_sagepay_direct->logger('Release result', $release_response);
+
+ if ($release_response['Status'] == 'OK') {
+ $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'payment', $this->request->post['amount']);
+
+ $total_released = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']);
+
+ if ($total_released >= $sagepay_direct_order['total'] || $sagepay_direct_order['settle_type'] == 0) {
+ $this->model_extension_payment_sagepay_direct->updateReleaseStatus($sagepay_direct_order['sagepay_direct_order_id'], 1);
+ $release_status = 1;
+ $json['msg'] = $this->language->get('text_release_ok_order');
+ } else {
+ $release_status = 0;
+ $json['msg'] = $this->language->get('text_release_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'];
+ $json['data']['release_status'] = $release_status;
+ $json['data']['total'] = (float)$total_released;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($release_response['StatusDetail']) && !empty($release_response['StatusDetail']) ? (string)$release_response['StatusDetail'] : 'Unable to release';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/sagepay_direct');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/sagepay_direct');
+
+ $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_sagepay_direct->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_sagepay_direct->logger('Rebate result', $rebate_response);
+
+ if ($rebate_response['Status'] == 'OK') {
+ $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'rebate', $this->request->post['amount'] * -1);
+
+ $total_rebated = $this->model_extension_payment_sagepay_direct->getTotalRebated($sagepay_direct_order['sagepay_direct_order_id']);
+ $total_released = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']);
+
+ if ($total_released <= 0 && $sagepay_direct_order['release_status'] == 1) {
+ $this->model_extension_payment_sagepay_direct->updateRebateStatus($sagepay_direct_order['sagepay_direct_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'] * -1;
+ $json['data']['total_released'] = (float)$total_released;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response['StatusDetail']) && !empty($rebate_response['StatusDetail']) ? (string)$rebate_response['StatusDetail'] : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_direct')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_sagepay_direct_vendor']) {
+ $this->error['vendor'] = $this->language->get('error_vendor');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/sagepay_server.php b/public/admin/controller/extension/payment/sagepay_server.php
new file mode 100644
index 0000000..6bd0427
--- /dev/null
+++ b/public/admin/controller/extension/payment/sagepay_server.php
@@ -0,0 +1,328 @@
+<?php
+class ControllerExtensionPaymentSagepayServer extends Controller {
+ private $error = array();
+
+ public function index() {
+
+ $this->load->language('extension/payment/sagepay_server');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_sagepay_server', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['vendor'])) {
+ $data['error_vendor'] = $this->error['vendor'];
+ } else {
+ $data['error_vendor'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/sagepay_server', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/sagepay_server', '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_sagepay_server_vendor'])) {
+ $data['payment_sagepay_server_vendor'] = $this->request->post['payment_sagepay_server_vendor'];
+ } else {
+ $data['payment_sagepay_server_vendor'] = $this->config->get('payment_sagepay_server_vendor');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_password'])) {
+ $data['payment_sagepay_server_password'] = $this->request->post['payment_sagepay_server_password'];
+ } else {
+ $data['payment_sagepay_server_password'] = $this->config->get('payment_sagepay_server_password');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_test'])) {
+ $data['payment_sagepay_server_test'] = $this->request->post['payment_sagepay_server_test'];
+ } else {
+ $data['payment_sagepay_server_test'] = $this->config->get('payment_sagepay_server_test');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_transaction'])) {
+ $data['payment_sagepay_server_transaction'] = $this->request->post['payment_sagepay_server_transaction'];
+ } else {
+ $data['payment_sagepay_server_transaction'] = $this->config->get('payment_sagepay_server_transaction');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_total'])) {
+ $data['payment_sagepay_server_total'] = $this->request->post['payment_sagepay_server_total'];
+ } else {
+ $data['payment_sagepay_server_total'] = $this->config->get('payment_sagepay_server_total');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_card'])) {
+ $data['payment_sagepay_server_card'] = $this->request->post['payment_sagepay_server_card'];
+ } else {
+ $data['payment_sagepay_server_card'] = $this->config->get('payment_sagepay_server_card');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_order_status_id'])) {
+ $data['payment_sagepay_server_order_status_id'] = $this->request->post['payment_sagepay_server_order_status_id'];
+ } else {
+ $data['payment_sagepay_server_order_status_id'] = $this->config->get('payment_sagepay_server_order_status_id');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_cron_job_token'])) {
+ $data['payment_sagepay_server_cron_job_token'] = $this->request->post['payment_sagepay_server_cron_job_token'];
+ } elseif ($this->config->get('payment_sagepay_server_cron_job_token')) {
+ $data['payment_sagepay_server_cron_job_token'] = $this->config->get('payment_sagepay_server_cron_job_token');
+ } else {
+ $data['payment_sagepay_server_cron_job_token'] = sha1(uniqid(mt_rand(), 1));
+ }
+
+ $data['sagepay_server_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/sagepay_server/cron&token=' . $data['payment_sagepay_server_cron_job_token'];
+
+ if ($this->config->get('payment_sagepay_server_last_cron_job_run')) {
+ $data['payment_sagepay_server_last_cron_job_run'] = $this->config->get('payment_sagepay_server_last_cron_job_run');
+ } else {
+ $data['payment_sagepay_server_last_cron_job_run'] = '';
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_sagepay_server_geo_zone_id'])) {
+ $data['payment_sagepay_server_geo_zone_id'] = $this->request->post['payment_sagepay_server_geo_zone_id'];
+ } else {
+ $data['payment_sagepay_server_geo_zone_id'] = $this->config->get('payment_sagepay_server_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_sagepay_server_status'])) {
+ $data['payment_sagepay_server_status'] = $this->request->post['payment_sagepay_server_status'];
+ } else {
+ $data['payment_sagepay_server_status'] = $this->config->get('payment_sagepay_server_status');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_debug'])) {
+ $data['payment_sagepay_server_debug'] = $this->request->post['payment_sagepay_server_debug'];
+ } else {
+ $data['payment_sagepay_server_debug'] = $this->config->get('payment_sagepay_server_debug');
+ }
+
+ if (isset($this->request->post['payment_sagepay_server_sort_order'])) {
+ $data['payment_sagepay_server_sort_order'] = $this->request->post['payment_sagepay_server_sort_order'];
+ } else {
+ $data['payment_sagepay_server_sort_order'] = $this->config->get('payment_sagepay_server_sort_order');
+ }
+
+ $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/sagepay_server', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/sagepay_server');
+ $this->model_extension_payment_sagepay_server->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/sagepay_server');
+ $this->model_extension_payment_sagepay_server->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_sagepay_server_status')) {
+ $this->load->model('extension/payment/sagepay_server');
+
+ $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->get['order_id']);
+
+ if (!empty($sagepay_server_order)) {
+ $this->load->language('extension/payment/sagepay_server');
+
+ $sagepay_server_order['total_released'] = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']);
+
+ $sagepay_server_order['total_formatted'] = $this->currency->format($sagepay_server_order['total'], $sagepay_server_order['currency_code'], false, false);
+ $sagepay_server_order['total_released_formatted'] = $this->currency->format($sagepay_server_order['total_released'], $sagepay_server_order['currency_code'], false, false);
+
+ $data['sagepay_server_order'] = $sagepay_server_order;
+
+ $data['auto_settle'] = $sagepay_server_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/sagepay_server_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/sagepay_server');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/sagepay_server');
+
+ $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_sagepay_server->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_sagepay_server->logger('Void result', $void_response);
+
+ if ($void_response['Status'] == 'OK') {
+ $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'void', 0.00);
+ $this->model_extension_payment_sagepay_server->updateVoidStatus($sagepay_server_order['sagepay_server_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_void_ok');
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($void_response['StatuesDetail']) && !empty($void_response['StatuesDetail']) ? (string)$void_response['StatuesDetail'] : 'Unable to void';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function release() {
+ $this->load->language('extension/payment/sagepay_server');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) {
+ $this->load->model('extension/payment/sagepay_server');
+
+ $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']);
+
+ $release_response = $this->model_extension_payment_sagepay_server->release($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_sagepay_server->logger('Release result', $release_response);
+
+ if ($release_response['Status'] == 'OK') {
+ $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'payment', $this->request->post['amount']);
+
+ $total_released = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']);
+
+ if ($total_released >= $sagepay_server_order['total'] || $sagepay_server_order['settle_type'] == 0) {
+ $this->model_extension_payment_sagepay_server->updateReleaseStatus($sagepay_server_order['sagepay_server_order_id'], 1);
+ $release_status = 1;
+ $json['msg'] = $this->language->get('text_release_ok_order');
+ } else {
+ $release_status = 0;
+ $json['msg'] = $this->language->get('text_release_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'];
+ $json['data']['release_status'] = $release_status;
+ $json['data']['total'] = (float)$total_released;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($release_response['StatusDetail']) && !empty($release_response['StatusDetail']) ? (string)$release_response['StatusDetail'] : 'Unable to release';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/sagepay_server');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/sagepay_server');
+
+ $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']);
+
+ $rebate_response = $this->model_extension_payment_sagepay_server->rebate($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_sagepay_server->logger('Rebate result', $rebate_response);
+
+ if ($rebate_response['Status'] == 'OK') {
+ $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'rebate', $this->request->post['amount'] * -1);
+
+ $total_rebated = $this->model_extension_payment_sagepay_server->getTotalRebated($sagepay_server_order['sagepay_server_order_id']);
+ $total_released = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']);
+
+ if ($total_released <= 0 && $sagepay_server_order['release_status'] == 1) {
+ $this->model_extension_payment_sagepay_server->updateRebateStatus($sagepay_server_order['sagepay_server_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['date_added'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->request->post['amount'] * -1;
+ $json['data']['total_released'] = (float)$total_released;
+ $json['data']['total_rebated'] = (float)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($rebate_response['StatusDetail']) && !empty($rebate_response['StatusDetail']) ? (string)$rebate_response['StatusDetail'] : 'Unable to rebate';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_server')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_sagepay_server_vendor']) {
+ $this->error['vendor'] = $this->language->get('error_vendor');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/sagepay_us.php b/public/admin/controller/extension/payment/sagepay_us.php
new file mode 100644
index 0000000..1a92ba7
--- /dev/null
+++ b/public/admin/controller/extension/payment/sagepay_us.php
@@ -0,0 +1,131 @@
+<?php
+class ControllerExtensionPaymentSagepayUS extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/sagepay_us');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_sagepay_us', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['merchant_id'])) {
+ $data['error_merchant_id'] = $this->error['merchant_id'];
+ } else {
+ $data['error_merchant_id'] = '';
+ }
+
+ if (isset($this->error['merchant_key'])) {
+ $data['error_merchant_key'] = $this->error['merchant_key'];
+ } else {
+ $data['error_merchant_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/sagepay_us', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/sagepay_us', '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_sagepay_us_merchant_id'])) {
+ $data['payment_sagepay_us_merchant_id'] = $this->request->post['payment_sagepay_us_merchant_id'];
+ } else {
+ $data['payment_sagepay_us_merchant_id'] = $this->config->get('payment_sagepay_us_merchant_id');
+ }
+
+ if (isset($this->request->post['payment_sagepay_us_merchant_key'])) {
+ $data['payment_sagepay_us_merchant_key'] = $this->request->post['payment_sagepay_us_merchant_key'];
+ } else {
+ $data['payment_sagepay_us_merchant_key'] = $this->config->get('payment_sagepay_us_merchant_key');
+ }
+
+ if (isset($this->request->post['payment_sagepay_us_total'])) {
+ $data['payment_sagepay_us_total'] = $this->request->post['payment_sagepay_us_total'];
+ } else {
+ $data['payment_sagepay_us_total'] = $this->config->get('payment_sagepay_us_total');
+ }
+
+ if (isset($this->request->post['payment_sagepay_us_order_status_id'])) {
+ $data['payment_sagepay_us_order_status_id'] = $this->request->post['payment_sagepay_us_order_status_id'];
+ } else {
+ $data['payment_sagepay_us_order_status_id'] = $this->config->get('payment_sagepay_us_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_sagepay_us_geo_zone_id'])) {
+ $data['payment_sagepay_us_geo_zone_id'] = $this->request->post['payment_sagepay_us_geo_zone_id'];
+ } else {
+ $data['payment_sagepay_us_geo_zone_id'] = $this->config->get('payment_sagepay_us_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_sagepay_us_status'])) {
+ $data['payment_sagepay_us_status'] = $this->request->post['payment_sagepay_us_status'];
+ } else {
+ $data['payment_sagepay_us_status'] = $this->config->get('payment_sagepay_us_status');
+ }
+
+ if (isset($this->request->post['payment_sagepay_us_sort_order'])) {
+ $data['payment_sagepay_us_sort_order'] = $this->request->post['payment_sagepay_us_sort_order'];
+ } else {
+ $data['payment_sagepay_us_sort_order'] = $this->config->get('payment_sagepay_us_sort_order');
+ }
+
+ $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/sagepay_us', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_us')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_sagepay_us_merchant_id']) {
+ $this->error['merchant_id'] = $this->language->get('error_merchant_id');
+ }
+
+ if (!$this->request->post['payment_sagepay_us_merchant_key']) {
+ $this->error['merchant_key'] = $this->language->get('error_merchant_key');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/securetrading_pp.php b/public/admin/controller/extension/payment/securetrading_pp.php
new file mode 100644
index 0000000..de4850c
--- /dev/null
+++ b/public/admin/controller/extension/payment/securetrading_pp.php
@@ -0,0 +1,475 @@
+<?php
+class ControllerExtensionPaymentSecureTradingPp extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->model('setting/setting');
+ $this->load->model('localisation/geo_zone');
+ $this->load->model('localisation/order_status');
+ $this->load->language('extension/payment/securetrading_pp');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->request->post['payment_securetrading_pp_site_reference'] = trim($this->request->post['payment_securetrading_pp_site_reference']);
+
+ $this->model_setting_setting->editSetting('payment_securetrading_pp', $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));
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_site_reference'])) {
+ $data['payment_securetrading_pp_site_reference'] = $this->request->post['payment_securetrading_pp_site_reference'];
+ } else {
+ $data['payment_securetrading_pp_site_reference'] = $this->config->get('payment_securetrading_pp_site_reference');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_username'])) {
+ $data['payment_securetrading_pp_username'] = $this->request->post['payment_securetrading_pp_username'];
+ } else {
+ $data['payment_securetrading_pp_username'] = $this->config->get('payment_securetrading_pp_username');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_password'])) {
+ $data['payment_securetrading_pp_password'] = $this->request->post['payment_securetrading_pp_password'];
+ } else {
+ $data['payment_securetrading_pp_password'] = $this->config->get('payment_securetrading_pp_password');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_notification_password'])) {
+ $data['payment_securetrading_pp_notification_password'] = $this->request->post['payment_securetrading_pp_notification_password'];
+ } else {
+ $data['payment_securetrading_pp_notification_password'] = $this->config->get('payment_securetrading_pp_notification_password');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_site_security_password'])) {
+ $data['payment_securetrading_pp_site_security_password'] = $this->request->post['payment_securetrading_pp_site_security_password'];
+ } else {
+ $data['payment_securetrading_pp_site_security_password'] = $this->config->get('payment_securetrading_pp_site_security_password');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_site_security_status'])) {
+ $data['payment_securetrading_pp_site_security_status'] = $this->request->post['payment_securetrading_pp_site_security_status'];
+ } else {
+ $data['payment_securetrading_pp_site_security_status'] = $this->config->get('payment_securetrading_pp_site_security_status');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_webservice_username'])) {
+ $data['payment_securetrading_pp_webservice_username'] = $this->request->post['payment_securetrading_pp_webservice_username'];
+ } else {
+ $data['payment_securetrading_pp_webservice_username'] = $this->config->get('payment_securetrading_pp_webservice_username');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_webservice_password'])) {
+ $data['payment_securetrading_pp_webservice_password'] = $this->request->post['payment_securetrading_pp_webservice_password'];
+ } else {
+ $data['payment_securetrading_pp_webservice_password'] = $this->config->get('payment_securetrading_pp_webservice_password');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_order_status_id'])) {
+ $data['payment_securetrading_pp_order_status_id'] = $this->request->post['payment_securetrading_pp_order_status_id'];
+ } elseif($this->config->get('payment_securetrading_pp_order_status_id') != '') {
+ $data['payment_securetrading_pp_order_status_id'] = $this->config->get('payment_securetrading_pp_order_status_id');
+ } else {
+ $data['payment_securetrading_pp_order_status_id'] = 1;
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_declined_order_status_id'])) {
+ $data['payment_securetrading_pp_declined_order_status_id'] = $this->request->post['payment_securetrading_pp_declined_order_status_id'];
+ } elseif($this->config->get('payment_securetrading_pp_declined_order_status_id') != '') {
+ $data['payment_securetrading_pp_declined_order_status_id'] = $this->config->get('payment_securetrading_pp_declined_order_status_id');
+ } else {
+ $data['payment_securetrading_pp_declined_order_status_id'] = 8;
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_refunded_order_status_id'])) {
+ $data['payment_securetrading_pp_refunded_order_status_id'] = $this->request->post['payment_securetrading_pp_refunded_order_status_id'];
+ } elseif($this->config->get('payment_securetrading_pp_refunded_order_status_id') != '') {
+ $data['payment_securetrading_pp_refunded_order_status_id'] = $this->config->get('payment_securetrading_pp_refunded_order_status_id');
+ } else {
+ $data['payment_securetrading_pp_refunded_order_status_id'] = 11;
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_authorisation_reversed_order_status_id'])) {
+ $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = $this->request->post['payment_securetrading_pp_authorisation_reversed_order_status_id'];
+ } elseif($this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id') != '') {
+ $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = $this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id');
+ } else {
+ $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = 12;
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_settle_status'])) {
+ $data['payment_securetrading_pp_settle_status'] = $this->request->post['payment_securetrading_pp_settle_status'];
+ } else {
+ $data['payment_securetrading_pp_settle_status'] = $this->config->get('payment_securetrading_pp_settle_status');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_settle_due_date'])) {
+ $data['payment_securetrading_pp_settle_due_date'] = $this->request->post['payment_securetrading_pp_settle_due_date'];
+ } else {
+ $data['payment_securetrading_pp_settle_due_date'] = $this->config->get('payment_securetrading_pp_settle_due_date');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_geo_zone_id'])) {
+ $data['payment_securetrading_pp_geo_zone_id'] = $this->request->post['payment_securetrading_pp_geo_zone_id'];
+ } else {
+ $data['payment_securetrading_pp_geo_zone_id'] = $this->config->get('payment_securetrading_pp_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_status'])) {
+ $data['payment_securetrading_pp_status'] = $this->request->post['payment_securetrading_pp_status'];
+ } else {
+ $data['payment_securetrading_pp_status'] = $this->config->get('payment_securetrading_pp_status');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_sort_order'])) {
+ $data['payment_securetrading_pp_sort_order'] = $this->request->post['payment_securetrading_pp_sort_order'];
+ } else {
+ $data['payment_securetrading_pp_sort_order'] = $this->config->get('payment_securetrading_pp_sort_order');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_total'])) {
+ $data['payment_securetrading_pp_total'] = $this->request->post['payment_securetrading_pp_total'];
+ } else {
+ $data['payment_securetrading_pp_total'] = $this->config->get('payment_securetrading_pp_total');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_parent_css'])) {
+ $data['payment_securetrading_pp_parent_css'] = $this->request->post['payment_securetrading_pp_parent_css'];
+ } else {
+ $data['payment_securetrading_pp_parent_css'] = $this->config->get('payment_securetrading_pp_parent_css');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_child_css'])) {
+ $data['payment_securetrading_pp_child_css'] = $this->request->post['payment_securetrading_pp_child_css'];
+ } else {
+ $data['payment_securetrading_pp_child_css'] = $this->config->get('payment_securetrading_pp_child_css');
+ }
+
+ if (isset($this->request->post['payment_securetrading_pp_cards_accepted'])) {
+ $data['payment_securetrading_pp_cards_accepted'] = $this->request->post['payment_securetrading_pp_cards_accepted'];
+ } else {
+ $data['payment_securetrading_pp_cards_accepted'] = $this->config->get('payment_securetrading_pp_cards_accepted');
+
+ if ($data['payment_securetrading_pp_cards_accepted'] == null) {
+ $data['payment_securetrading_pp_cards_accepted'] = array();
+ }
+ }
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['site_reference'])) {
+ $data['error_site_reference'] = $this->error['site_reference'];
+ } else {
+ $data['error_site_reference'] = '';
+ }
+
+ if (isset($this->error['cards_accepted'])) {
+ $data['error_cards_accepted'] = $this->error['cards_accepted'];
+ } else {
+ $data['error_cards_accepted'] = '';
+ }
+
+ if (isset($this->error['notification_password'])) {
+ $data['error_notification_password'] = $this->error['notification_password'];
+ } else {
+ $data['error_notification_password'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/securetrading_pp', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+ $data['cards'] = array(
+ 'AMEX' => 'American Express',
+ 'VISA' => 'Visa',
+ 'DELTA' => 'Visa Debit',
+ 'ELECTRON' => 'Visa Electron',
+ 'PURCHASING' => 'Visa Purchasing',
+ 'VPAY' => 'V Pay',
+ 'MASTERCARD' => 'MasterCard',
+ 'MASTERCARDDEBIT' => 'MasterCard Debit',
+ 'MAESTRO' => 'Maestro',
+ 'PAYPAL' => 'PayPal',
+ );
+
+ $data['settlement_statuses'] = array(
+ '0' => $this->language->get('text_pending_settlement'),
+ '1' => $this->language->get('text_pending_settlement_manually_overriden'),
+ '2' => $this->language->get('text_pending_suspended'),
+ '100' => $this->language->get('text_pending_settled'),
+ );
+
+ $data['action'] = $this->url->link('extension/payment/securetrading_pp', '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);
+
+ $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/securetrading_pp', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/securetrading_pp');
+ $this->model_extension_payment_securetrading_pp->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/securetrading_pp');
+ $this->model_extension_payment_securetrading_pp->uninstall();
+ }
+
+ public function order() {
+ if ($this->config->get('payment_securetrading_pp_status')) {
+ $this->load->model('extension/payment/securetrading_pp');
+
+ $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->get['order_id']);
+
+ if (!empty($securetrading_pp_order)) {
+ $this->load->language('extension/payment/securetrading_pp');
+
+ $securetrading_pp_order['total_released'] = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']);
+
+ $securetrading_pp_order['total_formatted'] = $this->currency->format($securetrading_pp_order['total'], $securetrading_pp_order['currency_code'], false, false);
+ $securetrading_pp_order['total_released_formatted'] = $this->currency->format($securetrading_pp_order['total_released'], $securetrading_pp_order['currency_code'], false, false);
+
+ $data['securetrading_pp_order'] = $securetrading_pp_order;
+
+ $data['auto_settle'] = $securetrading_pp_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/securetrading_pp_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/securetrading_pp');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/securetrading_pp');
+
+ $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_securetrading_pp->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_securetrading_pp->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if ($void_response !== false) {
+ $response_xml = simplexml_load_string($void_response);
+
+ if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') {
+ $json['msg'] = (string)$response_xml->response->error->message;
+ $json['error'] = true;
+ } else {
+
+ $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'reversed', 0.00);
+ $this->model_extension_payment_securetrading_pp->updateVoidStatus($securetrading_pp_order['securetrading_pp_order_id'], 1);
+
+ $this->data = array(
+ 'order_status_id' => $this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id'),
+ 'notify' => false,
+ 'comment' => '',
+ );
+
+ $this->load->model('sale/order');
+
+ $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $this->data);
+
+ $json['msg'] = $this->language->get('text_authorisation_reversed');
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ }
+ } else {
+ $json['msg'] = $this->language->get('error_connection');
+ $json['error'] = true;
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function release() {
+ $this->load->language('extension/payment/securetrading_pp');
+ $json = array();
+
+ $amount = number_format($this->request->post['amount'], 2);
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($amount) && $amount > 0) {
+ $this->load->model('extension/payment/securetrading_pp');
+
+ $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']);
+
+ $release_response = $this->model_extension_payment_securetrading_pp->release($this->request->post['order_id'], $amount);
+
+ $this->model_extension_payment_securetrading_pp->logger('Release result:\r\n' . print_r($release_response, 1));
+
+ if ($release_response !== false) {
+ $response_xml = simplexml_load_string($release_response);
+
+ if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') {
+ $json['error'] = true;
+ $json['msg'] = (string)$response_xml->response->error->message;
+ } else {
+ $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'payment', $amount);
+
+ $total_released = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']);
+
+ if ($total_released >= $securetrading_pp_order['total'] || $securetrading_pp_order['settle_type'] == 100) {
+ $this->model_extension_payment_securetrading_pp->updateReleaseStatus($securetrading_pp_order['securetrading_pp_order_id'], 1);
+ $release_status = 1;
+ $json['msg'] = $this->language->get('text_release_ok_order');
+
+ $this->load->model('sale/order');
+
+ $history = array();
+ $history['order_status_id'] = $this->config->get('securetrading_pp_order_status_success_settled_id');
+ $history['comment'] = '';
+ $history['notify'] = '';
+
+ $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history);
+ } else {
+ $release_status = 0;
+ $json['msg'] = $this->language->get('text_release_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $amount;
+ $json['data']['release_status'] = $release_status;
+ $json['data']['total'] = (double)$total_released;
+ $json['error'] = false;
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_connection');
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/securetrading_pp');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/securetrading_pp');
+
+ $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']);
+
+ $amount = number_format($this->request->post['amount'], 2);
+
+ $rebate_response = $this->model_extension_payment_securetrading_pp->rebate($this->request->post['order_id'], $amount);
+
+ $this->model_extension_payment_securetrading_pp->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if ($rebate_response !== false) {
+ $response_xml = simplexml_load_string($rebate_response);
+
+ $error_code = (string)$response_xml->response->error->code;
+
+ if ($error_code == '0') {
+
+ $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'rebate', $amount * -1);
+
+ $total_rebated = $this->model_extension_payment_securetrading_pp->getTotalRebated($securetrading_pp_order['securetrading_pp_order_id']);
+ $total_released = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']);
+
+ if ($total_released <= 0 && $securetrading_pp_order['release_status'] == 1) {
+ $json['status'] = 1;
+ $json['message'] = $this->language->get('text_refund_issued');
+
+ $this->model_extension_payment_securetrading_pp->updateRebateStatus($securetrading_pp_order['securetrading_pp_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+
+ $this->load->model('sale/order');
+
+ $history = array();
+ $history['order_status_id'] = $this->config->get('payment_securetrading_pp_refunded_order_status_id');
+ $history['comment'] = '';
+ $history['notify'] = '';
+
+ $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history);
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $amount * -1;
+ $json['data']['total_released'] = (double)$total_released;
+ $json['data']['total_rebated'] = (double)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = (string)$response_xml->response->error->message;
+ }
+ } else {
+ $json['status'] = 0;
+ $json['message'] = $this->language->get('error_connection');
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/securetrading_pp')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_securetrading_pp_site_reference']) {
+ $this->error['site_reference'] = $this->language->get('error_site_reference');
+ }
+
+ if (empty($this->request->post['payment_securetrading_pp_cards_accepted'])) {
+ $this->error['cards_accepted'] = $this->language->get('error_cards_accepted');
+ }
+
+ if (!$this->request->post['payment_securetrading_pp_notification_password']) {
+ $this->error['notification_password'] = $this->language->get('error_notification_password');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/securetrading_ws.php b/public/admin/controller/extension/payment/securetrading_ws.php
new file mode 100644
index 0000000..8e702ec
--- /dev/null
+++ b/public/admin/controller/extension/payment/securetrading_ws.php
@@ -0,0 +1,570 @@
+<?php
+class ControllerExtensionPaymentSecureTradingWs extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->model('setting/setting');
+ $this->load->model('localisation/geo_zone');
+ $this->load->model('localisation/order_status');
+ $this->load->model('localisation/currency');
+ $this->load->language('extension/payment/securetrading_ws');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->request->post['payment_securetrading_ws_site_reference'] = trim($this->request->post['payment_securetrading_ws_site_reference']);
+ $this->request->post['payment_securetrading_ws_username'] = trim($this->request->post['payment_securetrading_ws_username']);
+
+ $this->model_setting_setting->editSetting('payment_securetrading_ws', $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));
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_site_reference'])) {
+ $data['payment_securetrading_ws_site_reference'] = $this->request->post['payment_securetrading_ws_site_reference'];
+ } else {
+ $data['payment_securetrading_ws_site_reference'] = $this->config->get('payment_securetrading_ws_site_reference');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_username'])) {
+ $data['payment_securetrading_ws_username'] = $this->request->post['payment_securetrading_ws_username'];
+ } else {
+ $data['payment_securetrading_ws_username'] = $this->config->get('payment_securetrading_ws_username');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_password'])) {
+ $data['payment_securetrading_ws_password'] = $this->request->post['payment_securetrading_ws_password'];
+ } else {
+ $data['payment_securetrading_ws_password'] = $this->config->get('payment_securetrading_ws_password');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_csv_username'])) {
+ $data['payment_securetrading_ws_csv_username'] = $this->request->post['payment_securetrading_ws_csv_username'];
+ } else {
+ $data['payment_securetrading_ws_csv_username'] = $this->config->get('payment_securetrading_ws_csv_username');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_csv_password'])) {
+ $data['payment_securetrading_ws_csv_password'] = $this->request->post['payment_securetrading_ws_csv_password'];
+ } else {
+ $data['payment_securetrading_ws_csv_password'] = $this->config->get('payment_securetrading_ws_csv_password');
+ }
+
+ $this->config->set('payment_securetrading_ws_3d_secure', 1);
+
+ if (isset($this->request->post['payment_securetrading_ws_3d_secure'])) {
+ $data['payment_securetrading_ws_3d_secure'] = $this->request->post['payment_securetrading_ws_3d_secure'];
+ } else {
+ $data['payment_securetrading_ws_3d_secure'] = $this->config->get('payment_securetrading_ws_3d_secure');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_cards_accepted'])) {
+ $data['payment_securetrading_ws_cards_accepted'] = $this->request->post['payment_securetrading_ws_cards_accepted'];
+ } else {
+ $data['payment_securetrading_ws_cards_accepted'] = $this->config->get('payment_securetrading_ws_cards_accepted');
+
+ if ($data['payment_securetrading_ws_cards_accepted'] == null) {
+ $data['payment_securetrading_ws_cards_accepted'] = array();
+ }
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_order_status_id'])) {
+ $data['payment_securetrading_ws_order_status_id'] = $this->request->post['payment_securetrading_ws_order_status_id'];
+ } elseif ($this->config->get('payment_securetrading_ws_order_status_id') != '') {
+ $data['payment_securetrading_ws_order_status_id'] = $this->config->get('payment_securetrading_ws_order_status_id');
+ } else {
+ $data['payment_securetrading_ws_order_status_id'] = 1;
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_failed_order_status_id'])) {
+ $data['payment_securetrading_ws_failed_order_status_id'] = $this->request->post['payment_securetrading_ws_failed_order_status_id'];
+ } elseif ($this->config->get('payment_securetrading_ws_failed_order_status_id') != '') {
+ $data['payment_securetrading_ws_failed_order_status_id'] = $this->config->get('payment_securetrading_ws_failed_order_status_id');
+ } else {
+ $data['payment_securetrading_ws_failed_order_status_id'] = 10;
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_declined_order_status_id'])) {
+ $data['payment_securetrading_ws_declined_order_status_id'] = $this->request->post['payment_securetrading_ws_declined_order_status_id'];
+ } elseif ($this->config->get('payment_securetrading_ws_declined_order_status_id') != '') {
+ $data['payment_securetrading_ws_declined_order_status_id'] = $this->config->get('payment_securetrading_ws_declined_order_status_id');
+ } else {
+ $data['payment_securetrading_ws_declined_order_status_id'] = 8;
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_refunded_order_status_id'])) {
+ $data['payment_securetrading_ws_refunded_order_status_id'] = $this->request->post['payment_securetrading_ws_refunded_order_status_id'];
+ } elseif ($this->config->get('payment_securetrading_ws_refunded_order_status_id') != '') {
+ $data['payment_securetrading_ws_refunded_order_status_id'] = $this->config->get('payment_securetrading_ws_refunded_order_status_id');
+ } else {
+ $data['payment_securetrading_ws_refunded_order_status_id'] = 11;
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_authorisation_reversed_order_status_id'])) {
+ $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = $this->request->post['payment_securetrading_ws_authorisation_reversed_order_status_id'];
+ } elseif ($this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id') != '') {
+ $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = $this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id');
+ } else {
+ $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = 12;
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_settle_status'])) {
+ $data['payment_securetrading_ws_settle_status'] = $this->request->post['payment_securetrading_ws_settle_status'];
+ } else {
+ $data['payment_securetrading_ws_settle_status'] = $this->config->get('payment_securetrading_ws_settle_status');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_settle_due_date'])) {
+ $data['payment_securetrading_ws_settle_due_date'] = $this->request->post['payment_securetrading_ws_settle_due_date'];
+ } else {
+ $data['payment_securetrading_ws_settle_due_date'] = $this->config->get('payment_securetrading_ws_settle_due_date');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_geo_zone'])) {
+ $data['payment_securetrading_ws_geo_zone_id'] = $this->request->post['payment_securetrading_ws_geo_zone_id'];
+ } else {
+ $data['payment_securetrading_ws_geo_zone_id'] = $this->config->get('payment_securetrading_ws_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_status'])) {
+ $data['payment_securetrading_ws_status'] = $this->request->post['payment_securetrading_ws_status'];
+ } else {
+ $data['payment_securetrading_ws_status'] = $this->config->get('payment_securetrading_ws_status');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_sort_order'])) {
+ $data['payment_securetrading_ws_sort_order'] = $this->request->post['payment_securetrading_ws_sort_order'];
+ } else {
+ $data['payment_securetrading_ws_sort_order'] = $this->config->get('payment_securetrading_ws_sort_order');
+ }
+
+ if (isset($this->request->post['payment_securetrading_ws_total'])) {
+ $data['payment_securetrading_ws_total'] = $this->request->post['payment_securetrading_ws_total'];
+ } else {
+ $data['payment_securetrading_ws_total'] = $this->config->get('payment_securetrading_ws_total');
+ }
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['site_reference'])) {
+ $data['error_site_reference'] = $this->error['site_reference'];
+ } else {
+ $data['error_site_reference'] = '';
+ }
+
+ if (isset($this->error['username'])) {
+ $data['error_username'] = $this->error['username'];
+ } else {
+ $data['error_username'] = '';
+ }
+
+ if (isset($this->error['password'])) {
+ $data['error_password'] = $this->error['password'];
+ } else {
+ $data['error_password'] = '';
+ }
+
+ if (isset($this->error['cards_accepted'])) {
+ $data['error_cards_accepted'] = $this->error['cards_accepted'];
+ } else {
+ $data['error_cards_accepted'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/securetrading_ws', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $data['cards'] = array(
+ 'AMEX' => 'American Express',
+ 'VISA' => 'Visa',
+ 'DELTA' => 'Visa Debit',
+ 'ELECTRON' => 'Visa Electron',
+ 'PURCHASING' => 'Visa Purchasing',
+ 'VPAY' => 'V Pay',
+ 'MASTERCARD' => 'MasterCard',
+ 'MASTERCARDDEBIT' => 'MasterCard Debit',
+ 'MAESTRO' => 'Maestro',
+ 'PAYPAL' => 'PayPal',
+ );
+
+ $data['settlement_statuses'] = array(
+ '0' => $this->language->get('text_pending_settlement'),
+ '1' => $this->language->get('text_pending_settlement_manually_overriden'),
+ '2' => $this->language->get('text_pending_suspended'),
+ '100' => $this->language->get('text_pending_settled'),
+ );
+
+ $data['action'] = $this->url->link('extension/payment/securetrading_ws', '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);
+
+ $data['myst_status'] = !empty($data['securetrading_ws_csv_username']) && !empty($data['securetrading_ws_csv_password']);
+ $data['hours'] = array();
+
+ for ($i = 0; $i < 24; $i++) {
+ $data['hours'][] = str_pad($i, 2, '0', STR_PAD_LEFT);
+ }
+
+ $data['minutes'] = array();
+
+ for ($i = 0; $i < 60; $i++) {
+ $data['minutes'][] = str_pad($i, 2, '0', STR_PAD_LEFT);
+ }
+
+ $data['currencies'] = $this->model_localisation_currency->getCurrencies();
+
+ $data['user_token'] = $this->session->data['user_token'];
+
+ $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/securetrading_ws', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/securetrading_ws');
+ $this->model_extension_payment_securetrading_ws->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/securetrading_ws');
+ $this->model_extension_payment_securetrading_ws->uninstall();
+ }
+
+ public function downloadTransactions() {
+ $this->load->model('extension/payment/securetrading_ws');
+ $this->load->language('extension/payment/securetrading_ws');
+
+ $csv_data = $this->request->post;
+ $csv_data['detail'] = true;
+
+ $response = $this->model_extension_payment_securetrading_ws->getCsv($csv_data);
+
+ header('Content-Type: application/octet-stream');
+ header('Content-Disposition: attachment; filename="' . $this->language->get('text_transactions') . '.csv"');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ header('Pragma: public');
+ header('Content-Length: ' . strlen($response));
+
+ if (ob_get_level()) {
+ ob_end_clean();
+ }
+
+ echo $response;
+ exit();
+ }
+
+ public function showTransactions() {
+ $this->load->model('extension/payment/securetrading_ws');
+ $this->load->language('extension/payment/securetrading_ws');
+
+ $csv_data = $this->request->post;
+ $csv_data['detail'] = false;
+
+ $response = $this->model_extension_payment_securetrading_ws->getCsv($csv_data);
+
+ $data['transactions'] = array();
+
+ $status_mapping = array(
+ '0' => $this->language->get('text_ok'),
+ '70000' => $this->language->get('text_denied'),
+ );
+
+ $settle_status_mapping = array(
+ '0' => $this->language->get('text_pending_settlement'),
+ '1' => $this->language->get('text_manual_settlement'),
+ '2' => $this->language->get('text_suspended'),
+ '3' => $this->language->get('text_cancelled'),
+ '10' => $this->language->get('text_settling'),
+ '100' => $this->language->get('text_settled'),
+ );
+
+ if ($response) {
+ $lines = array_filter(explode("\n", $response));
+
+ $csv = array();
+ $keys = str_getcsv($lines[0]);
+
+ for ($i = 1; $i < count($lines); $i++) {
+ $csv[] = array_combine($keys, str_getcsv($lines[$i]));
+ }
+
+ foreach ($csv as $row) {
+ $data['transactions'][] = array(
+ 'order_id' => $row['orderreference'],
+ 'order_href' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $row['orderreference'], true),
+ 'transaction_reference' => $row['transactionreference'],
+ 'customer' => $row['billingfirstname'] . ' ' . $row['billinglastname'],
+ 'total' => $row['mainamount'],
+ 'currency' => $row['currencyiso3a'],
+ 'settle_status' => $settle_status_mapping[$row['settlestatus']],
+ 'status' => $status_mapping[$row['errorcode']],
+ 'type' => $row['requesttypedescription'],
+ 'payment_type' => $row['paymenttypedescription'],
+ );
+ }
+ }
+
+ return $this->load->view('extension/payment/securetrading_ws_transactions', $data);
+ }
+
+ public function order() {
+
+ if ($this->config->get('payment_securetrading_ws_status')) {
+ $this->load->model('extension/payment/securetrading_ws');
+
+ $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->get['order_id']);
+
+ if (!empty($securetrading_ws_order)) {
+ $this->load->language('extension/payment/securetrading_ws');
+
+ $securetrading_ws_order['total_released'] = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']);
+
+ $securetrading_ws_order['total_formatted'] = $this->currency->format($securetrading_ws_order['total'], $securetrading_ws_order['currency_code'], false, false);
+ $securetrading_ws_order['total_released_formatted'] = $this->currency->format($securetrading_ws_order['total_released'], $securetrading_ws_order['currency_code'], false, false);
+
+ $data['securetrading_ws_order'] = $securetrading_ws_order;
+
+ $data['auto_settle'] = $securetrading_ws_order['settle_type'];
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/securetrading_ws_order', $data);
+ }
+ }
+ }
+
+ public function void() {
+ $this->load->language('extension/payment/securetrading_ws');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') {
+ $this->load->model('extension/payment/securetrading_ws');
+
+ $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']);
+
+ $void_response = $this->model_extension_payment_securetrading_ws->void($this->request->post['order_id']);
+
+ $this->model_extension_payment_securetrading_ws->logger('Void result:\r\n' . print_r($void_response, 1));
+
+ if ($void_response !== false) {
+ $response_xml = simplexml_load_string($void_response);
+
+ if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') {
+ $json['msg'] = (string)$response_xml->response->error->message;
+ $json['error'] = true;
+ } else {
+
+ $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'reversed', 0.00);
+ $this->model_extension_payment_securetrading_ws->updateVoidStatus($securetrading_ws_order['securetrading_ws_order_id'], 1);
+
+ $this->data = array(
+ 'order_status_id' => $this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id'),
+ 'notify' => false,
+ 'comment' => '',
+ );
+
+ $this->load->model('sale/order');
+
+ $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $this->data);
+
+ $json['msg'] = $this->language->get('text_authorisation_reversed');
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['error'] = false;
+ }
+ } else {
+ $json['msg'] = $this->language->get('error_connection');
+ $json['error'] = true;
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function release() {
+ $this->load->language('extension/payment/securetrading_ws');
+ $json = array();
+
+ $amount = number_format($this->request->post['amount'], 2);
+
+ if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($amount) && $amount > 0) {
+ $this->load->model('extension/payment/securetrading_ws');
+
+ $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']);
+
+ $release_response = $this->model_extension_payment_securetrading_ws->release($this->request->post['order_id'], $amount);
+
+ $this->model_extension_payment_securetrading_ws->logger('Release result:\r\n' . print_r($release_response, 1));
+
+ if ($release_response !== false) {
+ $response_xml = simplexml_load_string($release_response);
+
+ if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') {
+ $json['error'] = true;
+ $json['msg'] = (string)$response_xml->response->error->message;
+ } else {
+ $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'payment', $amount);
+
+ $total_released = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']);
+
+ if ($total_released >= $securetrading_ws_order['total'] || $securetrading_ws_order['settle_type'] == 100) {
+ $this->model_extension_payment_securetrading_ws->updateReleaseStatus($securetrading_ws_order['securetrading_ws_order_id'], 1);
+ $release_status = 1;
+ $json['msg'] = $this->language->get('text_release_ok_order');
+
+ $this->load->model('sale/order');
+
+ $history = array();
+ $history['order_status_id'] = $this->config->get('securetrading_ws_order_status_success_settled_id');
+ $history['comment'] = '';
+ $history['notify'] = '';
+
+ $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history);
+ } else {
+ $release_status = 0;
+ $json['msg'] = $this->language->get('text_release_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $amount;
+ $json['data']['release_status'] = $release_status;
+ $json['data']['total'] = (double)$total_released;
+ $json['error'] = false;
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_connection');
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = $this->language->get('error_data_missing');
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ public function rebate() {
+ $this->load->language('extension/payment/securetrading_ws');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/securetrading_ws');
+
+ $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']);
+
+ $amount = number_format($this->request->post['amount'], 2);
+
+ $rebate_response = $this->model_extension_payment_securetrading_ws->rebate($this->request->post['order_id'], $amount);
+
+ $this->model_extension_payment_securetrading_ws->logger('Rebate result:\r\n' . print_r($rebate_response, 1));
+
+ if ($rebate_response !== false) {
+ $response_xml = simplexml_load_string($rebate_response);
+
+ $error_code = (string)$response_xml->response->error->code;
+
+ if ($error_code == '0') {
+
+ $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'rebate', $amount * -1);
+
+ $total_rebated = $this->model_extension_payment_securetrading_ws->getTotalRebated($securetrading_ws_order['securetrading_ws_order_id']);
+ $total_released = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']);
+
+ if ($total_released <= 0 && $securetrading_ws_order['release_status'] == 1) {
+ $json['status'] = 1;
+ $json['message'] = $this->language->get('text_refund_issued');
+
+ $this->model_extension_payment_securetrading_ws->updateRebateStatus($securetrading_ws_order['securetrading_ws_order_id'], 1);
+ $rebate_status = 1;
+ $json['msg'] = $this->language->get('text_rebate_ok_order');
+
+ $this->load->model('sale/order');
+
+ $history = array();
+ $history['order_status_id'] = $this->config->get('payment_securetrading_ws_refunded_order_status_id');
+ $history['comment'] = '';
+ $history['notify'] = '';
+
+ $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history);
+ } else {
+ $rebate_status = 0;
+ $json['msg'] = $this->language->get('text_rebate_ok');
+ }
+
+ $json['data'] = array();
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $amount * -1;
+ $json['data']['total_released'] = (double)$total_released;
+ $json['data']['total_rebated'] = (double)$total_rebated;
+ $json['data']['rebate_status'] = $rebate_status;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = (string)$response_xml->response->error->message;
+ }
+ } else {
+ $json['status'] = 0;
+ $json['message'] = $this->language->get('error_connection');
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/securetrading_pp')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_securetrading_ws_site_reference']) {
+ $this->error['site_reference'] = $this->language->get('error_site_reference');
+ }
+
+ if (!$this->request->post['payment_securetrading_ws_username']) {
+ $this->error['username'] = $this->language->get('error_username');
+ }
+
+ if (!$this->request->post['payment_securetrading_ws_password']) {
+ $this->error['password'] = $this->language->get('error_password');
+ }
+
+ if (empty($this->request->post['payment_securetrading_ws_cards_accepted'])) {
+ $this->error['cards_accepted'] = $this->language->get('error_cards_accepted');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/skrill.php b/public/admin/controller/extension/payment/skrill.php
new file mode 100644
index 0000000..f53b107
--- /dev/null
+++ b/public/admin/controller/extension/payment/skrill.php
@@ -0,0 +1,157 @@
+<?php
+class ControllerExtensionPaymentSkrill extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/skrill');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_skrill', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['email'])) {
+ $data['error_email'] = $this->error['email'];
+ } else {
+ $data['error_email'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/skrill', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/skrill', '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_skrill_email'])) {
+ $data['payment_skrill_email'] = $this->request->post['payment_skrill_email'];
+ } else {
+ $data['payment_skrill_email'] = $this->config->get('payment_skrill_email');
+ }
+
+ if (isset($this->request->post['payment_skrill_secret'])) {
+ $data['payment_skrill_secret'] = $this->request->post['payment_skrill_secret'];
+ } else {
+ $data['payment_skrill_secret'] = $this->config->get('payment_skrill_secret');
+ }
+
+ if (isset($this->request->post['payment_skrill_total'])) {
+ $data['payment_skrill_total'] = $this->request->post['payment_skrill_total'];
+ } else {
+ $data['payment_skrill_total'] = $this->config->get('payment_skrill_total');
+ }
+
+ if (isset($this->request->post['payment_skrill_order_status_id'])) {
+ $data['payment_skrill_order_status_id'] = $this->request->post['payment_skrill_order_status_id'];
+ } else {
+ $data['payment_skrill_order_status_id'] = $this->config->get('payment_skrill_order_status_id');
+ }
+
+ if (isset($this->request->post['payment_skrill_pending_status_id'])) {
+ $data['payment_skrill_pending_status_id'] = $this->request->post['payment_skrill_pending_status_id'];
+ } else {
+ $data['payment_skrill_pending_status_id'] = $this->config->get('payment_skrill_pending_status_id');
+ }
+
+ if (isset($this->request->post['payment_skrill_canceled_status_id'])) {
+ $data['payment_skrill_canceled_status_id'] = $this->request->post['payment_skrill_canceled_status_id'];
+ } else {
+ $data['payment_skrill_canceled_status_id'] = $this->config->get('payment_skrill_canceled_status_id');
+ }
+
+ if (isset($this->request->post['payment_skrill_failed_status_id'])) {
+ $data['payment_skrill_failed_status_id'] = $this->request->post['payment_skrill_failed_status_id'];
+ } else {
+ $data['payment_skrill_failed_status_id'] = $this->config->get('payment_skrill_failed_status_id');
+ }
+
+ if (isset($this->request->post['payment_skrill_chargeback_status_id'])) {
+ $data['payment_skrill_chargeback_status_id'] = $this->request->post['payment_skrill_chargeback_status_id'];
+ } else {
+ $data['payment_skrill_chargeback_status_id'] = $this->config->get('payment_skrill_chargeback_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_skrill_geo_zone_id'])) {
+ $data['payment_skrill_geo_zone_id'] = $this->request->post['payment_skrill_geo_zone_id'];
+ } else {
+ $data['payment_skrill_geo_zone_id'] = $this->config->get('payment_skrill_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_skrill_status'])) {
+ $data['payment_skrill_status'] = $this->request->post['payment_skrill_status'];
+ } else {
+ $data['payment_skrill_status'] = $this->config->get('payment_skrill_status');
+ }
+
+ if (isset($this->request->post['payment_skrill_sort_order'])) {
+ $data['payment_skrill_sort_order'] = $this->request->post['payment_skrill_sort_order'];
+ } else {
+ $data['payment_skrill_sort_order'] = $this->config->get('payment_skrill_sort_order');
+ }
+
+ if (isset($this->request->post['payment_skrill_rid'])) {
+ $data['payment_skrill_rid'] = $this->request->post['payment_skrill_rid'];
+ } else {
+ $data['payment_skrill_rid'] = $this->config->get('payment_skrill_rid');
+ }
+
+ if (isset($this->request->post['payment_skrill_custnote'])) {
+ $data['payment_skrill_custnote'] = $this->request->post['payment_skrill_custnote'];
+ } else {
+ $data['payment_skrill_custnote'] = $this->config->get('payment_skrill_custnote');
+ }
+
+ $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/skrill', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/skrill')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_skrill_email']) {
+ $this->error['email'] = $this->language->get('error_email');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/squareup.php b/public/admin/controller/extension/payment/squareup.php
new file mode 100644
index 0000000..1ab2916
--- /dev/null
+++ b/public/admin/controller/extension/payment/squareup.php
@@ -0,0 +1,1079 @@
+<?php
+
+class ControllerExtensionPaymentSquareup extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/squareup');
+
+ $this->load->model('extension/payment/squareup');
+ $this->load->model('setting/setting');
+
+ $this->load->library('squareup');
+
+ if ($this->request->server['HTTPS']) {
+ $server = HTTPS_SERVER;
+ } else {
+ $server = HTTP_SERVER;
+ }
+
+ $previous_setting = $this->model_setting_setting->getSetting('payment_squareup');
+
+ try {
+ if ($this->config->get('payment_squareup_access_token')) {
+ if (!$this->squareup->verifyToken($this->config->get('payment_squareup_access_token'))) {
+ unset($previous_setting['payment_squareup_merchant_id']);
+ unset($previous_setting['payment_squareup_merchant_name']);
+ unset($previous_setting['payment_squareup_access_token']);
+ unset($previous_setting['payment_squareup_access_token_expires']);
+ unset($previous_setting['payment_squareup_locations']);
+ unset($previous_setting['payment_squareup_sandbox_locations']);
+
+ $this->config->set('payment_squareup_merchant_id', null);
+ } else {
+ if (!$this->config->get('payment_squareup_locations')) {
+ $previous_setting['payment_squareup_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_access_token'), $first_location_id);
+ $previous_setting['payment_squareup_location_id'] = $first_location_id;
+ }
+ }
+ }
+
+ if (!$this->config->get('payment_squareup_sandbox_locations') && $this->config->get('payment_squareup_sandbox_token')) {
+ $previous_setting['payment_squareup_sandbox_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_sandbox_token'), $first_location_id);
+ $previous_setting['payment_squareup_sandbox_location_id'] = $first_location_id;
+ }
+
+ $this->model_setting_setting->editSetting('payment_squareup', $previous_setting);
+ } catch (\Squareup\Exception $e) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => sprintf($this->language->get('text_location_error'), $e->getMessage())
+ ));
+ }
+
+ $previous_config = new Config();
+
+ foreach ($previous_setting as $key => $value) {
+ $previous_config->set($key, $value);
+ }
+
+ if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_squareup', array_merge($previous_setting, $this->request->post));
+
+ $this->session->data['success'] = $this->language->get('text_success');
+
+ if (isset($this->request->get['save_and_auth'])) {
+ $this->response->redirect($this->squareup->authLink($this->request->post['payment_squareup_client_id']));
+ } else {
+ $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true));
+ }
+ }
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $data['error_status'] = $this->getValidationError('status');
+ $data['error_display_name'] = $this->getValidationError('display_name');
+ $data['error_client_id'] = $this->getValidationError('client_id');
+ $data['error_client_secret'] = $this->getValidationError('client_secret');
+ $data['error_delay_capture'] = $this->getValidationError('delay_capture');
+ $data['error_sandbox_client_id'] = $this->getValidationError('sandbox_client_id');
+ $data['error_sandbox_token'] = $this->getValidationError('sandbox_token');
+ $data['error_location'] = $this->getValidationError('location');
+ $data['error_cron_email'] = $this->getValidationError('cron_email');
+ $data['error_cron_acknowledge'] = $this->getValidationError('cron_acknowledge');
+
+ $data['payment_squareup_status'] = $this->getSettingValue('payment_squareup_status');
+ $data['payment_squareup_status_authorized'] = $this->getSettingValue('payment_squareup_status_authorized');
+ $data['payment_squareup_status_captured'] = $this->getSettingValue('payment_squareup_status_captured');
+ $data['payment_squareup_status_voided'] = $this->getSettingValue('payment_squareup_status_voided');
+ $data['payment_squareup_status_failed'] = $this->getSettingValue('payment_squareup_status_failed');
+ $data['payment_squareup_display_name'] = $this->getSettingValue('payment_squareup_display_name');
+ $data['payment_squareup_client_id'] = $this->getSettingValue('payment_squareup_client_id');
+ $data['payment_squareup_client_secret'] = $this->getSettingValue('payment_squareup_client_secret');
+ $data['payment_squareup_enable_sandbox'] = $this->getSettingValue('payment_squareup_enable_sandbox');
+ $data['payment_squareup_debug'] = $this->getSettingValue('payment_squareup_debug');
+ $data['payment_squareup_sort_order'] = $this->getSettingValue('payment_squareup_sort_order');
+ $data['payment_squareup_total'] = $this->getSettingValue('payment_squareup_total');
+ $data['payment_squareup_geo_zone_id'] = $this->getSettingValue('payment_squareup_geo_zone_id');
+ $data['payment_squareup_sandbox_client_id'] = $this->getSettingValue('payment_squareup_sandbox_client_id');
+ $data['payment_squareup_sandbox_token'] = $this->getSettingValue('payment_squareup_sandbox_token');
+ $data['payment_squareup_locations'] = $this->getSettingValue('payment_squareup_locations', $previous_config->get('payment_squareup_locations'));
+ $data['payment_squareup_location_id'] = $this->getSettingValue('payment_squareup_location_id');
+ $data['payment_squareup_sandbox_locations'] = $this->getSettingValue('payment_squareup_sandbox_locations', $previous_config->get('payment_squareup_sandbox_locations'));
+ $data['payment_squareup_sandbox_location_id'] = $this->getSettingValue('payment_squareup_sandbox_location_id');
+ $data['payment_squareup_delay_capture'] = $this->getSettingValue('payment_squareup_delay_capture');
+ $data['payment_squareup_recurring_status'] = $this->getSettingValue('payment_squareup_recurring_status');
+ $data['payment_squareup_cron_email_status'] = $this->getSettingValue('payment_squareup_cron_email_status');
+ $data['payment_squareup_cron_email'] = $this->getSettingValue('payment_squareup_cron_email', $this->config->get('config_email'));
+ $data['payment_squareup_cron_token'] = $this->getSettingValue('payment_squareup_cron_token');
+ $data['payment_squareup_cron_acknowledge'] = $this->getSettingValue('payment_squareup_cron_acknowledge', null, true);
+ $data['payment_squareup_notify_recurring_success'] = $this->getSettingValue('payment_squareup_notify_recurring_success');
+ $data['payment_squareup_notify_recurring_fail'] = $this->getSettingValue('payment_squareup_notify_recurring_fail');
+ $data['payment_squareup_merchant_id'] = $this->getSettingValue('payment_squareup_merchant_id', $previous_config->get('payment_squareup_merchant_id'));
+ $data['payment_squareup_merchant_name'] = $this->getSettingValue('payment_squareup_merchant_name', $previous_config->get('payment_squareup_merchant_name'));
+
+ if ($previous_config->get('payment_squareup_access_token') && $previous_config->get('payment_squareup_access_token_expires')) {
+ $expiration_time = date_create_from_format('Y-m-d\TH:i:s\Z', $previous_config->get('payment_squareup_access_token_expires'));
+ $now = date_create();
+
+ $delta = $expiration_time->getTimestamp() - $now->getTimestamp();
+ $expiration_date_formatted = $expiration_time->format('l, F jS, Y h:i:s A, e');
+
+ if ($delta < 0) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => sprintf($this->language->get('text_token_expired'), $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true))
+ ));
+ } else if ($delta < (5 * 24 * 60 * 60)) { // token is valid, just about to expire
+ $this->pushAlert(array(
+ 'type' => 'warning',
+ 'icon' => 'exclamation-circle',
+ 'text' => sprintf($this->language->get('text_token_expiry_warning'), $expiration_date_formatted, $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true))
+ ));
+ }
+
+ $data['access_token_expires_time'] = $expiration_date_formatted;
+ } else if ($previous_config->get('payment_squareup_client_id')) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => sprintf($this->language->get('text_token_revoked'), $this->squareup->authLink($previous_config->get('payment_squareup_client_id')))
+ ));
+
+ $data['access_token_expires_time'] = $this->language->get('text_na');
+ }
+
+ if ($previous_config->get('payment_squareup_client_id')) {
+ $data['payment_squareup_auth_link'] = $this->squareup->authLink($previous_config->get('payment_squareup_client_id'));
+ } else {
+ $data['payment_squareup_auth_link'] = null;
+ }
+
+ $data['payment_squareup_redirect_uri'] = str_replace('&amp;', '&', $this->url->link('extension/payment/squareup/oauth_callback', '', true));
+ $data['payment_squareup_refresh_link'] = $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true);
+
+ if ($this->config->get('payment_squareup_enable_sandbox')) {
+ $this->pushAlert(array(
+ 'type' => 'warning',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('text_sandbox_enabled')
+ ));
+ }
+
+ if (isset($this->error['warning'])) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->error['warning']
+ ));
+ }
+
+ // Insert success message from the session
+ if (isset($this->session->data['success'])) {
+ $this->pushAlert(array(
+ 'type' => 'success',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->session->data['success']
+ ));
+
+ unset($this->session->data['success']);
+ }
+
+ if ($this->request->server['HTTPS']) {
+ // Push the SSL reminder alert
+ $this->pushAlert(array(
+ 'type' => 'info',
+ 'icon' => 'lock',
+ 'text' => $this->language->get('text_notification_ssl')
+ ));
+ } else {
+ // Push the SSL reminder alert
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('error_no_ssl')
+ ));
+ }
+
+ $tabs = array(
+ 'tab-transaction',
+ 'tab-setting',
+ 'tab-recurring',
+ 'tab-cron'
+ );
+
+ if (isset($this->request->get['tab']) && in_array($this->request->get['tab'], $tabs)) {
+ $data['tab'] = $this->request->get['tab'];
+ } else if (isset($this->error['cron_email']) || isset($this->error['cron_acknowledge'])) {
+ $data['tab'] = 'tab-cron';
+ } else if ($this->error) {
+ $data['tab'] = 'tab-setting';
+ } else {
+ $data['tab'] = $tabs[1];
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = html_entity_decode($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ $data['action_save_auth'] = html_entity_decode($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'] . '&save_and_auth=1', true));
+ $data['cancel'] = html_entity_decode($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true));
+ $data['url_list_transactions'] = html_entity_decode($this->url->link('extension/payment/squareup/transactions', 'user_token=' . $this->session->data['user_token'] . '&page={PAGE}', true));
+
+ $this->load->model('localisation/language');
+ $data['languages'] = array();
+ foreach ($this->model_localisation_language->getLanguages() as $language) {
+ $data['languages'][] = array(
+ 'language_id' => $language['language_id'],
+ 'name' => $language['name'] . ($language['code'] == $this->config->get('config_language') ? $this->language->get('text_default') : ''),
+ 'image' => 'language/' . $language['code'] . '/'. $language['code'] . '.png'
+ );
+ }
+
+ $this->load->model('localisation/order_status');
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ $this->load->model('localisation/geo_zone');
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $data['payment_squareup_cron_command'] = PHP_BINDIR . '/php -d session.save_path=' . session_save_path() . ' ' . DIR_SYSTEM . 'library/squareup/cron.php ' . parse_url($server, PHP_URL_HOST) . ' 443 > /dev/null 2> /dev/null';
+
+ if (!$this->config->get('payment_squareup_cron_token')) {
+ $data['payment_squareup_cron_token'] = md5(mt_rand());
+ }
+
+ $data['payment_squareup_cron_url'] = 'https://' . parse_url($server, PHP_URL_HOST) . dirname(parse_url($server, PHP_URL_PATH)) . '/index.php?route=extension/recurring/squareup/recurring&cron_token={CRON_TOKEN}';
+
+ $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
+
+ // API login
+ $this->load->model('user/api');
+
+ $api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
+
+ if ($api_info && $this->user->hasPermission('modify', 'sale/order')) {
+ $session = new Session($this->config->get('session_engine'), $this->registry);
+
+ $session->start();
+
+ $this->model_user_api->deleteApiSessionBySessonId($session->getId());
+
+ $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']);
+
+ $session->data['api_id'] = $api_info['api_id'];
+
+ $data['api_token'] = $session->getId();
+ } else {
+ $data['api_token'] = '';
+ }
+
+ $data['header'] = $this->load->controller('common/header');
+ $data['column_left'] = $this->load->controller('common/column_left');
+ $data['footer'] = $this->load->controller('common/footer');
+
+ $data['alerts'] = $this->pullAlerts();
+
+ $this->clearAlerts();
+
+ $this->response->setOutput($this->load->view('extension/payment/squareup', $data));
+ }
+
+ public function transaction_info() {
+ $this->load->language('extension/payment/squareup');
+
+ $this->load->model('extension/payment/squareup');
+
+ $this->load->library('squareup');
+
+ if (isset($this->request->get['squareup_transaction_id'])) {
+ $squareup_transaction_id = $this->request->get['squareup_transaction_id'];
+ } else {
+ $squareup_transaction_id = 0;
+ }
+
+ $transaction_info = $this->model_extension_payment_squareup->getTransaction($squareup_transaction_id);
+
+ if (empty($transaction_info)) {
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ $this->document->setTitle(sprintf($this->language->get('heading_title_transaction'), $transaction_info['transaction_id']));
+
+ $data['alerts'] = $this->pullAlerts();
+
+ $this->clearAlerts();
+
+ $data['text_edit'] = sprintf($this->language->get('heading_title_transaction'), $transaction_info['transaction_id']);
+
+ $amount = $this->currency->format($transaction_info['transaction_amount'], $transaction_info['transaction_currency']);
+
+ $data['confirm_capture'] = sprintf($this->language->get('text_confirm_capture'), $amount);
+ $data['confirm_void'] = sprintf($this->language->get('text_confirm_void'), $amount);
+ $data['confirm_refund'] = $this->language->get('text_confirm_refund');
+ $data['insert_amount'] = sprintf($this->language->get('text_insert_amount'), $amount, $transaction_info['transaction_currency']);
+ $data['text_loading'] = $this->language->get('text_loading_short');
+
+ $data['billing_address_company'] = $transaction_info['billing_address_company'];
+ $data['billing_address_street'] = $transaction_info['billing_address_street_1'] . ' ' . $transaction_info['billing_address_street_2'];
+ $data['billing_address_city'] = $transaction_info['billing_address_city'];
+ $data['billing_address_postcode'] = $transaction_info['billing_address_postcode'];
+ $data['billing_address_province'] = $transaction_info['billing_address_province'];
+ $data['billing_address_country'] = $transaction_info['billing_address_country'];
+
+ $data['transaction_id'] = $transaction_info['transaction_id'];
+ $data['merchant'] = $transaction_info['merchant_id'];
+ $data['order_id'] = $transaction_info['order_id'];
+ $data['type'] = $transaction_info['transaction_type'];
+ $data['amount'] = $amount;
+ $data['currency'] = $transaction_info['transaction_currency'];
+ $data['browser'] = $transaction_info['device_browser'];
+ $data['ip'] = $transaction_info['device_ip'];
+ $data['date_created'] = date($this->language->get('datetime_format'), strtotime($transaction_info['created_at']));
+
+ $data['cancel'] = $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'] . '&tab=tab-transaction', true);
+
+ $data['url_order'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction_info['order_id'], true);
+ $data['url_void'] = $this->url->link('extension/payment/squareup' . '/void', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true);
+ $data['url_capture'] = $this->url->link('extension/payment/squareup' . '/capture', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true);
+ $data['url_refund'] = $this->url->link('extension/payment/squareup' . '/refund', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true);
+ $data['url_transaction'] = sprintf(
+ Squareup::VIEW_TRANSACTION_URL,
+ $transaction_info['transaction_id'],
+ $transaction_info['location_id']
+ );
+
+ $data['is_authorized'] = in_array($transaction_info['transaction_type'], array('AUTHORIZED'));
+ $data['is_captured'] = in_array($transaction_info['transaction_type'], array('CAPTURED'));
+
+ $data['has_refunds'] = (bool)$transaction_info['is_refunded'];
+
+ if ($data['has_refunds']) {
+ $refunds = @json_decode($transaction_info['refunds'], true);
+
+ $data['refunds'] = array();
+
+ $data['text_refunds'] = sprintf($this->language->get('text_refunds'), count($refunds));
+
+ foreach ($refunds as $refund) {
+ $amount = $this->currency->format(
+ $this->squareup->standardDenomination(
+ $refund['amount_money']['amount'],
+ $refund['amount_money']['currency']
+ ),
+ $refund['amount_money']['currency']
+ );
+
+ $fee = $this->currency->format(
+ $this->squareup->standardDenomination(
+ $refund['processing_fee_money']['amount'],
+ $refund['processing_fee_money']['currency']
+ ),
+ $refund['processing_fee_money']['currency']
+ );
+
+ $data['refunds'][] = array(
+ 'date_created' => date($this->language->get('datetime_format'), strtotime($refund['created_at'])),
+ 'reason' => $refund['reason'],
+ 'status' => $refund['status'],
+ 'amount' => $amount,
+ 'fee' => $fee
+ );
+ }
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => sprintf($this->language->get('heading_title_transaction'), $transaction_info['squareup_transaction_id']),
+ 'href' => $this->url->link('extension/payment/squareup/transaction_info', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $squareup_transaction_id, true)
+ );
+
+ $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
+
+ // API login
+ $this->load->model('user/api');
+
+ $api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
+
+ if ($api_info && $this->user->hasPermission('modify', 'sale/order')) {
+ $session = new Session($this->config->get('session_engine'), $this->registry);
+
+ $session->start();
+
+ $this->model_user_api->deleteApiSessionBySessonId($session->getId());
+
+ $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']);
+
+ $session->data['api_id'] = $api_info['api_id'];
+
+ $data['api_token'] = $session->getId();
+ } else {
+ $data['api_token'] = '';
+ }
+
+ $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/squareup_transaction_info', $data));
+ }
+
+ public function transactions() {
+ $this->load->language('extension/payment/squareup');
+
+ $this->load->model('extension/payment/squareup');
+
+ if (isset($this->request->get['page'])) {
+ $page = (int)$this->request->get['page'];
+ } else {
+ $page = 1;
+ }
+
+ $result = array(
+ 'transactions' => array(),
+ 'pagination' => ''
+ );
+
+ $filter_data = array(
+ 'start' => ($page - 1) * (int)$this->config->get('config_limit_admin'),
+ 'limit' => $this->config->get('config_limit_admin')
+ );
+
+ if (isset($this->request->get['order_id'])) {
+ $filter_data['order_id'] = $this->request->get['order_id'];
+ }
+
+ $transactions_total = $this->model_extension_payment_squareup->getTotalTransactions($filter_data);
+ $transactions = $this->model_extension_payment_squareup->getTransactions($filter_data);
+
+ $this->load->model('sale/order');
+
+ foreach ($transactions as $transaction) {
+ $amount = $this->currency->format($transaction['transaction_amount'], $transaction['transaction_currency']);
+
+ $order_info = $this->model_sale_order->getOrder($transaction['order_id']);
+
+ $result['transactions'][] = array(
+ 'squareup_transaction_id' => $transaction['squareup_transaction_id'],
+ 'transaction_id' => $transaction['transaction_id'],
+ 'url_order' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction['order_id'], true),
+ 'url_void' => $this->url->link('extension/payment/squareup/void', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true),
+ 'url_capture' => $this->url->link('extension/payment/squareup/capture', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true),
+ 'url_refund' => $this->url->link('extension/payment/squareup/refund', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true),
+ 'confirm_capture' => sprintf($this->language->get('text_confirm_capture'), $amount),
+ 'confirm_void' => sprintf($this->language->get('text_confirm_void'), $amount),
+ 'confirm_refund' => $this->language->get('text_confirm_refund'),
+ 'insert_amount' => sprintf($this->language->get('text_insert_amount'), $amount, $transaction['transaction_currency']),
+ 'order_id' => $transaction['order_id'],
+ 'type' => $transaction['transaction_type'],
+ 'num_refunds' => count(@json_decode($transaction['refunds'], true)),
+ 'amount' => $amount,
+ 'customer' => $order_info['firstname'] . ' ' . $order_info['lastname'],
+ 'ip' => $transaction['device_ip'],
+ 'date_created' => date($this->language->get('datetime_format'), strtotime($transaction['created_at'])),
+ 'url_info' => $this->url->link('extension/payment/squareup/transaction_info', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true)
+ );
+ }
+
+ $pagination = new Pagination();
+ $pagination->total = $transactions_total;
+ $pagination->page = $page;
+ $pagination->limit = $this->config->get('config_limit_admin');
+ $pagination->url = '{page}';
+
+ $result['pagination'] = $pagination->render();
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($result));
+ }
+
+ public function refresh_token() {
+ $this->load->language('extension/payment/squareup');
+
+ if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('error_permission')
+ ));
+
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ $this->load->model('setting/setting');
+
+ $this->load->library('squareup');
+
+ try {
+ $response = $this->squareup->refreshToken();
+
+ if (!isset($response['access_token']) || !isset($response['token_type']) || !isset($response['expires_at']) || !isset($response['merchant_id']) ||
+ $response['merchant_id'] != $this->config->get('payment_squareup_merchant_id')) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('error_refresh_access_token')
+ ));
+ } else {
+ $settings = $this->model_setting_setting->getSetting('payment_squareup');
+
+ $settings['payment_squareup_access_token'] = $response['access_token'];
+ $settings['payment_squareup_access_token_expires'] = $response['expires_at'];
+
+ $this->model_setting_setting->editSetting('payment_squareup', $settings);
+
+ $this->pushAlert(array(
+ 'type' => 'success',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('text_refresh_access_token_success')
+ ));
+ }
+ } catch (\Squareup\Exception $e) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => sprintf($this->language->get('error_token'), $e->getMessage())
+ ));
+ }
+
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ public function oauth_callback() {
+ $this->load->language('extension/payment/squareup');
+
+ if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('error_permission')
+ ));
+
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ $this->load->model('setting/setting');
+
+ $this->load->library('squareup');
+
+ if (isset($this->request->get['error']) || isset($this->request->get['error_description'])) {
+ // auth error
+ if ($this->request->get['error'] == 'access_denied' && $this->request->get['error_description'] == 'user_denied') {
+ // user rejected giving auth permissions to his store
+ $this->pushAlert(array(
+ 'type' => 'warning',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('error_user_rejected_connect_attempt')
+ ));
+ }
+
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ // verify parameters for the redirect from Square (against random url crawling)
+ if (!isset($this->request->get['state']) || !isset($this->request->get['code']) || !isset($this->request->get['response_type'])) {
+ // missing or wrong info
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('error_possible_xss')
+ ));
+
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ // verify the state (against cross site requests)
+ if (!isset($this->session->data['payment_squareup_oauth_state']) || $this->session->data['payment_squareup_oauth_state'] != $this->request->get['state']) {
+ // state mismatch
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('error_possible_xss')
+ ));
+
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ try {
+ $token = $this->squareup->exchangeCodeForAccessToken($this->request->get['code']);
+
+ $previous_setting = $this->model_setting_setting->getSetting('payment_squareup');
+
+ $previous_setting['payment_squareup_locations'] = $this->squareup->fetchLocations($token['access_token'], $first_location_id);
+
+ if (
+ !isset($previous_setting['payment_squareup_location_id']) ||
+ (isset($previous_setting['payment_squareup_location_id']) && !in_array(
+ $previous_setting['payment_squareup_location_id'],
+ array_map(
+ function($location) {
+ return $location['id'];
+ },
+ $previous_setting['payment_squareup_locations']
+ )
+ ))
+ ) {
+ $previous_setting['payment_squareup_location_id'] = $first_location_id;
+ }
+
+ if (!$this->config->get('payment_squareup_sandbox_locations') && $this->config->get('payment_squareup_sandbox_token')) {
+ $previous_setting['payment_squareup_sandbox_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_sandbox_token'), $first_location_id);
+ $previous_setting['payment_squareup_sandbox_location_id'] = $first_location_id;
+ }
+
+ $previous_setting['payment_squareup_merchant_id'] = $token['merchant_id'];
+ $previous_setting['payment_squareup_merchant_name'] = ''; // only available in v1 of the API, not populated for now
+ $previous_setting['payment_squareup_access_token'] = $token['access_token'];
+ $previous_setting['payment_squareup_access_token_expires'] = $token['expires_at'];
+
+ $this->model_setting_setting->editSetting('payment_squareup', $previous_setting);
+
+ unset($this->session->data['payment_squareup_oauth_state']);
+ unset($this->session->data['payment_squareup_oauth_redirect']);
+
+ $this->pushAlert(array(
+ 'type' => 'success',
+ 'icon' => 'exclamation-circle',
+ 'text' => $this->language->get('text_refresh_access_token_success')
+ ));
+ } catch (\Squareup\Exception $e) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => sprintf($this->language->get('error_token'), $e->getMessage())
+ ));
+ }
+
+ $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true));
+ }
+
+ public function capture() {
+ $this->transactionAction(function($transaction_info, &$json) {
+ $updated_transaction = $this->squareup->captureTransaction($transaction_info['location_id'], $transaction_info['transaction_id']);
+
+ $status = $updated_transaction['tenders'][0]['card_details']['status'];
+
+ $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status);
+
+ $json['order_history_data'] = array(
+ 'notify' => 1,
+ 'order_id' => $transaction_info['order_id'],
+ 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id'], $status),
+ 'comment' => $this->language->get('squareup_status_comment_' . strtolower($status)),
+ );
+
+ $json['success'] = $this->language->get('text_success_capture');
+ });
+ }
+
+ public function void() {
+ $this->transactionAction(function($transaction_info, &$json) {
+ $updated_transaction = $this->squareup->voidTransaction($transaction_info['location_id'], $transaction_info['transaction_id']);
+
+ $status = $updated_transaction['tenders'][0]['card_details']['status'];
+
+ $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status);
+
+ $json['order_history_data'] = array(
+ 'notify' => 1,
+ 'order_id' => $transaction_info['order_id'],
+ 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id'], $status),
+ 'comment' => $this->language->get('squareup_status_comment_' . strtolower($status)),
+ );
+
+ $json['success'] = $this->language->get('text_success_void');
+ });
+ }
+
+ public function refund() {
+ $this->transactionAction(function($transaction_info, &$json) {
+ if (!empty($this->request->post['reason'])) {
+ $reason = $this->request->post['reason'];
+ } else {
+ $reason = $this->language->get('text_no_reason_provided');
+ }
+
+ if (!empty($this->request->post['amount'])) {
+ $amount = preg_replace('~[^0-9\.\,]~', '', $this->request->post['amount']);
+
+ if (strpos($amount, ',') !== FALSE && strpos($amount, '.') !== FALSE) {
+ $amount = (float)str_replace(',', '', $amount);
+ } else if (strpos($amount, ',') !== FALSE && strpos($amount, '.') === FALSE) {
+ $amount = (float)str_replace(',', '.', $amount);
+ } else {
+ $amount = (float)$amount;
+ }
+ } else {
+ $amount = 0;
+ }
+
+ $currency = $transaction_info['transaction_currency'];
+ $tenders = @json_decode($transaction_info['tenders'], true);
+
+ $updated_transaction = $this->squareup->refundTransaction($transaction_info['location_id'], $transaction_info['transaction_id'], $reason, $amount, $currency, $tenders[0]['id']);
+
+ $status = $updated_transaction['tenders'][0]['card_details']['status'];
+
+ $refunds = array();
+
+ if (!empty($updated_transaction['refunds'])) {
+ $refunds = $updated_transaction['refunds'];
+ }
+
+ $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status, $refunds);
+
+ $last_refund = array_pop($refunds);
+
+ if ($last_refund) {
+ $refunded_amount = $this->currency->format(
+ $this->squareup->standardDenomination(
+ $last_refund['amount_money']['amount'],
+ $last_refund['amount_money']['currency']
+ ),
+ $last_refund['amount_money']['currency']
+ );
+
+ $comment = sprintf($this->language->get('text_refunded_amount'), $refunded_amount, $last_refund['status'], $last_refund['reason']);
+
+ $json['order_history_data'] = array(
+ 'notify' => 1,
+ 'order_id' => $transaction_info['order_id'],
+ 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id']),
+ 'comment' => $comment,
+ );
+
+ $json['success'] = $this->language->get('text_success_refund');
+ } else {
+ $json['error'] = $this->language->get('error_no_refund');
+ }
+ });
+ }
+
+ public function order() {
+ $this->load->language('extension/payment/squareup');
+
+ $data['url_list_transactions'] = html_entity_decode($this->url->link('extension/payment/squareup/transactions', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'] . '&page={PAGE}', true));
+ $data['user_token'] = $this->session->data['user_token'];
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
+
+ // API login
+ $this->load->model('user/api');
+
+ $api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
+
+ if ($api_info && $this->user->hasPermission('modify', 'sale/order')) {
+ $session = new Session($this->config->get('session_engine'), $this->registry);
+
+ $session->start();
+
+ $this->model_user_api->deleteApiSessionBySessonId($session->getId());
+
+ $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']);
+
+ $session->data['api_id'] = $api_info['api_id'];
+
+ $data['api_token'] = $session->getId();
+ } else {
+ $data['api_token'] = '';
+ }
+
+ return $this->load->view('extension/payment/squareup_order', $data);
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/squareup');
+
+ $this->model_extension_payment_squareup->createTables();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/squareup');
+
+ $this->model_extension_payment_squareup->dropTables();
+ }
+
+ public function recurringButtons() {
+ if (!$this->user->hasPermission('modify', 'sale/recurring')) {
+ return;
+ }
+
+ $this->load->model('extension/payment/squareup');
+
+ $this->load->language('extension/payment/squareup');
+
+ if (isset($this->request->get['order_recurring_id'])) {
+ $order_recurring_id = $this->request->get['order_recurring_id'];
+ } else {
+ $order_recurring_id = 0;
+ }
+
+ $recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id);
+
+ $data['button_text'] = $this->language->get('button_cancel_recurring');
+
+ if ($recurring_info['status'] == ModelExtensionPaymentSquareup::RECURRING_ACTIVE) {
+ $data['order_recurring_id'] = $order_recurring_id;
+ } else {
+ $data['order_recurring_id'] = '';
+ }
+
+ $this->load->model('sale/order');
+
+ $order_info = $this->model_sale_order->getOrder($recurring_info['order_id']);
+
+ $data['order_id'] = $recurring_info['order_id'];
+ $data['store_id'] = $order_info['store_id'];
+ $data['order_status_id'] = $order_info['order_status_id'];
+ $data['comment'] = $this->language->get('text_order_history_cancel');
+ $data['notify'] = 1;
+
+ $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
+
+ // API login
+ $this->load->model('user/api');
+
+ $api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
+
+ if ($api_info && $this->user->hasPermission('modify', 'sale/order')) {
+ $session = new Session($this->config->get('session_engine'), $this->registry);
+
+ $session->start();
+
+ $this->model_user_api->deleteApiSessionBySessonId($session->getId());
+
+ $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']);
+
+ $session->data['api_id'] = $api_info['api_id'];
+
+ $data['api_token'] = $session->getId();
+ } else {
+ $data['api_token'] = '';
+ }
+
+ $data['cancel'] = html_entity_decode($this->url->link('extension/payment/squareup/recurringCancel', 'order_recurring_id=' . $order_recurring_id . '&user_token=' . $this->session->data['user_token'], true));
+
+ return $this->load->view('extension/payment/squareup_recurring_buttons', $data);
+ }
+
+ public function recurringCancel() {
+ $this->load->language('extension/payment/squareup');
+
+ $json = array();
+
+ if (!$this->user->hasPermission('modify', 'sale/recurring')) {
+ $json['error'] = $this->language->get('error_permission_recurring');
+ } else {
+ $this->load->model('sale/recurring');
+
+ if (isset($this->request->get['order_recurring_id'])) {
+ $order_recurring_id = $this->request->get['order_recurring_id'];
+ } else {
+ $order_recurring_id = 0;
+ }
+
+ $recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id);
+
+ if ($recurring_info) {
+ $this->load->model('extension/payment/squareup');
+
+ $this->model_extension_payment_squareup->editOrderRecurringStatus($order_recurring_id, ModelExtensionPaymentSquareup::RECURRING_CANCELLED);
+
+ $json['success'] = $this->language->get('text_canceled_success');
+
+ } else {
+ $json['error'] = $this->language->get('error_not_found');
+ }
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (empty($this->request->post['payment_squareup_client_id']) || strlen($this->request->post['payment_squareup_client_id']) > 32) {
+ $this->error['client_id'] = $this->language->get('error_client_id');
+ }
+
+ if (empty($this->request->post['payment_squareup_client_secret']) || strlen($this->request->post['payment_squareup_client_secret']) > 50) {
+ $this->error['client_secret'] = $this->language->get('error_client_secret');
+ }
+
+ if (!empty($this->request->post['payment_squareup_enable_sandbox'])) {
+ if (empty($this->request->post['payment_squareup_sandbox_client_id']) || strlen($this->request->post['payment_squareup_sandbox_client_id']) > 42) {
+ $this->error['sandbox_client_id'] = $this->language->get('error_sandbox_client_id');
+ }
+
+ if (empty($this->request->post['payment_squareup_sandbox_token']) || strlen($this->request->post['payment_squareup_sandbox_token']) > 42) {
+ $this->error['sandbox_token'] = $this->language->get('error_sandbox_token');
+ }
+
+ if ($this->config->get('payment_squareup_merchant_id') && !$this->config->get('payment_squareup_sandbox_locations')) {
+ $this->error['warning'] = $this->language->get('text_no_appropriate_locations_warning');
+ }
+
+ if ($this->config->get('payment_squareup_sandbox_locations') && isset($this->request->post['payment_squareup_sandbox_location_id']) && !in_array($this->request->post['payment_squareup_sandbox_location_id'], array_map(function($location) {
+ return $location['id'];
+ }, $this->config->get('payment_squareup_sandbox_locations')))) {
+ $this->error['location'] = $this->language->get('error_no_location_selected');
+ }
+ } else {
+ if ($this->config->get('payment_squareup_merchant_id') && !$this->config->get('payment_squareup_locations')) {
+ $this->error['warning'] = $this->language->get('text_no_appropriate_locations_warning');
+ }
+
+ if ($this->config->get('payment_squareup_locations') && isset($this->request->post['payment_squareup_location_id']) && !in_array($this->request->post['payment_squareup_location_id'], array_map(function($location) {
+ return $location['id'];
+ }, $this->config->get('payment_squareup_locations')))) {
+ $this->error['location'] = $this->language->get('error_no_location_selected');
+ }
+ }
+
+ if (!empty($this->request->post['payment_squareup_cron_email_status'])) {
+ if (!filter_var($this->request->post['payment_squareup_cron_email'], FILTER_VALIDATE_EMAIL)) {
+ $this->error['cron_email'] = $this->language->get('error_invalid_email');
+ }
+ }
+
+ if (!isset($this->request->get['save_and_auth']) && empty($this->request->post['payment_squareup_cron_acknowledge'])) {
+ $this->error['cron_acknowledge'] = $this->language->get('error_cron_acknowledge');
+ }
+
+ if ($this->error && empty($this->error['warning'])) {
+ $this->error['warning'] = $this->language->get('error_form');
+ }
+
+ return !$this->error;
+ }
+
+ protected function transactionAction($callback) {
+ $this->load->language('extension/payment/squareup');
+
+ $this->load->model('extension/payment/squareup');
+
+ $this->load->library('squareup');
+
+ $json = array();
+
+ if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) {
+ $json['error'] = $this->language->get('error_permission');
+ }
+
+ if (isset($this->request->get['squareup_transaction_id'])) {
+ $squareup_transaction_id = $this->request->get['squareup_transaction_id'];
+ } else {
+ $squareup_transaction_id = 0;
+ }
+
+ $transaction_info = $this->model_extension_payment_squareup->getTransaction($squareup_transaction_id);
+
+ if (empty($transaction_info)) {
+ $json['error'] = $this->language->get('error_transaction_missing');
+ } else {
+ try {
+ $callback($transaction_info, $json);
+ } catch (\Squareup\Exception $e) {
+ $json['error'] = $e->getMessage();
+ }
+ }
+
+ if (isset($this->request->get['preserve_alert'])) {
+ if (!empty($json['error'])) {
+ $this->pushAlert(array(
+ 'type' => 'danger',
+ 'icon' => 'exclamation-circle',
+ 'text' => $json['error']
+ ));
+ }
+
+ if (!empty($json['success'])) {
+ $this->pushAlert(array(
+ 'type' => 'success',
+ 'icon' => 'exclamation-circle',
+ 'text' => $json['success']
+ ));
+ }
+ }
+
+ $this->response->addHeader('Content-Type: application/json');
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function pushAlert($alert) {
+ $this->session->data['payment_squareup_alerts'][] = $alert;
+ }
+
+ protected function pullAlerts() {
+ if (isset($this->session->data['payment_squareup_alerts'])) {
+ return $this->session->data['payment_squareup_alerts'];
+ } else {
+ return array();
+ }
+ }
+
+ protected function clearAlerts() {
+ unset($this->session->data['payment_squareup_alerts']);
+ }
+
+ protected function getSettingValue($key, $default = null, $checkbox = false) {
+ if ($checkbox) {
+ if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post[$key])) {
+ return $default;
+ } else {
+ return $this->config->get($key);
+ }
+ }
+
+ if (isset($this->request->post[$key])) {
+ return $this->request->post[$key];
+ } else if ($this->config->has($key)) {
+ return $this->config->get($key);
+ } else {
+ return $default;
+ }
+ }
+
+ protected function getValidationError($key) {
+ if (isset($this->error[$key])) {
+ return $this->error[$key];
+ } else {
+ return '';
+ }
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/twocheckout.php b/public/admin/controller/extension/payment/twocheckout.php
new file mode 100644
index 0000000..38ff762
--- /dev/null
+++ b/public/admin/controller/extension/payment/twocheckout.php
@@ -0,0 +1,143 @@
+<?php
+class ControllerExtensionPaymentTwoCheckout extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/twocheckout');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_twocheckout', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['account'])) {
+ $data['error_account'] = $this->error['account'];
+ } else {
+ $data['error_account'] = '';
+ }
+
+ if (isset($this->error['secret'])) {
+ $data['error_secret'] = $this->error['secret'];
+ } else {
+ $data['error_secret'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/twocheckout', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/twocheckout', '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_twocheckout_account'])) {
+ $data['payment_twocheckout_account'] = $this->request->post['payment_twocheckout_account'];
+ } else {
+ $data['payment_twocheckout_account'] = $this->config->get('payment_twocheckout_account');
+ }
+
+ if (isset($this->request->post['payment_twocheckout_secret'])) {
+ $data['payment_twocheckout_secret'] = $this->request->post['payment_twocheckout_secret'];
+ } else {
+ $data['payment_twocheckout_secret'] = $this->config->get('payment_twocheckout_secret');
+ }
+
+ if (isset($this->request->post['payment_twocheckout_display'])) {
+ $data['payment_twocheckout_display'] = $this->request->post['payment_twocheckout_display'];
+ } else {
+ $data['payment_twocheckout_display'] = $this->config->get('payment_twocheckout_display');
+ }
+
+ if (isset($this->request->post['payment_twocheckout_test'])) {
+ $data['payment_twocheckout_test'] = $this->request->post['payment_twocheckout_test'];
+ } else {
+ $data['payment_twocheckout_test'] = $this->config->get('payment_twocheckout_test');
+ }
+
+ if (isset($this->request->post['payment_twocheckout_total'])) {
+ $data['payment_twocheckout_total'] = $this->request->post['payment_twocheckout_total'];
+ } else {
+ $data['payment_twocheckout_total'] = $this->config->get('payment_twocheckout_total');
+ }
+
+ if (isset($this->request->post['payment_twocheckout_order_status_id'])) {
+ $data['payment_twocheckout_order_status_id'] = $this->request->post['payment_twocheckout_order_status_id'];
+ } else {
+ $data['payment_twocheckout_order_status_id'] = $this->config->get('payment_twocheckout_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_twocheckout_geo_zone_id'])) {
+ $data['payment_twocheckout_geo_zone_id'] = $this->request->post['payment_twocheckout_geo_zone_id'];
+ } else {
+ $data['payment_twocheckout_geo_zone_id'] = $this->config->get('payment_twocheckout_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_twocheckout_status'])) {
+ $data['payment_twocheckout_status'] = $this->request->post['payment_twocheckout_status'];
+ } else {
+ $data['payment_twocheckout_status'] = $this->config->get('payment_twocheckout_status');
+ }
+
+ if (isset($this->request->post['payment_twocheckout_sort_order'])) {
+ $data['payment_twocheckout_sort_order'] = $this->request->post['payment_twocheckout_sort_order'];
+ } else {
+ $data['payment_twocheckout_sort_order'] = $this->config->get('payment_twocheckout_sort_order');
+ }
+
+ $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/twocheckout', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/twocheckout')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_twocheckout_account']) {
+ $this->error['account'] = $this->language->get('error_account');
+ }
+
+ if (!$this->request->post['payment_twocheckout_secret']) {
+ $this->error['secret'] = $this->language->get('error_secret');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/web_payment_software.php b/public/admin/controller/extension/payment/web_payment_software.php
new file mode 100644
index 0000000..fa3a467
--- /dev/null
+++ b/public/admin/controller/extension/payment/web_payment_software.php
@@ -0,0 +1,142 @@
+<?php
+class ControllerExtensionPaymentWebPaymentSoftware extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/web_payment_software');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_web_payment_software', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['login'])) {
+ $data['error_login'] = $this->error['login'];
+ } else {
+ $data['error_login'] = '';
+ }
+
+ if (isset($this->error['key'])) {
+ $data['error_key'] = $this->error['key'];
+ } else {
+ $data['error_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/web_payment_software', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/web_payment_software', '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_web_payment_software_merchant_name'])) {
+ $data['payment_web_payment_software_merchant_name'] = $this->request->post['payment_web_payment_software_merchant_name'];
+ } else {
+ $data['payment_web_payment_software_merchant_name'] = $this->config->get('payment_web_payment_software_merchant_name');
+ }
+
+ if (isset($this->request->post['payment_web_payment_software_merchant_key'])) {
+ $data['payment_web_payment_software_merchant_key'] = $this->request->post['payment_web_payment_software_merchant_key'];
+ } else {
+ $data['payment_web_payment_software_merchant_key'] = $this->config->get('payment_web_payment_software_merchant_key');
+ }
+
+ if (isset($this->request->post['payment_web_payment_software_mode'])) {
+ $data['payment_web_payment_software_mode'] = $this->request->post['payment_web_payment_software_mode'];
+ } else {
+ $data['payment_web_payment_software_mode'] = $this->config->get('payment_web_payment_software_mode');
+ }
+
+ if (isset($this->request->post['payment_web_payment_software_method'])) {
+ $data['payment_web_payment_software_method'] = $this->request->post['payment_web_payment_software_method'];
+ } else {
+ $data['payment_web_payment_software_method'] = $this->config->get('payment_web_payment_software_method');
+ }
+
+ if (isset($this->request->post['payment_web_payment_software_order_status_id'])) {
+ $data['payment_web_payment_software_order_status_id'] = $this->request->post['payment_web_payment_software_order_status_id'];
+ } else {
+ $data['payment_web_payment_software_order_status_id'] = $this->config->get('payment_web_payment_software_order_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_web_payment_software_geo_zone_id'])) {
+ $data['payment_web_payment_software_geo_zone_id'] = $this->request->post['payment_web_payment_software_geo_zone_id'];
+ } else {
+ $data['payment_web_payment_software_geo_zone_id'] = $this->config->get('payment_web_payment_software_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_web_payment_software_status'])) {
+ $data['payment_web_payment_software_status'] = $this->request->post['payment_web_payment_software_status'];
+ } else {
+ $data['payment_web_payment_software_status'] = $this->config->get('payment_web_payment_software_status');
+ }
+
+ if (isset($this->request->post['payment_web_payment_software_total'])) {
+ $data['payment_web_payment_software_total'] = $this->request->post['payment_web_payment_software_total'];
+ } else {
+ $data['payment_web_payment_software_total'] = $this->config->get('payment_web_payment_software_total');
+ }
+
+ if (isset($this->request->post['payment_web_payment_software_sort_order'])) {
+ $data['payment_web_payment_software_sort_order'] = $this->request->post['payment_web_payment_software_sort_order'];
+ } else {
+ $data['payment_web_payment_software_sort_order'] = $this->config->get('payment_web_payment_software_sort_order');
+ }
+
+ $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/web_payment_software', $data));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/web_payment_software')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_web_payment_software_merchant_name']) {
+ $this->error['login'] = $this->language->get('error_login');
+ }
+
+ if (!$this->request->post['payment_web_payment_software_merchant_key']) {
+ $this->error['key'] = $this->language->get('error_key');
+ }
+
+ return !$this->error;
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/extension/payment/wechat_pay.php b/public/admin/controller/extension/payment/wechat_pay.php
new file mode 100644
index 0000000..754bb13
--- /dev/null
+++ b/public/admin/controller/extension/payment/wechat_pay.php
@@ -0,0 +1,177 @@
+<?php
+/**
+ * @package OpenCart
+ * @author Meng Wenbin
+ * @copyright Copyright (c) 2010 - 2017, Chengdu Guangda Network Technology Co. Ltd. (https://www.opencart.cn/)
+ * @license https://opensource.org/licenses/GPL-3.0
+ * @link https://www.opencart.cn
+ */
+
+class ControllerExtensionPaymentWechatPay extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/wechat_pay');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_wechat_pay', $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));
+ }
+
+ if (isset($this->error['warning'])) {
+ $data['error_warning'] = $this->error['warning'];
+ } else {
+ $data['error_warning'] = '';
+ }
+
+ if (isset($this->error['app_id'])) {
+ $data['error_app_id'] = $this->error['app_id'];
+ } else {
+ $data['error_app_id'] = '';
+ }
+
+ if (isset($this->error['app_secret'])) {
+ $data['error_app_secret'] = $this->error['app_secret'];
+ } else {
+ $data['error_app_secret'] = '';
+ }
+
+ if (isset($this->error['mch_id'])) {
+ $data['error_mch_id'] = $this->error['mch_id'];
+ } else {
+ $data['error_mch_id'] = '';
+ }
+
+ if (isset($this->error['api_secret'])) {
+ $data['error_api_secret'] = $this->error['api_secret'];
+ } else {
+ $data['error_api_secret'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/wechat_pay', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/wechat_pay', '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_wechat_pay_app_id'])) {
+ $data['payment_wechat_pay_app_id'] = $this->request->post['payment_wechat_pay_app_id'];
+ } else {
+ $data['payment_wechat_pay_app_id'] = $this->config->get('payment_wechat_pay_app_id');
+ }
+
+ if (isset($this->request->post['payment_wechat_pay_app_secret'])) {
+ $data['payment_wechat_pay_app_secret'] = $this->request->post['payment_wechat_pay_app_secret'];
+ } else {
+ $data['payment_wechat_pay_app_secret'] = $this->config->get('payment_wechat_pay_app_secret');
+ }
+
+ if (isset($this->request->post['payment_wechat_pay_mch_id'])) {
+ $data['payment_wechat_pay_mch_id'] = $this->request->post['payment_wechat_pay_mch_id'];
+ } else {
+ $data['payment_wechat_pay_mch_id'] = $this->config->get('payment_wechat_pay_mch_id');
+ }
+
+ if (isset($this->request->post['payment_wechat_pay_api_secret'])) {
+ $data['payment_wechat_pay_api_secret'] = $this->request->post['payment_wechat_pay_api_secret'];
+ } else {
+ $data['payment_wechat_pay_api_secret'] = $this->config->get('payment_wechat_pay_api_secret');
+ }
+
+ if (isset($this->request->post['payment_wechat_pay_total'])) {
+ $data['payment_wechat_pay_total'] = $this->request->post['payment_wechat_pay_total'];
+ } else {
+ $data['payment_wechat_pay_total'] = $this->config->get('payment_wechat_pay_total');
+ }
+
+ if (isset($this->request->post['payment_wechat_pay_currency'])) {
+ $data['payment_wechat_pay_currency'] = $this->request->post['payment_wechat_pay_currency'];
+ } else {
+ $data['payment_wechat_pay_currency'] = $this->config->get('payment_wechat_pay_currency');
+ }
+
+ if (isset($this->request->post['payment_wechat_pay_completed_status_id'])) {
+ $data['payment_wechat_pay_completed_status_id'] = $this->request->post['payment_wechat_pay_completed_status_id'];
+ } else {
+ $data['payment_wechat_pay_completed_status_id'] = $this->config->get('payment_wechat_pay_completed_status_id');
+ }
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_wechat_pay_geo_zone_id'])) {
+ $data['payment_wechat_pay_geo_zone_id'] = $this->request->post['payment_wechat_pay_geo_zone_id'];
+ } else {
+ $data['payment_wechat_pay_geo_zone_id'] = $this->config->get('payment_wechat_pay_geo_zone_id');
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ if (isset($this->request->post['payment_wechat_pay_status'])) {
+ $data['payment_wechat_pay_status'] = $this->request->post['payment_wechat_pay_status'];
+ } else {
+ $data['payment_wechat_pay_status'] = $this->config->get('payment_wechat_pay_status');
+ }
+
+ if (isset($this->request->post['payment_wechat_pay_sort_order'])) {
+ $data['payment_wechat_pay_sort_order'] = $this->request->post['payment_wechat_pay_sort_order'];
+ } else {
+ $data['payment_wechat_pay_sort_order'] = $this->config->get('payment_wechat_pay_sort_order');
+ }
+
+ $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/wechat_pay', $data));
+ }
+
+ private function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/wechat_pay')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_wechat_pay_app_id']) {
+ $this->error['app_id'] = $this->language->get('error_app_id');
+ }
+
+ if (!$this->request->post['payment_wechat_pay_app_secret']) {
+ $this->error['app_secret'] = $this->language->get('error_app_secret');
+ }
+
+ if (!$this->request->post['payment_wechat_pay_mch_id']) {
+ $this->error['mch_id'] = $this->language->get('error_mch_id');
+ }
+
+ if (!$this->request->post['payment_wechat_pay_api_secret']) {
+ $this->error['api_secret'] = $this->language->get('error_api_secret');
+ }
+
+ return !$this->error;
+ }
+}
diff --git a/public/admin/controller/extension/payment/worldpay.php b/public/admin/controller/extension/payment/worldpay.php
new file mode 100644
index 0000000..d421bab
--- /dev/null
+++ b/public/admin/controller/extension/payment/worldpay.php
@@ -0,0 +1,287 @@
+<?php
+class ControllerExtensionPaymentWorldpay extends Controller {
+ private $error = array();
+
+ public function index() {
+ $this->load->language('extension/payment/worldpay');
+
+ $this->document->setTitle($this->language->get('heading_title'));
+
+ $this->load->model('setting/setting');
+
+ if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
+ $this->model_setting_setting->editSetting('payment_worldpay', $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));
+ }
+
+ if (isset($this->error['error_service_key'])) {
+ $data['error_service_key'] = $this->error['error_service_key'];
+ } else {
+ $data['error_service_key'] = '';
+ }
+
+ if (isset($this->error['error_client_key'])) {
+ $data['error_client_key'] = $this->error['error_client_key'];
+ } else {
+ $data['error_client_key'] = '';
+ }
+
+ $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)
+ );
+
+ $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)
+ );
+
+ $data['breadcrumbs'][] = array(
+ 'text' => $this->language->get('heading_title'),
+ 'href' => $this->url->link('extension/payment/worldpay', 'user_token=' . $this->session->data['user_token'], true)
+ );
+
+ $data['action'] = $this->url->link('extension/payment/worldpay', '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_worldpay_service_key'])) {
+ $data['payment_worldpay_service_key'] = $this->request->post['payment_worldpay_service_key'];
+ } else {
+ $data['payment_worldpay_service_key'] = $this->config->get('payment_worldpay_service_key');
+ }
+
+ if (isset($this->request->post['payment_worldpay_client_key'])) {
+ $data['payment_worldpay_client_key'] = $this->request->post['payment_worldpay_client_key'];
+ } else {
+ $data['payment_worldpay_client_key'] = $this->config->get('payment_worldpay_client_key');
+ }
+
+ if (isset($this->request->post['payment_worldpay_total'])) {
+ $data['payment_worldpay_total'] = $this->request->post['payment_worldpay_total'];
+ } else {
+ $data['payment_worldpay_total'] = $this->config->get('payment_worldpay_total');
+ }
+
+ if (isset($this->request->post['payment_worldpay_card'])) {
+ $data['payment_worldpay_card'] = $this->request->post['payment_worldpay_card'];
+ } else {
+ $data['payment_worldpay_card'] = $this->config->get('payment_worldpay_card');
+ }
+
+ if (isset($this->request->post['payment_worldpay_order_status_id'])) {
+ $data['payment_worldpay_order_status_id'] = $this->request->post['payment_worldpay_order_status_id'];
+ } else {
+ $data['payment_worldpay_order_status_id'] = $this->config->get('payment_worldpay_order_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_geo_zone_id'])) {
+ $data['payment_worldpay_geo_zone_id'] = $this->request->post['payment_worldpay_geo_zone_id'];
+ } else {
+ $data['payment_worldpay_geo_zone_id'] = $this->config->get('payment_worldpay_geo_zone_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_status'])) {
+ $data['payment_worldpay_status'] = $this->request->post['payment_worldpay_status'];
+ } else {
+ $data['payment_worldpay_status'] = $this->config->get('payment_worldpay_status');
+ }
+
+ if (isset($this->request->post['payment_worldpay_debug'])) {
+ $data['payment_worldpay_debug'] = $this->request->post['payment_worldpay_debug'];
+ } else {
+ $data['payment_worldpay_debug'] = $this->config->get('payment_worldpay_debug');
+ }
+
+ if (isset($this->request->post['payment_worldpay_sort_order'])) {
+ $data['payment_worldpay_sort_order'] = $this->request->post['payment_worldpay_sort_order'];
+ } else {
+ $data['payment_worldpay_sort_order'] = $this->config->get('payment_worldpay_sort_order');
+ }
+
+ if (isset($this->request->post['payment_worldpay_secret_token'])) {
+ $data['payment_worldpay_secret_token'] = $this->request->post['payment_worldpay_secret_token'];
+ } elseif ($this->config->get('payment_worldpay_secret_token')) {
+ $data['payment_worldpay_secret_token'] = $this->config->get('payment_worldpay_secret_token');
+ } else {
+ $data['payment_worldpay_secret_token'] = sha1(uniqid(mt_rand(), 1));
+ }
+
+ $data['payment_worldpay_webhook_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/worldpay/webhook&token=' . $data['payment_worldpay_secret_token'];
+
+ $data['payment_worldpay_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/worldpay/cron&token=' . $data['payment_worldpay_secret_token'];
+
+ if ($this->config->get('payment_worldpay_last_cron_job_run')) {
+ $data['payment_worldpay_last_cron_job_run'] = $this->config->get('payment_worldpay_last_cron_job_run');
+ } else {
+ $data['payment_worldpay_last_cron_job_run'] = '';
+ }
+
+ $this->load->model('localisation/geo_zone');
+
+ $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
+
+ $this->load->model('localisation/order_status');
+
+ $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
+
+ if (isset($this->request->post['payment_worldpay_success_status_id'])) {
+ $data['payment_worldpay_success_status_id'] = $this->request->post['payment_worldpay_success_status_id'];
+ } else {
+ $data['payment_worldpay_success_status_id'] = $this->config->get('payment_worldpay_success_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_failed_status_id'])) {
+ $data['payment_worldpay_failed_status_id'] = $this->request->post['payment_worldpay_failed_status_id'];
+ } else {
+ $data['payment_worldpay_failed_status_id'] = $this->config->get('payment_worldpay_failed_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_settled_status_id'])) {
+ $data['payment_worldpay_settled_status_id'] = $this->request->post['payment_worldpay_settled_status_id'];
+ } else {
+ $data['payment_worldpay_settled_status_id'] = $this->config->get('payment_worldpay_settled_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_refunded_status_id'])) {
+ $data['payment_worldpay_refunded_status_id'] = $this->request->post['payment_worldpay_refunded_status_id'];
+ } else {
+ $data['payment_worldpay_refunded_status_id'] = $this->config->get('payment_worldpay_refunded_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_partially_refunded_status_id'])) {
+ $data['payment_worldpay_partially_refunded_status_id'] = $this->request->post['payment_worldpay_partially_refunded_status_id'];
+ } else {
+ $data['payment_worldpay_partially_refunded_status_id'] = $this->config->get('payment_worldpay_partially_refunded_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_charged_back_status_id'])) {
+ $data['payment_worldpay_charged_back_status_id'] = $this->request->post['payment_worldpay_charged_back_status_id'];
+ } else {
+ $data['payment_worldpay_charged_back_status_id'] = $this->config->get('payment_worldpay_charged_back_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_information_requested_status_id'])) {
+ $data['payment_worldpay_information_requested_status_id'] = $this->request->post['payment_worldpay_information_requested_status_id'];
+ } else {
+ $data['payment_worldpay_information_requested_status_id'] = $this->config->get('payment_worldpay_information_requested_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_information_supplied_status_id'])) {
+ $data['payment_worldpay_information_supplied_status_id'] = $this->request->post['payment_worldpay_information_supplied_status_id'];
+ } else {
+ $data['payment_worldpay_information_supplied_status_id'] = $this->config->get('payment_worldpay_information_supplied_status_id');
+ }
+
+ if (isset($this->request->post['payment_worldpay_chargeback_reversed_status_id'])) {
+ $data['payment_worldpay_chargeback_reversed_status_id'] = $this->request->post['payment_worldpay_chargeback_reversed_status_id'];
+ } else {
+ $data['payment_worldpay_chargeback_reversed_status_id'] = $this->config->get('payment_worldpay_chargeback_reversed_status_id');
+ }
+
+ $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/worldpay', $data));
+ }
+
+ public function install() {
+ $this->load->model('extension/payment/worldpay');
+ $this->model_extension_payment_worldpay->install();
+ }
+
+ public function uninstall() {
+ $this->load->model('extension/payment/worldpay');
+ $this->model_extension_payment_worldpay->uninstall();
+ }
+
+ public function order() {
+
+ if ($this->config->get('payment_worldpay_status')) {
+
+ $this->load->model('extension/payment/worldpay');
+
+ $worldpay_order = $this->model_extension_payment_worldpay->getOrder($this->request->get['order_id']);
+
+ if (!empty($worldpay_order)) {
+ $this->load->language('extension/payment/worldpay');
+
+ $worldpay_order['total_released'] = $this->model_extension_payment_worldpay->getTotalReleased($worldpay_order['worldpay_order_id']);
+
+ $worldpay_order['total_formatted'] = $this->currency->format($worldpay_order['total'], $worldpay_order['currency_code'], false);
+ $worldpay_order['total_released_formatted'] = $this->currency->format($worldpay_order['total_released'], $worldpay_order['currency_code'], false);
+
+ $data['worldpay_order'] = $worldpay_order;
+
+ $data['order_id'] = $this->request->get['order_id'];
+
+ $data['user_token'] = $this->request->get['user_token'];
+
+ return $this->load->view('extension/payment/worldpay_order', $data);
+ }
+ }
+ }
+
+ public function refund() {
+ $this->load->language('extension/payment/worldpay');
+ $json = array();
+
+ if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) {
+ $this->load->model('extension/payment/worldpay');
+
+ $worldpay_order = $this->model_extension_payment_worldpay->getOrder($this->request->post['order_id']);
+
+ $refund_response = $this->model_extension_payment_worldpay->refund($this->request->post['order_id'], $this->request->post['amount']);
+
+ $this->model_extension_payment_worldpay->logger('Refund result: ' . print_r($refund_response, 1));
+
+ if ($refund_response['status'] == 'success') {
+ $this->model_extension_payment_worldpay->addTransaction($worldpay_order['worldpay_order_id'], 'refund', $this->request->post['amount'] * -1);
+
+ $total_refunded = $this->model_extension_payment_worldpay->getTotalRefunded($worldpay_order['worldpay_order_id']);
+ $total_released = $this->model_extension_payment_worldpay->getTotalReleased($worldpay_order['worldpay_order_id']);
+
+ $this->model_extension_payment_worldpay->updateRefundStatus($worldpay_order['worldpay_order_id'], 1);
+
+ $json['msg'] = $this->language->get('text_refund_ok_order');
+ $json['data'] = array();
+ $json['data']['created'] = date("Y-m-d H:i:s");
+ $json['data']['amount'] = $this->currency->format(($this->request->post['amount'] * -1), $worldpay_order['currency_code'], false);
+ $json['data']['total_released'] = $this->currency->format($total_released, $worldpay_order['currency_code'], false);
+ $json['data']['total_refund'] = $this->currency->format($total_refunded, $worldpay_order['currency_code'], false);
+ $json['data']['refund_status'] = 1;
+ $json['error'] = false;
+ } else {
+ $json['error'] = true;
+ $json['msg'] = isset($refund_response['message']) && !empty($refund_response['message']) ? (string)$refund_response['message'] : 'Unable to refund';
+ }
+ } else {
+ $json['error'] = true;
+ $json['msg'] = 'Missing data';
+ }
+
+ $this->response->setOutput(json_encode($json));
+ }
+
+ protected function validate() {
+ if (!$this->user->hasPermission('modify', 'extension/payment/worldpay')) {
+ $this->error['warning'] = $this->language->get('error_permission');
+ }
+
+ if (!$this->request->post['payment_worldpay_service_key']) {
+ $this->error['error_service_key'] = $this->language->get('error_service_key');
+ }
+
+ if (!$this->request->post['payment_worldpay_client_key']) {
+ $this->error['error_client_key'] = $this->language->get('error_client_key');
+ }
+
+ return !$this->error;
+ }
+}