Skip to content

Commit

Permalink
Release 1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
sbossert committed Feb 20, 2019
1 parent 3a6ce02 commit e6fd5ed
Show file tree
Hide file tree
Showing 157 changed files with 2,958 additions and 1,035 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.8/docs/en/documentation.html)
* [English](https://plugin-documentation.postfinance-checkout.ch/pfpayments/opencart-2.1/1.0.9/docs/en/documentation.html)

## License

Please see the [license file](https://github.com/pfpayments/opencart-2.1/blob/1.0.8/LICENSE) for more information.
Please see the [license file](https://github.com/pfpayments/opencart-2.1/blob/1.0.9/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.8/">
<a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.9/">
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.8/">Download</a> the extension.</p>
<p><a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.9/">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
33 changes: 19 additions & 14 deletions upload/admin/model/extension/postfinancecheckout/alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ public function getAlertsTitle(){

public function getAlerts(){
if ($this->alerts == null) {
$this->load->language('payment/postfinancecheckout');
$this->alerts = array();
$alert_entities = \PostFinanceCheckout\Entity\Alert::loadAll($this->registry);
try {
$this->load->language('payment/postfinancecheckout');
$this->alerts = array();
$alert_entities = \PostFinanceCheckout\Entity\Alert::loadAll($this->registry);

foreach ($alert_entities as $alert_entity) {
$this->alerts[] = array(
'url' => $this->createUrl($alert_entity->getRoute(),
array(
\PostFinanceCheckoutVersionHelper::TOKEN => $this->session->data[\PostFinanceCheckoutVersionHelper::TOKEN]
)),
'text' => $this->language->get($alert_entity->getKey()),
'level' => $alert_entity->getLevel(),
'count' => $alert_entity->getCount()
);
foreach ($alert_entities as $alert_entity) {
$this->alerts[] = array(
'url' => $this->createUrl($alert_entity->getRoute(),
array(
\PostFinanceCheckoutVersionHelper::TOKEN => $this->session->data[\PostFinanceCheckoutVersionHelper::TOKEN]
)),
'text' => $this->language->get($alert_entity->getKey()),
'level' => $alert_entity->getLevel(),
'count' => $alert_entity->getCount()
);
}
}
catch(\Exception $e) {
// We ignore errors here otherwise we might not be albe to display the admin backend UI.
}
}
return $this->alerts;
Expand All @@ -44,4 +49,4 @@ public function getAlertCount(){
}
return $count;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$_['error_default'] = 'This action is not permitted.';
$_['error_order_edit'] = 'The PostFinance Checkout transaction is in a state in which the line items may no longer be changed.';
$_['error_not_pending'] = 'Transaction exists and is not in state pending.';
$_['error_confirmation'] = 'The transaction could not be confirmed. Please check to see if any payment has been made from your account, and retry if no charge has taken place.';

// Order overview / download buttons
$_['button_invoice'] = 'Invoice';
Expand Down
11 changes: 9 additions & 2 deletions upload/catalog/view/javascript/postfinancecheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
$('#button-confirm').removeAttr('disabled');
$('#postfinancecheckout-iframe-spinner').toggle();
},

reenable: function() {
$('#button-confirm').removeAttr('disabled');
if($('html').hasClass('quick-checkout-page')) { // modifications do not work for js
triggerLoadingOff();
}
},

submit : function() {
if (!PostFinanceCheckout.running) {
Expand All @@ -39,7 +46,7 @@
}
else {
alert(data.message);
$('#button-confirm').removeAttr('disabled');
PostFinanceCheckout.reenable();
}
PostFinanceCheckout.running = false;
});
Expand All @@ -50,7 +57,7 @@
if (result.success) {
PostFinanceCheckout.submit();
} else {
$('#button-confirm').removeAttr('disabled');
PostFinanceCheckout.reenable();
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function confirm(){
}
catch (Exception $e) {
\PostFinanceCheckoutHelper::instance($this->registry)->dbTransactionRollback();
$result['message'] = $e->getMessage();
\PostFinanceCheckoutHelper::instance($this->registry)->log($e->getMessage(), \PostFinanceCheckoutHelper::LOG_ERROR);
$result['message'] = $this->language->get('error_confirmation');
unset($this->session->data['order_id']); // this order number cannot be used anymore
}

$this->response->addHeader('Content-Type: application/json');
Expand All @@ -58,6 +60,7 @@ private function confirmTransaction(){
\PostFinanceCheckoutHelper::instance($this->registry)->dbTransactionCommit();
return $transaction;
}

throw new Exception('Transaction is not pending.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public function getMethod($address, $total){
}

try {
if (isset($this->session->data['order_id'])) {
$transaction = \PostFinanceCheckout\Entity\TransactionInfo::loadByOrderId($this->registry, $this->session->data['order_id']);
if ($transaction->getTransactionId() &&
!in_array($transaction->getState(),
array(
\PostFinanceCheckout\Sdk\Model\TransactionState::PENDING,
\PostFinanceCheckout\Sdk\Model\TransactionState::CREATE
))) {
unset($this->session->data['order_id']);
}
}

$available_methods = \PostFinanceCheckout\Service\Transaction::instance($this->registry)->getPaymentMethods($order_info);
$configuration_id = substr($this->getCode(), strlen('postfinancecheckout_'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ protected function hasValue($variable_name){
return array_key_exists($variable_name, $this->data);
}

protected static function query($query, $db){
set_error_handler('PostFinanceCheckoutHelper::exceptionErrorHandler');
$result = $db->query($query);
restore_error_handler();
return $result;
}

public function __call($name, $arguments){
$variable_name = substr($name, 3);

Expand Down Expand Up @@ -172,12 +179,12 @@ public function save(){

if ($this->getId() === null) {
$query = "INSERT INTO $table SET $valuesQuery;";
$res = $db->query($query);
$res = self::query($query, $db);
$this->setId($db->getLastId());
}
else {
$query = "UPDATE $table SET $valuesQuery WHERE id = {$this->getId()};";
$res = $db->query($query);
$res = self::query($query, $db);
}
}

Expand All @@ -187,9 +194,7 @@ public function save(){
* @return static
*/
public static function loadById(\Registry $registry, $id){
$db = $registry->get('db');

$result = $db->query("SELECT * FROM " . DB_PREFIX . static::getTableName() . " WHERE id = '$id';");
$result = self::query("SELECT * FROM " . DB_PREFIX . static::getTableName() . " WHERE id = '$id';", $registry->get('db'));

if (isset($result->row) && !empty($result->row)) {
return new static($registry, $result->row);
Expand All @@ -205,9 +210,7 @@ public static function loadById(\Registry $registry, $id){
* @return \PostFinanceCheckout\Entity\AbstractEntity[]
*/
public static function loadAll(\Registry $registry){
$db = $registry->get('db');

$db_result = $db->query("SELECT * FROM " . DB_PREFIX . static::getTableName() . ";");
$db_result = self::query("SELECT * FROM " . DB_PREFIX . static::getTableName() . ";", $registry->get('db'));

$result = array();
foreach ($db_result->rows as $row) {
Expand All @@ -227,20 +230,20 @@ protected static function isDateField($field){
'updated_at'
));
}
private static function getDefaultFilter(array &$filters, $filterName, $default) {
if(isset($filters[$filterName])) {

private static function getDefaultFilter(array &$filters, $filterName, $default){
if (isset($filters[$filterName])) {
$value = $filters[$filterName];
unset($filters[$filterName]);
return $value;
}
return $default;
}
private static function buildWhereClause($db, array $filters) {

private static function buildWhereClause($db, array $filters){
$query = '';
foreach ($filters as $field => $value) {
if($value){
if ($value) {
$field = $db->escape($field);
$value = "'" . $db->escape($value) . "'";
if (self::isDateField($field)) {
Expand All @@ -251,7 +254,7 @@ private static function buildWhereClause($db, array $filters) {
}
}
}
if($query) {
if ($query) {
$query = "WHERE " . rtrim($query, " AND");
}
return $query;
Expand All @@ -260,8 +263,8 @@ private static function buildWhereClause($db, array $filters) {
/**
* Load entities which match the filters.
* Filters are applied as sql =.
* Special Filters:
* order: ASC or DESC.
* Special Filters:
* order: ASC or DESC.
* sort: ORDERBY.
* isDateField($field)=true: Compares dates
* start: Limit start
Expand All @@ -277,7 +280,7 @@ public static function loadByFilters(\Registry $registry, array $filters){
$orderBy = static::getDefaultFilter($filters, 'sort', 'id');
$ordering = static::getDefaultFilter($filters, 'order', 'ASC');
$page = 1;
if(isset($filters['page'])) {
if (isset($filters['page'])) {
$page = $filters['page'];
unset($filters['page']);
}
Expand All @@ -286,32 +289,29 @@ public static function loadByFilters(\Registry $registry, array $filters){

$query = "SELECT * FROM $table " . static::buildWhereClause($db, $filters) . " ORDER BY $orderBy $ordering LIMIT $start, $end;";

$db_result = $db->query($query);
$db_result = self::query($query, $db);
$result = array();
foreach ($db_result->rows as $row) {
$result[] = new static($registry, $row);
}
return $result;
}

/**
* Returns the count of all entites.
*
*
* @param \Registry $registry
* @return int
*/
public static function countRows(\Registry $registry) {
public static function countRows(\Registry $registry){
$db = $registry->get('db');
$table = DB_PREFIX . static::getTableName();
$query = "SELECT COUNT(id) as count FROM $table;";
$dbResult = $db->query($query);
$dbResult = self::query($query, $db);
return $dbResult->row['count'];
}

public function delete(\Registry $registry){
$db = $registry->get('db');

$query = "DELETE FROM " . DB_PREFIX . static::getTableName() . " WHERE id = {$this->getId};";
$db->query($query);
self::query("DELETE FROM " . DB_PREFIX . static::getTableName() . " WHERE id = {$this->getId()};", $registry->get('db'));
}
}
20 changes: 10 additions & 10 deletions upload/system/library/postfinancecheckout/entity/abstract_job.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function loadByOrder(\Registry $registry, $order_id){

$query = "SELECT * FROM $table WHERE order_id='$order_id';";

$db_result = $db->query($query);
$db_result = self::query($query, $db);

$result = array();
if ($db_result->num_rows) {
Expand All @@ -83,7 +83,7 @@ public static function loadByJob(\Registry $registry, $space_id, $job_id){

$query = "SELECT * FROM $table WHERE job_id='$job_id' AND space_id='$space_id';";

$db_result = $db->query($query);
$db_result = self::query($query, $db);

if (isset($db_result->row) && !empty($db_result->row)) {
return new static($registry, $db_result->row);
Expand Down Expand Up @@ -128,7 +128,7 @@ public static function loadNotSent(\Registry $registry, $period = 'PT10M'){
$timestamp = $time->format('Y-m-dd h:i:s');

$query = "SELECT * FROM $table WHERE STATE='$created' AND updated_at<'$timestamp';";
$db_result = $registry->get('db')->query($query);
$db_result = self::query($query, $registry->get('db'));
$result = array();
if ($db_result->num_rows) {
foreach ($result->rows as $row) {
Expand Down Expand Up @@ -164,7 +164,7 @@ public static function hasNotSent(\Registry $registry, $period = 'PT10M'){
") as pending_job";
//@formatter:on

$result = $registry->get('db')->query($query);
$db_result = self::query($query, $registry->get('db'));

if ($result->row) {
return true;
Expand All @@ -181,7 +181,7 @@ public static function loadNotSentForOrder(\Registry $registry, $order_id){

$query = "SELECT * FROM $table WHERE order_id='$order_id' AND state='$created';";

$result = $db->query($query);
$result = self::query($query, $db);

if (isset($result->row) && !empty($result->row)) {
return new static($registry, $result->row);
Expand All @@ -201,7 +201,7 @@ public static function loadRunningForOrder(\Registry $registry, $order_id){

$query = "SELECT * FROM $table WHERE order_id='$order_id' AND state NOT IN ('$created', '$success', '$failed_1', '$failed_2');";

$result = $db->query($query);
$result = self::query($query, $db);

if (isset($result->row) && !empty($result->row)) {
return new static($registry, $result->row);
Expand All @@ -217,7 +217,7 @@ public static function loadOldestCheckable(\Registry $registry){

$query = "SELECT * FROM $table WHERE state='$state' ORDER BY updated_at ASC LIMIT 1;";

$db_result = $db->query($query);
$result = self::query($query, $db);

if (isset($db_result->row) && !empty($db_result->row)) {
return new static($registry, $db_result->row);
Expand All @@ -233,7 +233,7 @@ public static function countForOrder(\Registry $registry, $order_id){

$query = "SELECT COUNT(id) FROM $table WHERE order_id='$order_id';";

$db_result = $db->query($query);
$db_result = self::query($query, $db);

return $db_result->row['COUNT(id)'];
}
Expand All @@ -247,7 +247,7 @@ public static function loadFailedCheckedForOrder(\Registry $registry, $order_id)

$query = "SELECT * FROM $table WHERE order_id='$order_id' AND state='$state';";

$db_result = $db->query($query);
$db_result = self::query($query, $db);

$result = array();
if ($db_result->num_rows) {
Expand All @@ -272,7 +272,7 @@ public static function markFailedAsDone(\Registry $registry, $order_id){

$query = "SELECT * FROM $table WHERE order_id='$order_id' AND state='$state';";

$db_result = $db->query($query);
$db_result = self::query($query, $db);

if ($db_result->num_rows) {
foreach ($db_result->rows as $row) {
Expand Down
Loading

0 comments on commit e6fd5ed

Please sign in to comment.