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 694a018..15fca2a 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('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 34cc989..d466cb2 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..399a133 100644
--- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAdministration.ocmod.xml
+++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutAdministration.ocmod.xml
@@ -3,7 +3,7 @@
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
@@ -15,35 +15,12 @@
$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/PostFinanceCheckoutCore.ocmod.xml b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutCore.ocmod.xml
index 4d4d7c4..c11aa53 100644
--- a/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutCore.ocmod.xml
+++ b/upload/system/library/postfinancecheckout/modification/PostFinanceCheckoutCore.ocmod.xml
@@ -3,25 +3,9 @@
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
- ]]>
-
-
-
-
-
-
-
-
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/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/WalleeAdministration.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeAdministration.ocmod.xml
deleted file mode 100644
index d626e83..0000000
--- a/upload/system/library/postfinancecheckout/modification/WalleeAdministration.ocmod.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
- PostFinanceCheckoutAdministration
- postfinancecheckout administration: complete, refund and void from the OpenCart backend.
-
- 1.0.0
- Customweb GmbH
- http://github.com/postfinancecheckout-payment/opencart
-
-
- response->setOutput($this->load->view('sale/order_info.tpl', $data));
- ]]>
- 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/WalleeCore.ocmod.xml b/upload/system/library/postfinancecheckout/modification/WalleeCore.ocmod.xml
deleted file mode 100644
index c206816..0000000
--- a/upload/system/library/postfinancecheckout/modification/WalleeCore.ocmod.xml
+++ /dev/null
@@ -1,144 +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);
- }
- ]]>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- file)
- ]]>
- file))
- ]]>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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/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 8ba154e..321cfdc 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