Skip to content

Commit

Permalink
Merge pull request #154 from margud/3.5.4
Browse files Browse the repository at this point in the history
3.5.4
  • Loading branch information
margud authored Feb 14, 2020
2 parents 30cc612 + aaba560 commit c48008c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
30 changes: 21 additions & 9 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ class Mollie extends PaymentModule
'displayPaymentEU',
'paymentOptions',
'displayAdminOrder',
'displayHeader',
'displayBackOfficeHeader',
'displayOrderConfirmation',
'hookActionFrontControllerSetMedia'
);

public $extra_mail_vars = array();
Expand Down Expand Up @@ -268,7 +268,7 @@ public function __construct()
{
$this->name = 'mollie';
$this->tab = 'payments_gateways';
$this->version = '3.5.3';
$this->version = '3.5.4';
$this->author = 'Mollie B.V.';
$this->need_instance = 1;
$this->bootstrap = true;
Expand Down Expand Up @@ -2256,12 +2256,14 @@ protected function addCSSFile($file = null)
/**
* @throws PrestaShopException
*/
public function hookDisplayHeader()
public function hookActionFrontControllerSetMedia()
{
if ($this->context->controller instanceof OrderControllerCore) {

Media::addJsDef([
'profileId' => Configuration::get(Mollie::MOLLIE_PROFILE_ID),
'isoCode' => $this->context->language->language_code,
'isTestMode' => self::isTestMode()
]);
if ($this->isVersion17()) {
$this->context->controller->registerJavascript(
Expand Down Expand Up @@ -4624,8 +4626,8 @@ public function validateMollieOrder(
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$context_country = $this->context->country;
}
$orderStatus = new OrderState((int) $idOrderState, (int) $this->context->language->id);
if (!Validate::isLoadedObject($orderStatus)) {
$orderState = new OrderState((int) $idOrderState, (int) $this->context->language->id);
if (!Validate::isLoadedObject($orderState)) {
PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Order Status cannot be loaded', 3, null, 'Cart', (int) $idCart, true);
throw new PrestaShopException('Can\'t load Order status');
}
Expand Down Expand Up @@ -4775,7 +4777,7 @@ public function validateMollieOrder(
// We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php
// if ($order->total_paid != $order->total_paid_real)
// We use number_format in order to compare two string
if ($orderStatus->logable && number_format($cartTotalPaid, self::PS_PRICE_COMPUTE_PRECISION) != number_format($amountPaid, self::PS_PRICE_COMPUTE_PRECISION)) {
if ($orderState->logable && number_format($cartTotalPaid, self::PS_PRICE_COMPUTE_PRECISION) != number_format($amountPaid, self::PS_PRICE_COMPUTE_PRECISION)) {
$idOrderState = Configuration::get('PS_OS_ERROR');
}
$orderList[] = $order;
Expand Down Expand Up @@ -4813,7 +4815,7 @@ public function validateMollieOrder(
PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Payment is about to be added', 1, null, 'Cart', (int) $idCart, true);
}
// Register Payment only if the order status validate the order
if ($orderStatus->logable) {
if ($orderState->logable) {
// $order is the last order loop in the foreach
// The method addOrderPayment of the class Order make a create a paymentOrder
// linked to the order reference and not to the order id
Expand Down Expand Up @@ -5141,7 +5143,7 @@ public function validateMollieOrder(
'order' => $order,
'customer' => $this->context->customer,
'currency' => $this->context->currency,
'orderStatus' => $orderStatus,
'orderStatus' => $orderState,
));
foreach ($this->context->cart->getProducts() as $product) {
if ($orderStatus->logable) {
Expand Down Expand Up @@ -5237,7 +5239,7 @@ public function validateMollieOrder(
$data = array_merge($data, $extraVars);
}
// Join PDF invoice
if ((int) Configuration::get('PS_INVOICE') && $orderStatus->invoice && $order->invoice_number) {
if ((int) Configuration::get('PS_INVOICE') && $orderState->invoice && $order->invoice_number) {
$orderInvoiceList = $order->getInvoicesCollection();
Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $orderInvoiceList));
$pdf = new PDF($orderInvoiceList, PDF::TEMPLATE_INVOICE, $this->context->smarty);
Expand Down Expand Up @@ -6501,4 +6503,14 @@ public function isVersion17()
{
return (bool) version_compare(_PS_VERSION_, '1.7', '>=');
}

public static function isTestMode()
{
$apiKey = Configuration::get(self::MOLLIE_API_KEY);
if (strpos($apiKey, 'test') === 0) {
return true;
}

return false;
}
}
48 changes: 48 additions & 0 deletions upgrade/Upgrade-3.5.4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright (c) 2012-2019, Mollie B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* @author Mollie B.V. <[email protected]>
* @copyright Mollie B.V.
* @license Berkeley Software Distribution License (BSD-License 2) http://www.opensource.org/licenses/bsd-license.php
* @category Mollie
* @package Mollie
* @link https://www.mollie.nl
*/

if (!defined('_PS_VERSION_')) {
exit;
}

/**
* @param Mollie $module
* @return bool
*/
function upgrade_module_3_5_4(Mollie $module)
{
$module->registerHook('actionFrontControllerSetMedia');

return true;
}
2 changes: 1 addition & 1 deletion views/js/front/mollie_iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $(document).ready(function () {
}
}
};
var mollie = Mollie(profileId, {locale: isoCode, testMode: true});
var mollie = Mollie(profileId, {locale: isoCode, testMode: isTestMode});
var cardHolder = mollie.createComponent('cardHolder', options);
var cardNumber = mollie.createComponent('cardNumber', options);
var expiryDate = mollie.createComponent('expiryDate', options);
Expand Down
2 changes: 1 addition & 1 deletion views/js/front/mollie_iframe_16.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $(document).ready(function () {
}
}
};
var mollie = Mollie(profileId, {locale: isoCode, testMode: true});
var mollie = Mollie(profileId, {locale: isoCode, testMode: isTestMode});
var cardHolder = mollie.createComponent('cardHolder', options);
var cardNumber = mollie.createComponent('cardNumber', options);
var expiryDate = mollie.createComponent('expiryDate', options);
Expand Down

0 comments on commit c48008c

Please sign in to comment.