diff --git a/README.md b/README.md index a170309..cda4e25 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ This repository contains the OpenCart PostFinance Checkout payment module that ## Documentation -* [English](https://plugin-documentation.postfinance-checkout.ch/pfpayments/opencart-2.3/1.0.10/docs/en/documentation.html) +* [English](https://plugin-documentation.postfinance-checkout.ch/pfpayments/opencart-2.3/1.0.11/docs/en/documentation.html) ## License -Please see the [license file](https://github.com/pfpayments/opencart-2.3/blob/1.0.10/LICENSE) for more information. \ No newline at end of file +Please see the [license file](https://github.com/pfpayments/opencart-2.3/blob/1.0.11/LICENSE) for more information. \ No newline at end of file diff --git a/docs/en/documentation.html b/docs/en/documentation.html index 7b03ccf..f9ac1de 100644 --- a/docs/en/documentation.html +++ b/docs/en/documentation.html @@ -21,7 +21,7 @@

Documentation

  • - + Source
  • @@ -48,7 +48,7 @@

    1. -

      Download the extension.

      +

      Download the extension.

    2. Extract the files and upload the content of the Upload directory into the root directory of your store using FTP/SSH.

      diff --git a/upload/catalog/controller/extension/postfinancecheckout/transaction.php b/upload/catalog/controller/extension/postfinancecheckout/transaction.php new file mode 100644 index 0000000..96a20e3 --- /dev/null +++ b/upload/catalog/controller/extension/postfinancecheckout/transaction.php @@ -0,0 +1,26 @@ +request->get['order_id']) && + \PostFinanceCheckout\Service\Transaction::instance($this->registry)->waitForStates($this->request->get['order_id'], + array( + \PostFinanceCheckout\Sdk\Model\TransactionState::FAILED + ), 5)) { + $transaction_info = \PostFinanceCheckout\Entity\TransactionInfo::loadByOrderId($this->registry, $this->request->get['order_id']); + unset($this->registry->get('session')->data['order_id']); + $this->session->data['error'] = $transaction_info->getFailureReason(); + } + else { + $this->session->data['error'] = $this->language->get('error'); //TODO error text + } + $this->response->redirect($this->createUrl('checkout/checkout', '')); + } + + protected function getRequiredPermission(){ + return ''; + } +} \ No newline at end of file diff --git a/upload/catalog/view/javascript/postfinancecheckout.js b/upload/catalog/view/javascript/postfinancecheckout.js index 3e628fc..fa9fb6f 100644 --- a/upload/catalog/view/javascript/postfinancecheckout.js +++ b/upload/catalog/view/javascript/postfinancecheckout.js @@ -80,7 +80,11 @@ PostFinanceCheckout.handler .setInitializeCallback(this.initialized); PostFinanceCheckout.handler - .setValidationCallback(this.validated); + .setValidationCallback(this.validated); + PostFinanceCheckout.handler + .setEnableSubmitCallback(this.enableConfirmButton); + PostFinanceCheckout.handler + .setDisableSubmitCallback(this.disableConfirmButton); PostFinanceCheckout.handler .create('postfinancecheckout-iframe-container'); } diff --git a/upload/catalog/view/theme/default/template/extension/payment/postfinancecheckout/iframe.tpl b/upload/catalog/view/theme/default/template/extension/payment/postfinancecheckout/iframe.tpl index aee8804..3038c21 100644 --- a/upload/catalog/view/theme/default/template/extension/payment/postfinancecheckout/iframe.tpl +++ b/upload/catalog/view/theme/default/template/extension/payment/postfinancecheckout/iframe.tpl @@ -5,13 +5,12 @@
    - -
    - + -
    +
    function initPostFinanceCheckoutIframe(){ if(typeof PostFinanceCheckout === 'undefined') { - setTimeout(initPostFinanceCheckoutIframe, 500); + Window.loadPostFinanceCheckoutTimeout = setTimeout(initPostFinanceCheckoutIframe, 500); } else { PostFinanceCheckout.init(''); } } + if(typeof Window.loadPostFinanceCheckoutTimeout !== 'undefined') { + clearTimeout(Window.loadPostFinanceCheckoutTimeout); + } jQuery().ready(initPostFinanceCheckoutIframe);
    \ No newline at end of file diff --git a/upload/system/library/postfinancecheckout/dynamic/catalog/controller.php b/upload/system/library/postfinancecheckout/dynamic/catalog/controller.php index ffdc22a..88b1cf5 100644 --- a/upload/system/library/postfinancecheckout/dynamic/catalog/controller.php +++ b/upload/system/library/postfinancecheckout/dynamic/catalog/controller.php @@ -40,6 +40,7 @@ public function confirm(){ catch (Exception $e) { \PostFinanceCheckoutHelper::instance($this->registry)->dbTransactionRollback(); \PostFinanceCheckoutHelper::instance($this->registry)->log($e->getMessage(), \PostFinanceCheckoutHelper::LOG_ERROR); + $this->load->language('extension/payment/postfinancecheckout'); $result['message'] = $this->language->get('error_confirmation'); unset($this->session->data['order_id']); // this order number cannot be used anymore } @@ -49,7 +50,7 @@ public function confirm(){ } private function confirmTransaction(){ - $transaction = PostFinanceCheckout\Service\Transaction::instance($this->registry)->getTransaction(array(), false, + $transaction = PostFinanceCheckout\Service\Transaction::instance($this->registry)->getTransaction($this->getOrderInfo(), false, array( \PostFinanceCheckout\Sdk\Model\TransactionState::PENDING )); @@ -63,6 +64,14 @@ private function confirmTransaction(){ throw new Exception('Transaction is not pending.'); } + + private function getOrderInfo() { + if(!isset($this->session->data['order_id'])) { + throw new Exception("No order_id to confirm."); + } + $this->load->model('checkout/order'); + return $this->model_checkout_order->getOrder($this->session->data['order_id']); + } protected function getRequiredPermission(){ return ''; diff --git a/upload/system/library/postfinancecheckout/helper.php b/upload/system/library/postfinancecheckout/helper.php index 8c0218e..1da09cf 100644 --- a/upload/system/library/postfinancecheckout/helper.php +++ b/upload/system/library/postfinancecheckout/helper.php @@ -14,6 +14,7 @@ class PostFinanceCheckoutHelper { * @var Registry */ private $registry; + private $xfeepro; private static $instance; private $catalog_url; const LOG_INFO = 2; @@ -302,7 +303,7 @@ public function getCustomer(){ } return array(); } - + /** * Formats the given amount for the given currency. * If no currency is given, the current session currency is used. If that is not set the shop configuration is used. @@ -317,7 +318,7 @@ public function formatAmount($amount, $currency = null){ } return $this->registry->get('currency')->format($amount, $currency, false, false); } - + /** * Rounds the amount like Xfee would * @@ -331,7 +332,7 @@ public function roundXfeeAmount($amount, $currency = null){ } $decimals = $this->registry->get('currency')->getDecimalPlace(); $mode = PHP_ROUND_HALF_UP; - if($amount < 0) { + if ($amount < 0) { $mode = PHP_ROUND_HALF_DOWN; } return round($amount, $decimals, $mode); @@ -461,15 +462,18 @@ public function getCache(){ } public function getSuccessUrl(){ - return PostFinanceCheckoutVersionHelper::createUrl($this->getCatalogUrl(), 'checkout/success', '', - $this->registry->get('config')->get('config_secure')); + return PostFinanceCheckoutVersionHelper::createUrl($this->getCatalogUrl(), 'checkout/success', array( + 'utm_nooverride' => 1 + ), $this->registry->get('config')->get('config_secure')); } public function getFailedUrl($order_id){ return str_replace('&', '&', - PostFinanceCheckoutVersionHelper::createUrl($this->getCatalogUrl(), 'checkout/checkout', array( - 'order_id' => $order_id - ), $this->registry->get('config')->get('config_secure'))); + PostFinanceCheckoutVersionHelper::createUrl($this->getCatalogUrl(), 'extension/postfinancecheckout/transaction/fail', + array( + 'order_id' => $order_id, + 'utm_nooverride' => 1 + ), $this->registry->get('config')->get('config_secure'))); } public function getWebhookUrl(){ @@ -605,6 +609,31 @@ public function getLimitEnd($page){ $limit = $this->registry->get('config')->get('config_limit_admin'); return $page * $limit; } + + /** + * Disable inc vat setting in xfeepro. Necessary to ensure taxes are calculated and transmitted correctly. + */ + public function xfeeproDisableIncVat() { + $config = $this->registry->get('config'); + $xfeepro = $config->get('xfeepro'); + if($xfeepro) { + $xfeepro = unserialize(base64_decode($xfeepro)); + $this->xfeepro = $xfeepro; + foreach($xfeepro['inc_vat'] as $i => $value) { + $xfeepro['inc_vat'][$i] = 0; + } + $config->set('xfeepro', base64_encode(serialize($xfeepro))); + } + } + + /** + * Restore xfeepro settings. + */ + public function xfeeProRestoreIncVat() { + if($this->xfeepro) { + $this->registry->get('config')->set('xfeepro', base64_encode(serialize($this->xfeepro))); + } + } public static function instance(Registry $registry){ if (self::$instance === null) { diff --git a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAdministration.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAdministration.ocmod.xml index 9120b15..480e328 100644 --- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAdministration.ocmod.xml +++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAdministration.ocmod.xml @@ -3,55 +3,25 @@ PostFinanceCheckoutAdministration postfinancecheckout administration: complete, refund and void from the OpenCart backend. - 1.0.2 + 1.1.0 Customweb GmbH http://github.com/postfinancecheckout-payment/opencart response->setOutput($this->load->view('sale/order_info.tpl', $data)); + $data['shipping'] = $this->url->link('sale/order/shipping', 'token=' . $this->session->data['token'] . '&order_id=' . (int)$this->request->get['order_id'], true); ]]> document->addScript('view/javascript/postfinancecheckout/order.js'); $this->load->model('extension/postfinancecheckout/order'); $data['postfinancecheckout_buttons'] = $this->model_extension_postfinancecheckout_order->getButtons((int)$this->request->get['order_id']); $data['postfinancecheckout_failed_jobs'] = $this->model_extension_postfinancecheckout_order->getFailedJobs((int)$this->request->get['order_id']); - $data['postfinancecheckout_tab'] = $this->load->controller('payment/' . $order_info['payment_code'] . '/order'); ]]> - - - ]]> - -
  • - -]]>
    -
    - - - ]]> - -
    - -
    - -]]>
    -
    - - - ]]> - -]]> - diff --git a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAlerts.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAlerts.ocmod.xml index 5b232ce..deeb44a 100644 --- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAlerts.ocmod.xml +++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAlerts.ocmod.xml @@ -2,7 +2,7 @@ PostFinanceCheckoutAlerts postfinancecheckout alerts: show open manual tasks and failed jobs. - 1.0.0 + 1.1.0 Customweb GmbH http://github.com/postfinancecheckout-payment/opencart diff --git a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutCore.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutCore.ocmod.xml index 71df69a..ad7a412 100644 --- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutCore.ocmod.xml +++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutCore.ocmod.xml @@ -3,26 +3,10 @@ PostFinanceCheckoutCore postfinancecheckout core: load payment methods. - 1.0.2 + 1.1.2 Customweb GmbH http://github.com/postfinancecheckout-payment/opencart - - - session->data['error'])) { - ]]> - request->get['order_id']) && \PostFinanceCheckoutHelper::instance($this->registry)->isValidOrder($this->request->get['order_id']) - && \PostFinanceCheckout\Service\Transaction::instance($this->registry)->waitForStates($this->request->get['order_id'], array(\PostFinanceCheckout\Sdk\Model\TransactionState::FAILED), 5)) { - $transaction_info = \PostFinanceCheckout\Entity\TransactionInfo::loadByOrderId($this->registry, $this->request->get['order_id']); - unset($this->registry->get('session')->data['order_id']); - $data['error_warning'] = $transaction_info->getFailureReason(); - } else - ]]> - - - + model_extension_extension->uninstall('payment', $value); @@ -44,10 +28,10 @@ ]]> - + - - @@ -102,19 +86,11 @@ ]]> - file) + - file)) - ]]> - - - -
    @@ -125,30 +101,6 @@ ]]> - - - - - - - - - - - - diff --git a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutEvents.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutEvents.ocmod.xml index e3f5542..6f0ee66 100644 --- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutEvents.ocmod.xml +++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutEvents.ocmod.xml @@ -3,15 +3,15 @@ PostFinanceCheckoutEvents postfinancecheckout events: handle events unavailable in Opencart 2.0.x and 2.1.x. - 1.0.1 + 1.1.0 Customweb GmbH http://github.com/postfinancecheckout-payment/opencart load->controller('common/cart'); + $data['analytics'] = array(); ]]> - load->controller('extension/postfinancecheckout/event/includeDeviceIdentifier'); @@ -26,20 +26,10 @@ ]]> - - - - ]]> - - ]]> - - load->controller('extension/postfinancecheckout/event/createMethodConfigurationFiles'); diff --git a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutFrontendPdf.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutFrontendPdf.ocmod.xml index 9fa082b..5d32107 100644 --- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutFrontendPdf.ocmod.xml +++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutFrontendPdf.ocmod.xml @@ -3,13 +3,13 @@ PostFinanceCheckoutFrontendPdf postfinancecheckout customer pdf: Allow customers to download invoices and packing slips. - 1.0.1 + 1.1.0 Customweb GmbH http://github.com/postfinancecheckout-payment/opencart config->get('config_template') . '/template/account/order_info.tpl')) { + $this->response->setOutput($this->load->view('account/order_info', $data)); ]]> load->model('extension/postfinancecheckout/order'); diff --git a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutJournalCompatibility.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutJournalCompatibility.ocmod.xml deleted file mode 100644 index 5a3c302..0000000 --- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutJournalCompatibility.ocmod.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - PostFinanceCheckoutJournalCompatibility - postfinancecheckout compatibility: patch for Journal Theme. - - 1.0.1 - Customweb GmbH - http://github.com/postfinancecheckout-payment/opencart - - - session->data['error'])) { - ]]> - request->get['order_id']) && \PostFinanceCheckoutHelper::instance($this->registry)->isValidOrder($this->request->get['order_id']) - && \PostFinanceCheckout\Service\Transaction::instance($this->registry)->waitForStates($this->request->get['order_id'], array(\PostFinanceCheckout\Sdk\Model\TransactionState::FAILED), 5)) { - $transaction_info = \PostFinanceCheckout\Entity\TransactionInfo::loadByOrderId($this->registry, $this->request->get['order_id']); - unset($this->registry->get('session')->data['order_id']); - $this->data['error_warning'] = $transaction_info->getFailureReason(); - } else - ]]> - - - diff --git a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutQuickCheckoutCompatibility.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutQuickCheckoutCompatibility.ocmod.xml index be5c5e3..ed95318 100644 --- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutQuickCheckoutCompatibility.ocmod.xml +++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutQuickCheckoutCompatibility.ocmod.xml @@ -3,7 +3,7 @@ PostFinanceCheckoutQuickCheckoutCompatibility postfinancecheckout compatibility: patch for Ajax Quick Checkout. - 1.0.2 + 1.1.0 Customweb GmbH http://github.com/postfinancecheckout-payment/opencart @@ -15,21 +15,5 @@ if(file_exists(modification(DIR_APPLICATION . 'model/extension/payment/' . $result['code'] . '.php'))){ ]]> - - - - - - - - diff --git a/upload/system/library/postfinancecheckout/modification/WalleeAdministration.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeAdministration.ocmod.xml deleted file mode 100644 index 5508c1a..0000000 --- a/upload/system/library/postfinancecheckout/modification/WalleeAdministration.ocmod.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - PostFinanceCheckoutAdministration - postfinancecheckout administration: complete, refund and void from the OpenCart backend. - - 1.0.0 - Customweb GmbH - http://github.com/postfinancecheckout-payment/opencart - - - url->link('sale/order/shipping', 'token=' . $this->session->data['token'] . '&order_id=' . (int)$this->request->get['order_id'], true); - ]]> - document->addScript('view/javascript/postfinancecheckout/order.js'); - $this->load->model('extension/postfinancecheckout/order'); - $data['postfinancecheckout_buttons'] = $this->model_extension_postfinancecheckout_order->getButtons((int)$this->request->get['order_id']); - $data['postfinancecheckout_failed_jobs'] = $this->model_extension_postfinancecheckout_order->getFailedJobs((int)$this->request->get['order_id']); - ]]> - - - - - - - ]]> - '; -document.adminToken = ''; -setPostFinanceCheckoutButtons(); -var postfinancecheckout_failed_jobs = ; -window.setTimeout(function() { - for (var i = 0; i < postfinancecheckout_failed_jobs.length; i++) { - addPostFinanceCheckoutError(postfinancecheckout_failed_jobs[i]); - } -}, 500); -]]> - - - diff --git a/upload/system/library/postfinancecheckout/modification/WalleeAlerts.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeAlerts.ocmod.xml deleted file mode 100644 index 5b232ce..0000000 --- a/upload/system/library/postfinancecheckout/modification/WalleeAlerts.ocmod.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - PostFinanceCheckoutAlerts - postfinancecheckout alerts: show open manual tasks and failed jobs. - 1.0.0 - Customweb GmbH - http://github.com/postfinancecheckout-payment/opencart - - - - load->model("extension/postfinancecheckout/alert"); - $data['postfinancecheckout_alerts_title'] = $this->model_extension_postfinancecheckout_alert->getAlertsTitle(); - $data['postfinancecheckout_alerts'] = $this->model_extension_postfinancecheckout_alert->getAlerts(); - $postfinancecheckout_alert_count = $this->model_extension_postfinancecheckout_alert->getAlertCount(); - ]]> - - - - - - - - - - ]]> - - - -
  • - - ]]>
    -
    -
    -
    diff --git a/upload/system/library/postfinancecheckout/modification/WalleeCore.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeCore.ocmod.xml deleted file mode 100644 index ed77e61..0000000 --- a/upload/system/library/postfinancecheckout/modification/WalleeCore.ocmod.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - PostFinanceCheckoutCore - postfinancecheckout core: load payment methods. - - 1.0.1 - Customweb GmbH - http://github.com/postfinancecheckout-payment/opencart - - - session->data['error'])) { - ]]> - request->get['order_id']) && \PostFinanceCheckoutHelper::instance($this->registry)->isValidOrder($this->request->get['order_id']) - && \PostFinanceCheckout\Service\Transaction::instance($this->registry)->waitForStates($this->request->get['order_id'], array(\PostFinanceCheckout\Sdk\Model\TransactionState::FAILED), 5)) { - $transaction_info = \PostFinanceCheckout\Entity\TransactionInfo::loadByOrderId($this->registry, $this->request->get['order_id']); - $data['error_warning'] = $transaction_info->getFailureReason(); - } else - ]]> - - - - - model_extension_extension->uninstall('payment', $value); - ]]> - model_extension_extension->uninstall('payment', $value); - } - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/upload/system/library/postfinancecheckout/modification/WalleeEvents.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeEvents.ocmod.xml deleted file mode 100644 index ed380c9..0000000 --- a/upload/system/library/postfinancecheckout/modification/WalleeEvents.ocmod.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - PostFinanceCheckoutEvents - postfinancecheckout events: handle events unavailable in Opencart 2.0.x and 2.1.x. - - 1.0.0 - Customweb GmbH - http://github.com/postfinancecheckout-payment/opencart - - - - load->controller('extension/postfinancecheckout/event/includeDeviceIdentifier'); - - \PostFinanceCheckoutHelper::instance($this->registry)->refreshWebhook(); - \PostFinanceCheckout\Entity\Cron::cleanUpHangingCrons($this->registry); - \PostFinanceCheckout\Entity\Cron::insertNewPendingCron($this->registry); - $postfinancecheckout_cron_token = \PostFinanceCheckout\Entity\Cron::getCurrentSecurityTokenForPendingCron($this->registry); - if($postfinancecheckout_cron_token) { - $data['postfinancecheckout_cron'] = \PostFinanceCheckoutVersionHelper::createUrl($this->url, 'extension/postfinancecheckout/cron', array('security_token' => $postfinancecheckout_cron_token), $this->config->get('config_secure')); - } - } catch (Exception $e) { \PostFinanceCheckoutHelper::instance($this->registry)->log($e->getMessage()); } - ]]> - - - - - - load->controller('extension/postfinancecheckout/event/createMethodConfigurationFiles'); - ]]> - - - diff --git a/upload/system/library/postfinancecheckout/modification/WalleeFrontendPdf.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeFrontendPdf.ocmod.xml deleted file mode 100644 index f335ebf..0000000 --- a/upload/system/library/postfinancecheckout/modification/WalleeFrontendPdf.ocmod.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - PostFinanceCheckoutFrontendPdf - postfinancecheckout customer pdf: Allow customers to download invoices and packing slips. - - 1.0.0 - Customweb GmbH - http://github.com/postfinancecheckout-payment/opencart - - - response->setOutput($this->load->view('account/order_info', $data)); - ]]> - load->model('extension/postfinancecheckout/order'); - $data['postfinancecheckout_buttons'] = $this->model_extension_postfinancecheckout_order->getButtons($order_info['order_id']); - ]]> - - - - - - ]]> - -
    - - - -
    - - ]]>
    -
    -
    -
    diff --git a/upload/system/library/postfinancecheckout/modification/WalleeQuickCheckoutCompatibility.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeQuickCheckoutCompatibility.ocmod.xml deleted file mode 100644 index caf9e15..0000000 --- a/upload/system/library/postfinancecheckout/modification/WalleeQuickCheckoutCompatibility.ocmod.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - PostFinanceCheckoutQuickCheckoutCompatibility - postfinancecheckout compatibility: patch for Ajax Quick Checkout. - - 1.0.0 - Customweb GmbH - http://github.com/postfinancecheckout-payment/opencart - - - - - - - diff --git a/upload/system/library/postfinancecheckout/service/line_item.php b/upload/system/library/postfinancecheckout/service/line_item.php index 94e672c..e36adc4 100644 --- a/upload/system/library/postfinancecheckout/service/line_item.php +++ b/upload/system/library/postfinancecheckout/service/line_item.php @@ -18,21 +18,12 @@ class LineItem extends AbstractService { private $coupon; private $voucher; private $total; + private $xfeepro; public static function instance(\Registry $registry){ return new self($registry); } - public function getTotalLineItem($total){ - $line_item = new \PostFinanceCheckout\Sdk\Model\LineItemCreate(); - $line_item->setAmountIncludingTax($total); - $line_item->setQuantity(1); - $line_item->setType(\PostFinanceCheckout\Sdk\Model\LineItemType::PRODUCT); - $line_item->setName('temp'); - $line_item->setUniqueId('temp'); - return $line_item; - } - /** * Gets the current order items, with all succesfull refunds applied. * @@ -46,7 +37,9 @@ public function getReducedItemsFromOrder(array $order_info, $transaction_id, $sp $this->tax->setShippingAddress($order_info['shipping_country_id'], $order_info['shipping_zone_id']); $this->tax->setPaymentAddress($order_info['payment_country_id'], $order_info['payment_zone_id']); + \PostFinanceCheckoutHelper::instance($this->registry)->xfeeproDisableIncVat(); $line_items = $this->getItemsFromOrder($order_info, $transaction_id, $space_id); + \PostFinanceCheckoutHelper::instance($this->registry)->xfeeproRestoreIncVat(); // get all succesfully reduced items $refund_jobs = \PostFinanceCheckout\Entity\RefundJob::loadByOrder($this->registry, $order_info['order_id']); @@ -127,7 +120,7 @@ public function getItemsFromOrder(array $order_info){ break; } } - + $this->coupon = $this->getCoupon($transaction_info->getCouponCode(), $sub_total, $order_info['customer_id']); return $this->createLineItems($order_info['currency_code']); @@ -136,10 +129,13 @@ public function getItemsFromOrder(array $order_info){ public function getItemsFromSession(){ $this->tax = $this->registry->get('tax'); - $i = 0; - $items = array(); - $fees = array(); - + $session = $this->registry->get('session'); + if (isset($session->data['shipping_country_id']) && isset($session->data['shipping_country_id'])) { + $this->tax->setShippingAddress($session->data['shipping_country_id'], $session->data['shipping_zone_id']); + } + if (isset($session->data['payment_country_id']) && isset($session->data['payment_zone_id'])) { + $this->tax->setPaymentAddress($session->data['payment_country_id'], $session->data['payment_zone_id']); + } $this->products = $this->registry->get('cart')->getProducts(); if (!empty($this->registry->get('session')->data['vouchers'])) { @@ -159,7 +155,9 @@ public function getItemsFromSession(){ $this->shipping = false; } + \PostFinanceCheckoutHelper::instance($this->registry)->xfeeproDisableIncVat(); $this->total = \PostFinanceCheckoutVersionHelper::getSessionTotals($this->registry); + \PostFinanceCheckoutHelper::instance($this->registry)->xfeeProRestoreIncVat(); $sub_total = 0; foreach ($this->total as $total) { @@ -295,7 +293,7 @@ private function createXFeeLineItem($total){ $line_item = new LineItemCreate(); $line_item->setName($total['title']); $line_item->setSku($total['code']); - $line_item->setUniqueId($total['code']); + $line_item->setUniqueId($this->createUniqueIdFromXfee($total)); $line_item->setQuantity(1); $line_item->setType(LineItemType::FEE); if ($total['value'] < 0) { @@ -304,14 +302,49 @@ private function createXFeeLineItem($total){ $line_item->setAmountIncludingTax( \PostFinanceCheckoutHelper::instance($this->registry)->formatAmount( \PostFinanceCheckoutHelper::instance($this->registry)->roundXfeeAmount($total['value']))); - $fee_id = substr($total['code'], 4); - if ($config->get('xfee_tax_class_id' . $fee_id)) { - $tax_amount = $this->addTaxesToLineItem($line_item, $total['value'], $config->get('xfee_tax_class_id' . $fee_id)); + $taxClass = $this->getXfeeTaxClass($total); + if ($taxClass) { + $tax_amount = $this->addTaxesToLineItem($line_item, $total['value'], $taxClass); $line_item->setAmountIncludingTax(\PostFinanceCheckoutHelper::instance($this->registry)->formatAmount($total['value'] + $tax_amount)); } return $this->cleanLineItem($line_item); } + private function createUniqueIdFromXfee($total){ + if (isset($total['xcode'])) { + return $total['xcode']; + } + else { + return substr($total['code'] . preg_replace("/\W/", "-", $total['title']), 0, 200); + } + } + + private function getXfeeTaxClass($total){ + $config = $this->registry->get('config'); + if ($total['code'] == 'xfee') { + for ($i = 0; $i < 12; $i++) { + // TODO value comparison percentages + if ($config->get('xfee_name' . $i) == $total['title'] /* && $config->get('xfee_value') == $total['value']*/) { + return $config->get('xfee_tax_class_id' . $i); + } + } + } + else if ($total['code'] == 'xfeepro') { + $i = substr($total['xcode'], strlen('xfeepro.xfeepro')); + $xfeepro = $this->getXfeePro(); + return $xfeepro['tax_class_id'][$i]; + } + return null; + } + + private function getXfeePro() { + if($this->xfeepro === null) { + $config = $this->registry->get('config'); + $this->xfeepro = $xfeepro = unserialize(base64_decode($config->get('xfeepro'))); + } + return $this->xfeepro; + } + private function createLineItemFromProduct($product){ $line_item = new LineItemCreate(); $amount_excluding_tax = $product['total']; @@ -362,7 +395,7 @@ private function createUniqueIdFromProduct($product){ $id .= '=' . $option['option_value_id']; } } - if(isset($option['value']) && !$hasValue) { + if (isset($option['value']) && !$hasValue) { $id .= '_v=' . $option['value']; } } diff --git a/upload/system/library/postfinancecheckout/service/transaction.php b/upload/system/library/postfinancecheckout/service/transaction.php index 2480d14..980db25 100644 --- a/upload/system/library/postfinancecheckout/service/transaction.php +++ b/upload/system/library/postfinancecheckout/service/transaction.php @@ -281,8 +281,10 @@ public function updateLineItemsFromOrder($order_id){ $order_info = \PostFinanceCheckoutHelper::instance($this->registry)->getOrder($order_id); $transaction_info = \PostFinanceCheckout\Entity\TransactionInfo::loadByOrderId($this->registry, $order_id); + \PostFinanceCheckoutHelper::instance($this->registry)->xfeeproDisableIncVat(); $line_items = \PostFinanceCheckout\Service\LineItem::instance($this->registry)->getItemsFromOrder($order_info, $transaction_info->getTransactionId(), $transaction_info->getSpaceId()); + \PostFinanceCheckoutHelper::instance($this->registry)->xfeeproRestoreIncVat(); $update_request = new \PostFinanceCheckout\Sdk\Model\TransactionLineItemUpdateRequest(); $update_request->setTransactionId($transaction_info->getTransactionId()); diff --git a/upload/system/library/postfinancecheckout/version_helper.php b/upload/system/library/postfinancecheckout/version_helper.php index 38bc532..9895ce0 100644 --- a/upload/system/library/postfinancecheckout/version_helper.php +++ b/upload/system/library/postfinancecheckout/version_helper.php @@ -28,10 +28,6 @@ public static function getModifications(){ 'file' => 'PostFinanceCheckoutQuickCheckoutCompatibility.ocmod.xml', 'default_status' => 0 ), - 'PostFinanceCheckoutJournalCompatibility' => array( - 'file' => 'PostFinanceCheckoutJournalCompatibility.ocmod.xml', - 'default_status' => 0 - ), 'PostFinanceCheckoutXFeeProCompatibility' => array( 'file' => 'PostFinanceCheckoutXFeeProCompatibility.ocmod.xml', 'default_status' => 0