Skip to content

Commit

Permalink
Release 1.0.29
Browse files Browse the repository at this point in the history
  • Loading branch information
sbossert committed Nov 6, 2019
1 parent 53fb937 commit 42d6832
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 47 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.28/docs/en/documentation.html)
* [English](https://plugin-documentation.postfinance-checkout.ch/pfpayments/opencart-2.1/1.0.29/docs/en/documentation.html)

## License

Please see the [license file](https://github.com/pfpayments/opencart-2.1/blob/1.0.28/LICENSE) for more information.
Please see the [license file](https://github.com/pfpayments/opencart-2.1/blob/1.0.29/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.28/">
<a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.29/">
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.28/">Download</a> the extension.</p>
<p><a href="https://github.com/pfpayments/opencart-2.1/releases/tag/1.0.29/">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
92 changes: 55 additions & 37 deletions upload/system/library/postfinancecheckout/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function __construct(Registry $registry){
$this->loggers = array(
self::LOG_ERROR => $registry->get('log'),
self::LOG_DEBUG => new Log('postfinancecheckout_debug.log'),
self::LOG_INFO => new Log('postfinancecheckout_info.log')
self::LOG_INFO => new Log('postfinancecheckout_info.log')
);
}
else {
Expand Down Expand Up @@ -108,14 +108,15 @@ public function compareStoredCustomerSessionIdentifier(){
else {
return false;
}

$parts = explode('_', $id);
$customer = $this->getCustomer();
switch ($parts[0]) {
case 'customer':
return isset($customer['customer_id']) && 'customer_' . $customer['customer_id'] == $id;
case 'user':
return (isset($customer['user_id']) && 'user_' . $customer['user_id'] == $id) || (isset($data['user_id']) && 'user_' . $data['user_id'] == $id);
return (isset($customer['user_id']) && 'user_' . $customer['user_id'] == $id) ||
(isset($data['user_id']) && 'user_' . $data['user_id'] == $id);
case 'guest':
return $this->buildGuestSessionIdentifier($customer) == $id;
case 'cart':
Expand All @@ -140,17 +141,17 @@ public function getAddress($key, $order_info = array()){
$session = $this->registry->get('session')->data;
$address_model = $this->registry->get('model_account_address');
$address = array();

if (isset($order_info[$key . '_address'])) {
$address = \PostFinanceCheckoutHelper::mergeArray($address, $order_info[$key . '_address']);
}
if (isset($order_info[$key . '_address_id'])) {
$address = \PostFinanceCheckoutHelper::mergeArray($address, $address_model->getAddress($$order_info[$key . '_address_id']));
}
if(empty($address) && $key != 'payment') {
if (empty($address) && $key != 'payment') {
$address = $this->getAddress('payment', $order_info);
}
if(empty($address)) {
if (empty($address)) {
if ($customer && $customer->isLogged() && isset($session[$key . '_address_id'])) {
$address = $address_model->getAddress($session[$key . '_address_id']);
}
Expand All @@ -170,7 +171,7 @@ public function getAddress($key, $order_info = array()){
public function refreshWebhook(){
$db = $this->registry->get('db');
$config = DB_PREFIX . 'setting';

$generated = $this->getWebhookUrl();
$saved = $this->registry->get('config')->get('postfinancecheckout_notification_url');
if ($generated == $saved) {
Expand All @@ -179,7 +180,7 @@ public function refreshWebhook(){
$space_id = $this->registry->get('config')->get('postfinancecheckout_space_id');
\PostFinanceCheckout\Service\Webhook::instance($this->registry)->uninstall($space_id, $saved);
\PostFinanceCheckout\Service\Webhook::instance($this->registry)->install($space_id, $generated);

$store_id = $this->registry->get('config')->get('config_store_id');
if ($store_id === null) {
$store_id = 0;
Expand Down Expand Up @@ -217,22 +218,22 @@ public function areAmountsEqual($amount1, $amount2, $currency_code){

public function hasRunningJobs(\PostFinanceCheckout\Entity\TransactionInfo $transaction_info){
return \PostFinanceCheckout\Entity\CompletionJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) +
\PostFinanceCheckout\Entity\VoidJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) +
\PostFinanceCheckout\Entity\RefundJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) > 0;
\PostFinanceCheckout\Entity\VoidJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) +
\PostFinanceCheckout\Entity\RefundJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) > 0;
}

public function isCompletionPossible(\PostFinanceCheckout\Entity\TransactionInfo $transaction_info){
return $transaction_info->getState() == \PostFinanceCheckout\Sdk\Model\TransactionState::AUTHORIZED &&
(\PostFinanceCheckout\Entity\CompletionJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) == 0) &&
(\PostFinanceCheckout\Entity\VoidJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) == 0);
(\PostFinanceCheckout\Entity\CompletionJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) == 0) &&
(\PostFinanceCheckout\Entity\VoidJob::countRunningForOrder($this->registry, $transaction_info->getOrderId()) == 0);
}

public function isRefundPossible(\PostFinanceCheckout\Entity\TransactionInfo $transaction_info){
if (!in_array($transaction_info->getState(),
array(
\PostFinanceCheckout\Sdk\Model\TransactionState::COMPLETED,
\PostFinanceCheckout\Sdk\Model\TransactionState::FULFILL,
\PostFinanceCheckout\Sdk\Model\TransactionState::DECLINE
\PostFinanceCheckout\Sdk\Model\TransactionState::DECLINE
))) {
return false;
}
Expand Down Expand Up @@ -372,14 +373,14 @@ public function dbTransactionRollback(){
*/
public function dbTransactionLock($space_id, $transaction_id){
$db = $this->registry->get('db');

$table = DB_PREFIX . 'postfinancecheckout_transaction_info';
$locked_at = date('Y-m-d H:i:s');
$space_id = $db->escape($space_id);
$transaction_id = $db->escape($transaction_id);

$db->query("SELECT locked_at FROM $table WHERE transaction_id = '$transaction_id' AND space_id = '$space_id' FOR UPDATE");

$db->query("UPDATE $table SET locked_at = '$locked_at' WHERE transaction_id = '$transaction_id' AND space_id = '$space_id'");
}

Expand All @@ -388,7 +389,7 @@ public function translate($strings, $language = null){
if (isset($strings[$language])) {
return $strings[$language];
}

if ($language) {
try {
$language_provider = \PostFinanceCheckout\Provider\Language::instance($this->registry);
Expand Down Expand Up @@ -434,10 +435,10 @@ public function getCleanLanguageCode($language = null){
$language = $config->get('config_admin_language');
}
}

$prefixWithDash = substr($language, 0, 3);
$postfix = strtoupper(substr($language, 3));

return $prefixWithDash . $postfix;
}

Expand Down Expand Up @@ -468,7 +469,7 @@ public function getCache(){

public function getSuccessUrl(){
return PostFinanceCheckoutVersionHelper::createUrl($this->getCatalogUrl(), 'checkout/success', array(
'utm_nooverride' => 1
'utm_nooverride' => 1
), $this->registry->get('config')->get('config_secure'));
}

Expand All @@ -477,7 +478,7 @@ public function getFailedUrl($order_id){
PostFinanceCheckoutVersionHelper::createUrl($this->getCatalogUrl(), 'extension/postfinancecheckout/transaction/fail',
array(
'order_id' => $order_id,
'utm_nooverride' => 1
'utm_nooverride' => 1
), $this->registry->get('config')->get('config_secure')));
}

Expand All @@ -494,7 +495,8 @@ public function getWebhookUrl(){
public function isValidOrder($order_id){
if (!$this->isAdmin()) {
$order_info = $this->getOrder($order_id);
if ($this->registry->get('customer') && $this->registry->get('customer')->isLogged() && isset($this->registry->get('session')->data['customer_id'])) {
if ($this->registry->get('customer') && $this->registry->get('customer')->isLogged() &&
isset($this->registry->get('session')->data['customer_id'])) {
if ($this->registry->get('session')->data['customer_id'] != $order_info['customer_id']) {
return false;
}
Expand Down Expand Up @@ -539,6 +541,21 @@ public function addOrderHistory($order_id, $status, $message = '', $notify = fal
$this->registry->get('model_checkout_order')->addOrderHistory($order_id, $status, $message, $notify);
}

public function ensurePaymentCode(array $order_info, \PostFinanceCheckout\Sdk\Model\Transaction $transaction){
$code = 'postfinancecheckout_' . $transaction->getPaymentConnectorConfiguration()->getPaymentMethodConfiguration()->getId();
if ($order_info['payment_code'] == $code) {
return;
}
$db = $this->registry->get('db');
$table = DB_PREFIX . 'order';
$code = $db->escape($code);
$title = $db->escape($transaction->getPaymentConnectorConfiguration()->getPaymentMethodConfiguration()->getName());
$order_id = $db->escape($order_info['order_id']);
$query = "UPDATE `$table` SET `payment_code`='$code', `payment_method`='$title' WHERE `order_id`='$order_id';";
$this->log("Changing payment method on order: [" . $query . "], was [" . $order_info['payment_code'] . "]", self::LOG_DEBUG);
$db->query($query);
}

/**
*
* @return Url
Expand Down Expand Up @@ -580,10 +597,10 @@ private function getStoreUrl($ssl = true){
public function rewrite($url){
return str_replace(array(
HTTP_SERVER,
HTTPS_SERVER
HTTPS_SERVER
), array(
HTTP_CATALOG,
HTTPS_CATALOG
HTTPS_CATALOG
), $url);
}

Expand Down Expand Up @@ -614,30 +631,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.
* Disable inc vat setting in xfeepro.
* Necessary to ensure taxes are calculated and transmitted correctly.
*/
public function xfeeproDisableIncVat() {
public function xfeeproDisableIncVat(){
$config = $this->registry->get('config');
$xfeepro = $config->get('xfeepro');
if($xfeepro) {
if ($xfeepro) {
$xfeepro = unserialize(base64_decode($xfeepro));
$this->xfeepro = $xfeepro;
if(isset($xfeepro['inc_vat'])) {
foreach($xfeepro['inc_vat'] as $i => $value) {
if (isset($xfeepro['inc_vat'])) {
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) {
public function xfeeProRestoreIncVat(){
if ($this->xfeepro) {
$this->registry->get('config')->set('xfeepro', base64_encode(serialize($this->xfeepro)));
}
}
Expand All @@ -648,8 +666,8 @@ public static function instance(Registry $registry){
}
return self::$instance;
}
public static function extractPaymentMethodId($code) {

public static function extractPaymentMethodId($code){
return substr($code, strlen('postfinancecheckout_'));
}

Expand All @@ -669,7 +687,7 @@ public static function isEditableState($state){
$completable_states = array(
\PostFinanceCheckout\Sdk\Model\TransactionState::AUTHORIZED,
\PostFinanceCheckout\Sdk\Model\TransactionState::CONFIRMED,
\PostFinanceCheckout\Sdk\Model\TransactionState::PROCESSING
\PostFinanceCheckout\Sdk\Model\TransactionState::PROCESSING
);
return in_array($state, $completable_states);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function updateTransactionInfo(\PostFinanceCheckout\Sdk\Model\Transaction
$transaction->getPaymentConnectorConfiguration() != null ? $transaction->getPaymentConnectorConfiguration()->getConnector() : null);
$info->setPaymentMethodId(
$transaction->getPaymentConnectorConfiguration() != null && $transaction->getPaymentConnectorConfiguration()->getPaymentMethodConfiguration() !=
null ? $transaction->getPaymentConnectorConfiguration()->getPaymentMethodConfiguration()->getPaymentMethod() : null);
null ? $transaction->getPaymentConnectorConfiguration()->getPaymentMethodConfiguration()->getPaymentMethod() : null);
$info->setImage($this->getPaymentMethodImage($transaction));
$info->setLabels($this->getTransactionLabels($transaction));
if ($transaction->getState() == \PostFinanceCheckout\Sdk\Model\TransactionState::FAILED ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ protected function getTransactionId($transaction){
}

protected function processOrderRelatedInner(array $order_info, $transaction){
$oid = $order_info['order_id'];
$tid = $transaction->getId();
/* @var \PostFinanceCheckout\Sdk\Model\Transaction $transaction */
$transaction_info = \PostFinanceCheckout\Entity\TransactionInfo::loadByOrderId($this->registry, $order_info['order_id']);
\PostFinanceCheckoutHelper::instance($this->registry)->ensurePaymentCode($order_info, $transaction);
if ($transaction->getState() != $transaction_info->getState()) {
switch ($transaction->getState()) {
case \PostFinanceCheckout\Sdk\Model\TransactionState::CONFIRMED:
Expand Down Expand Up @@ -71,13 +70,11 @@ protected function processOrderRelatedInner(array $order_info, $transaction){
}

protected function processing(\PostFinanceCheckout\Sdk\Model\Transaction $transaction, array $order_info){
// TODO none..
\PostFinanceCheckoutHelper::instance($this->registry)->addOrderHistory($order_info['order_id'], 'postfinancecheckout_processing_status_id',
\PostFinanceCheckoutHelper::instance($this->registry)->getTranslation('message_webhook_processing'));
}

protected function confirm(\PostFinanceCheckout\Sdk\Model\Transaction $transaction, array $order_info){
// TODO none..
\PostFinanceCheckoutHelper::instance($this->registry)->addOrderHistory($order_info['order_id'], 'postfinancecheckout_processing_status_id',
\PostFinanceCheckoutHelper::instance($this->registry)->getTranslation('message_webhook_confirm'));
}
Expand All @@ -98,7 +95,6 @@ protected function decline(\PostFinanceCheckout\Sdk\Model\Transaction $transacti
}

protected function failed(\PostFinanceCheckout\Sdk\Model\Transaction $transaction, array $order_info){
// TODO none
\PostFinanceCheckoutHelper::instance($this->registry)->addOrderHistory($order_info['order_id'], 'postfinancecheckout_failed_status_id',
\PostFinanceCheckoutHelper::instance($this->registry)->getTranslation('message_webhook_failed'));
}
Expand Down

0 comments on commit 42d6832

Please sign in to comment.