Skip to content

Commit

Permalink
Release 1.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
sbossert committed Mar 6, 2019
1 parent 063c144 commit 782b5b0
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 375 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.1/1.0.10/docs/en/documentation.html)
* [English](https://plugin-documentation.postfinance-checkout.ch/pfpayments/opencart-2.1/1.0.11/docs/en/documentation.html)

## License

Please see the [license file](https://github.com/pfpayments/opencart-2.1/blob/1.0.10/LICENSE) for more information.
Please see the [license file](https://github.com/pfpayments/opencart-2.1/blob/1.0.11/LICENSE) for more information.
4 changes: 2 additions & 2 deletions docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.10/">
<a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.11/">
Source
</a>
</li>
Expand All @@ -48,7 +48,7 @@ <h1>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.10/">Download</a> the extension.</p>
<p><a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.11/">Download</a> the extension.</p>
</li>
<li>
<p>Extract the files and upload the content of the <code>Upload</code> directory into the root directory of your store using FTP/SSH.</p>
Expand Down
32 changes: 23 additions & 9 deletions upload/catalog/controller/extension/postfinancecheckout/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function includeDeviceIdentifier(){
$script .= '/s/[spaceId]/payment/device.js?sessionIdentifier=[UniqueSessionIdentifier]';

$this->setDeviceCookie();

$script = str_replace(array(
'[spaceId]',
'[UniqueSessionIdentifier]'
Expand Down Expand Up @@ -81,15 +81,29 @@ public function canSaveOrder($order_info){
}

if (!empty($new_order)) {
\PostFinanceCheckoutHelper::instance($this->registry)->log($this->language->get('error_order_edit') . " ($order_id)", \PostFinanceCheckoutHelper::LOG_ERROR);
\PostFinanceCheckoutHelper::instance($this->registry)->log($this->language->get('error_order_edit') . " ($order_id)",
\PostFinanceCheckoutHelper::LOG_ERROR);

$this->language->load('payment/postfinancecheckout');
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode(array(
'error' => $this->language->get('error_order_edit')
)));
$this->response->output();
die();
if ($this->request->get['route'] == 'checkout/checkout') {
// ensure reload without order_id
unset($this->session->data['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, $order_id);
$this->session->data['error'] = $transaction_info->getFailureReason();
$this->response->redirect($this->createUrl('checkout/checkout', $this->request->get));
}
else {
$this->language->load('payment/postfinancecheckout');
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode(array(
'error' => $this->language->get('error_order_edit')
)));
$this->response->output();
die();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
require_once modification(DIR_SYSTEM . 'library/postfinancecheckout/helper.php');
use PostFinanceCheckout\Controller\AbstractController;

class ControllerExtensionPostFinanceCheckoutTransaction extends AbstractController {

public function fail(){
if (isset($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->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 '';
}
}
6 changes: 5 additions & 1 deletion upload/catalog/view/javascript/postfinancecheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
</div>
<div style="padding: 15px;">
<div id="postfinancecheckout-iframe-spinner" class="text-center">
<i style="font-size: 12em;"
class='fa fa-spinner fa-spin '></i>
</div>
<div id="postfinancecheckout-iframe-container" class="text-center" style="display:none;">
<i style="font-size: 12em;" class='fa fa-spinner fa-spin '></i>
</div>
<div id="postfinancecheckout-iframe-container" class="text-center"
style="display: none;"></div>

<div class="buttons" style="overflow:hidden;">
<div class="buttons" style="overflow: hidden;">
<div class="pull-right">
<input type="button" value="<?php echo $button_confirm; ?>"
id="button-confirm" class="btn btn-primary"
Expand All @@ -24,11 +23,14 @@
<script type="text/javascript">
function initPostFinanceCheckoutIframe(){
if(typeof PostFinanceCheckout === 'undefined') {
setTimeout(initPostFinanceCheckoutIframe, 500);
Window.loadPostFinanceCheckoutTimeout = setTimeout(initPostFinanceCheckoutIframe, 500);
} else {
PostFinanceCheckout.init('<?php echo $configuration_id; ?>');
}
}
if(typeof Window.loadPostFinanceCheckoutTimeout !== 'undefined') {
clearTimeout(Window.loadPostFinanceCheckoutTimeout);
}
jQuery().ready(initPostFinanceCheckoutIframe);
</script>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
));
Expand All @@ -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 '';
Expand Down
45 changes: 37 additions & 8 deletions upload/system/library/postfinancecheckout/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PostFinanceCheckoutHelper {
* @var Registry
*/
private $registry;
private $xfeepro;
private static $instance;
private $catalog_url;
const LOG_INFO = 2;
Expand Down Expand Up @@ -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.
Expand All @@ -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
*
Expand All @@ -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);
Expand Down Expand Up @@ -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('&amp;', '&',
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(){
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<code>PostFinanceCheckoutAdministration</code>
<name>postfinancecheckout administration: complete, refund and void from the OpenCart backend.
</name>
<version>1.0.2</version>
<version>1.1.0</version>
<author>Customweb GmbH</author>
<link>http://github.com/postfinancecheckout-payment/opencart</link>
<file path="admin/controller/sale/order.php">
Expand All @@ -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');
]]></add>
</operation>
</file>
<!-- order_info.tpl ajax api callback autoremoves all alerts, so must add
with delay. -->
<file path="admin/view/template/sale/order_info.tpl">
<operation>
<search><![CDATA[
<li><a href="#tab-history" data-toggle="tab"><?php echo $tab_history; ?></a></li>
]]></search>
<add position="before"><![CDATA[
<?php if($postfinancecheckout_tab): ?>
<li><a href="#tab-postfinancecheckout" data-toggle="tab"><?php echo $postfinancecheckout_tab['title']; ?></a></li>
<?php endif; ?>
]]></add>
</operation>
<operation>
<search><![CDATA[
<div class="tab-pane" id="tab-history">
]]></search>
<add position="before"><![CDATA[
<?php if($postfinancecheckout_tab) : ?>
<div class="tab-pane" id="tab-postfinancecheckout">
<?php echo $postfinancecheckout_tab['content']; ?>
</div>
<?php endif; ?>
]]></add>
</operation>
<operation>
<search><![CDATA[
<div id="content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,9 @@
<code>PostFinanceCheckoutCore</code>
<name>postfinancecheckout core: load payment methods.
</name>
<version>1.0.2</version>
<version>1.1.2</version>
<author>Customweb GmbH</author>
<link>http://github.com/postfinancecheckout-payment/opencart</link>
<file path="catalog/controller/checkout/checkout.php">
<operation>
<search><![CDATA[
if (isset($this->session->data['error'])) {
]]></search>
<add position="before"><![CDATA[
require_once modification(DIR_SYSTEM . 'library/postfinancecheckout/helper.php');
if (isset($this->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
]]></add>
</operation>
</file>
<file path="admin/controller/extension/payment.php">
<operation>
<search><![CDATA[
Expand Down Expand Up @@ -81,16 +65,6 @@
]]></add>
</operation>
</file>
<file path="admin/controller/sale/order.php">
<operation>
<search><![CDATA[
if (is_file(DIR_CATALOG . 'controller/payment/' . $order_info['payment_code'] . '.php')) {
]]></search>
<add position="replace"><![CDATA[
if (is_file(DIR_CATALOG . 'controller/payment/' . $order_info['payment_code'] . '.php') || strpos($order_info['payment_code'], 'postfinancecheckout_') === 0) {
]]></add>
</operation>
</file>

<file path="system/engine/action.php">
<operation>
Expand Down
Loading

0 comments on commit 782b5b0

Please sign in to comment.