From 1f4fc4163f8eae6606fa2a430ed876bbd3cef766 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 8 Jan 2020 14:14:13 +0200 Subject: [PATCH 01/17] shipment information fixed where it would disappear --- controllers/front/ajax.php | 1 + controllers/front/return.php | 6 ++++-- views/js/front/mollie_iframe.js | 1 + views/templates/admin/_configure/helpers/form/form.tpl | 10 +++++----- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 52159046a..d05ed7658 100644 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -42,6 +42,7 @@ public function postProcess() foreach ($errorMessages as $errorMessage) { if (strpos($errorMessage, 'mollieMessage=') === 0) { $errorMessage = str_replace('mollieMessage=', '', $errorMessage); + $errorMessage = str_replace('_', ' ', $errorMessage); $this->context->smarty->assign(array( 'errorMessage' => $errorMessage diff --git a/controllers/front/return.php b/controllers/front/return.php index 86560529a..9890bed67 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -324,8 +324,10 @@ protected function processGetStatus() case \Mollie\Api\Types\PaymentStatus::STATUS_CANCELED: $status = static::DONE; $href = $this->context->link->getPagelink('order', true, null, array('step' => 3)); - $href .= isset($apiPayment->details->failureMessage) ? - "#mollieMessage={$apiPayment->details->failureMessage}" : ''; + if (isset($apiPayment->details->failureMessage)) { + $tagMessage = str_replace(' ', '_', $apiPayment->details->failureMessage); + $href .= "#mollieMessage={$tagMessage}"; + } die(json_encode(array( 'success' => true, 'status' => $status, diff --git a/views/js/front/mollie_iframe.js b/views/js/front/mollie_iframe.js index e991925b2..a2033a443 100644 --- a/views/js/front/mollie_iframe.js +++ b/views/js/front/mollie_iframe.js @@ -105,6 +105,7 @@ $(document).ready(function () { $mollieAlert.text(token.error.message); return; } + $mollieCardToken.val(token.token); isResubmit = true; $form.submit(); diff --git a/views/templates/admin/_configure/helpers/form/form.tpl b/views/templates/admin/_configure/helpers/form/form.tpl index cb5c913d8..50eb959e2 100644 --- a/views/templates/admin/_configure/helpers/form/form.tpl +++ b/views/templates/admin/_configure/helpers/form/form.tpl @@ -167,11 +167,11 @@ window.MollieModule.unmountComponentAtNode(container); window.MollieModule.debug = {if Configuration::get(Mollie::MOLLIE_DISPLAY_ERRORS)}true{else}false{/if}; } - {if version_compare($smarty.const._PS_VERSION_, '1.6.0.0', '<')} - container.closest('.form-group').style.display = 'none'; - {else} - container.closest('.form-group').style.display = 'none'; - {/if} +{* {if version_compare($smarty.const._PS_VERSION_, '1.6.0.0', '<')}*} +{* container.closest('.form-group').style.display = 'none';*} +{* {else}*} +{* container.closest('.form-group').style.display = 'none';*} +{* {/if}*} } } From 29fcc8695e6db4726b58c90a8935f76cfba9daa0 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 8 Jan 2020 15:37:07 +0200 Subject: [PATCH 02/17] improved mollie shipment when order status is set on creation --- controllers/front/webhook.php | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/front/webhook.php b/controllers/front/webhook.php index 73deec3ca..dd6489281 100644 --- a/controllers/front/webhook.php +++ b/controllers/front/webhook.php @@ -279,6 +279,7 @@ public function processTransaction($transaction) if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ALL) { Logger::addLog(__METHOD__.' said: Received webhook request for order '.(int) $orderId.' / transaction '.$transaction->id, Mollie::NOTICE); } + Hook::exec('actionOrderStatusUpdate', array('newOrderStatus' => (int) $this->module->statuses[$apiPayment->status], 'id_order' => (int) $orderId)); return $apiPayment; } From 0c4b0154b1c22f9e571a725f136bd1f007e5cf79 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 8 Jan 2020 17:21:40 +0200 Subject: [PATCH 03/17] fixed shipment on specific status settings --- mollie.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mollie.php b/mollie.php index 417e8f8fa..01dadabd7 100644 --- a/mollie.php +++ b/mollie.php @@ -883,12 +883,7 @@ protected function getSettingTabs($isApiKeyProvided) protected function getAccountSettingsSection($isApiKeyProvided) { $generalSettings = 'general_settings'; - $orderStatuses = array( - array( - 'name' => $this->l('Disable this status'), - 'id_order_state' => '0', - ), - ); + $orderStatuses = array(); $orderStatuses = array_merge($orderStatuses, OrderState::getOrderStates($this->context->language->id)); if ($isApiKeyProvided) { $input = array( @@ -6071,8 +6066,7 @@ public function hookActionOrderStatusUpdate($params = array()) } $shipmentInfo = static::getShipmentInformation($idOrder); - if (!(Configuration::get(static::MOLLIE_AUTO_SHIP_MAIN) && $orderStatus->shipped - || in_array($orderStatusNumber, $checkStatuses) + if (!(Configuration::get(static::MOLLIE_AUTO_SHIP_MAIN) && in_array($orderStatusNumber, $checkStatuses) ) || $shipmentInfo === null ) { return; From 5ab36a82e8cf6f86b68fd5aa4351b35fe40633bf Mon Sep 17 00:00:00 2001 From: marius Date: Thu, 9 Jan 2020 11:07:03 +0200 Subject: [PATCH 04/17] improved idle page display and order status when failed --- mollie.php | 1 + views/css/mollie.css | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/mollie.php b/mollie.php index 01dadabd7..75c34cdfa 100644 --- a/mollie.php +++ b/mollie.php @@ -319,6 +319,7 @@ public function __construct() \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED => Configuration::get(static::MOLLIE_STATUS_EXPIRED), \Mollie\Api\Types\RefundStatus::STATUS_REFUNDED => Configuration::get(static::MOLLIE_STATUS_REFUNDED), \Mollie\Api\Types\PaymentStatus::STATUS_OPEN => Configuration::get(static::MOLLIE_STATUS_OPEN), + \Mollie\Api\Types\PaymentStatus::STATUS_FAILED => Configuration::get(static::MOLLIE_STATUS_CANCELED), static::PARTIAL_REFUND_CODE => Configuration::get(static::MOLLIE_STATUS_PARTIAL_REFUND), 'created' => Configuration::get(static::MOLLIE_STATUS_OPEN), $this::STATUS_PAID_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK_PAID'), diff --git a/views/css/mollie.css b/views/css/mollie.css index a8f0340e5..f46b46719 100644 --- a/views/css/mollie.css +++ b/views/css/mollie.css @@ -78,4 +78,8 @@ .mollie-signature { padding-top: 20px; +} + +.mollie_button { + width: 100%; } \ No newline at end of file From c24a618c3711a7777a75ab2ba3d54928e1f0e439 Mon Sep 17 00:00:00 2001 From: marius Date: Thu, 9 Jan 2020 13:49:39 +0200 Subject: [PATCH 05/17] removed own page for ideal payment --- controllers/front/payment.php | 38 ----------------------------------- mollie.php | 7 +------ 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/controllers/front/payment.php b/controllers/front/payment.php index ad9e4d045..0c3088511 100644 --- a/controllers/front/payment.php +++ b/controllers/front/payment.php @@ -88,44 +88,6 @@ public function initContent() } $issuer = Tools::getValue('issuer') ?: null; - // If no issuer was set yet and the issuer list has its own page, show issuer list here - if (!$issuer - && Configuration::get(Mollie::MOLLIE_ISSUERS) === Mollie::ISSUERS_OWN_PAGE - && $method === \Mollie\Api\Types\PaymentMethod::IDEAL - ) { - $tplData = array(); - try { - $issuers = $this->module->getIssuerList(); - } catch (\Mollie\Api\Exceptions\ApiException $e) { - $this->setTemplate('error.tpl'); - $this->errors[] = Configuration::get(Mollie::MOLLIE_DISPLAY_ERRORS) - ? $e->getMessage() - : $this->module->l('An error occurred while initializing your payment. Please contact our customer support.', 'payment'); - return; - } catch (PrestaShopException $e) { - $this->setTemplate('error.tpl'); - $this->errors[] = Configuration::get(Mollie::MOLLIE_DISPLAY_ERRORS) - ? $e->getMessage() - : $this->module->l('An error occurred while initializing your payment. Please contact our customer support.', 'payment'); - return; - } - $tplData['issuers'] = isset($issuers[\Mollie\Api\Types\PaymentMethod::IDEAL]) ? $issuers[\Mollie\Api\Types\PaymentMethod::IDEAL] : array(); - if (!empty($tplData['issuers'])) { - $tplData['msg_bankselect'] = $this->module->lang['Select your bank:']; - $tplData['msg_ok'] = $this->module->lang['OK']; - $tplData['msg_return'] = $this->module->lang['Different payment method']; - $tplData['link'] = $this->context->link; - $tplData['cartAmount'] = (int) ($this->context->cart->getOrderTotal(true) * 100); - $tplData['qrAlign'] = 'center'; - $tplData['publicPath'] = __PS_BASE_URI__.'modules/'.basename(__FILE__, '.php').'/views/js/dist/'; - $this->context->controller->addJS(Mollie::getWebpackChunks('app')); - $this->context->smarty->assign($tplData); - $this->setTemplate('mollie_issuers.tpl'); - - return; - } - } - $originalAmount = $cart->getOrderTotal( true, Cart::BOTH diff --git a/mollie.php b/mollie.php index 75c34cdfa..f17a2cff7 100644 --- a/mollie.php +++ b/mollie.php @@ -151,7 +151,6 @@ class Mollie extends PaymentModule const LOGOS_HIDE = 'hide'; const ISSUERS_ON_CLICK = 'on-click'; - const ISSUERS_OWN_PAGE = 'own-page'; const ISSUERS_PAYMENT_PAGE = 'payment-page'; const METHODS_CONFIG = 'MOLLIE_METHODS_CONFIG'; @@ -269,7 +268,7 @@ public function __construct() { $this->name = 'mollie'; $this->tab = 'payments_gateways'; - $this->version = '3.5.1'; + $this->version = '3.5.3'; $this->author = 'Mollie B.V.'; $this->need_instance = 1; $this->bootstrap = true; @@ -1057,10 +1056,6 @@ protected function getAccountSettingsSection($isApiKeyProvided) 'id' => static::ISSUERS_ON_CLICK, 'name' => $this->l('On click'), ), - array( - 'id' => static::ISSUERS_OWN_PAGE, - 'name' => $this->l('Own page'), - ), array( 'id' => static::ISSUERS_PAYMENT_PAGE, 'name' => $this->l('Payment page'), From a79b4fa6bf8a62893f8e9410a76d27fb319c0f48 Mon Sep 17 00:00:00 2001 From: marius Date: Thu, 9 Jan 2020 14:11:33 +0200 Subject: [PATCH 06/17] hide profile id if its disabled --- views/js/validation.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/views/js/validation.js b/views/js/validation.js index bfd758d59..099b070cb 100644 --- a/views/js/validation.js +++ b/views/js/validation.js @@ -58,5 +58,15 @@ $(document).ready(function() { $('.alert.alert-success').hide(); showErrorMessage(profile_id_message); } + }); + + var $profileSwitch = $('input[name="MOLLIE_IFRAME"]'); + var $profileId = $('#MOLLIE_PROFILE_ID'); + $profileSwitch.on('change', function () { + if ($profileSwitch.prop('checked')) { + $profileId.closest('.form-group').show(); + } else { + $profileId.closest('.form-group').hide(); + } }) }); From 4ff18230231b369e3ad04a3b6dbfa6c208c048f3 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 15 Jan 2020 13:56:08 +0200 Subject: [PATCH 07/17] succes messages for admin order page Mollie module --- .../components/orderlines/OrderLinesTable.tsx | 5 +- .../components/orderlines/OrderPanel.tsx | 2 + .../components/orderlines/WarningContent.tsx | 76 +++++++++++++++++++ .../components/refund/RefundForm.tsx | 3 +- .../js/src/back/transaction/store/actions.ts | 10 +++ views/js/src/back/transaction/store/order.ts | 13 +++- 6 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 views/js/src/back/transaction/components/orderlines/WarningContent.tsx diff --git a/views/js/src/back/transaction/components/orderlines/OrderLinesTable.tsx b/views/js/src/back/transaction/components/orderlines/OrderLinesTable.tsx index 1d8628816..78bffba22 100644 --- a/views/js/src/back/transaction/components/orderlines/OrderLinesTable.tsx +++ b/views/js/src/back/transaction/components/orderlines/OrderLinesTable.tsx @@ -44,7 +44,7 @@ import OrderLinesTableFooter from '@transaction/components/orderlines//OrderLine import OrderLinesEditor from '@transaction/components/orderlines//OrderLinesEditor'; import ShipmentTrackingEditor from '@transaction/components/orderlines//ShipmentTrackingEditor'; import { cancelOrder, refundOrder, shipOrder } from '@transaction/misc/ajax'; -import { updateOrder } from '@transaction/store/actions'; +import {updateOrder, updateWarning} from '@transaction/store/actions'; import OrderLinesTableActions from '@transaction/components/orderlines//OrderLinesTableActions'; import { formatCurrency } from '@shared/tools'; import { IMollieApiOrder, IMollieOrderLine, IMollieTracking, } from '@shared/globals'; @@ -131,6 +131,7 @@ export default function OrderLinesTable(): ReactElement<{}> { const { success, order: newOrder } = await shipOrder(order.id, lines, tracking); if (success) { dispatch(updateOrder(newOrder)); + dispatch(updateWarning('shipped')); } else { import(/* webpackPrefetch: true, webpackChunkName: "sweetalert" */ 'sweetalert').then(({ default: swal }) => { swal({ @@ -184,6 +185,7 @@ export default function OrderLinesTable(): ReactElement<{}> { setLoading(true); const { success, order: newOrder } = await refundOrder(order.id, lines); if (success) { + dispatch(updateWarning('refunded')); dispatch(updateOrder(newOrder)); } else { import(/* webpackPrefetch: true, webpackChunkName: "sweetalert" */ 'sweetalert').then(({ default: swal }) => { @@ -239,6 +241,7 @@ export default function OrderLinesTable(): ReactElement<{}> { const { success, order: newOrder } = await cancelOrder(order.id, lines); if (success) { dispatch(updateOrder(newOrder)); + dispatch(updateWarning('canceled')); } else { swal({ icon: 'error', diff --git a/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx b/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx index f557fa21e..fde16393c 100644 --- a/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx +++ b/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx @@ -34,6 +34,7 @@ import React, { ReactElement, useCallback } from 'react'; import { useMappedState } from 'redux-react-hook'; import OrderPanelContent from '@transaction/components/orderlines/OrderPanelContent'; +import WarningContent from '@transaction/components/orderlines/WarningContent'; export default function OrderPanel(): ReactElement<{}> { const { config: { legacy, moduleDir }, config } = useCallback(useMappedState((state: IMollieOrderState): any => ({ @@ -76,6 +77,7 @@ export default function OrderPanel(): ReactElement<{}> { />  Mollie  + ); diff --git a/views/js/src/back/transaction/components/orderlines/WarningContent.tsx b/views/js/src/back/transaction/components/orderlines/WarningContent.tsx new file mode 100644 index 000000000..928f5f59d --- /dev/null +++ b/views/js/src/back/transaction/components/orderlines/WarningContent.tsx @@ -0,0 +1,76 @@ +/** + * 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. + * @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 + */ +import React, {ReactElement, useCallback} from 'react'; +import cx from 'classnames'; + +import PaymentInfo from '@transaction/components/orderlines/PaymentInfo'; +import OrderLinesInfo from '@transaction/components/orderlines/OrderLinesInfo'; +import LoadingDots from '@shared/components/LoadingDots'; +import {useMappedState} from 'redux-react-hook'; + +export default function WarningContent(): ReactElement<{}> { + + const {orderWarning, translations} = useMappedState((state): any => ({ + orderWarning: state.orderWarning, + translations: state.translations, + })); + + let message = ''; + switch (orderWarning) { + case "refunded" : + message = translations.refundWarning; + break; + case "shipped": + message = translations.shipmentWarning; + break; + case "canceled": + message = translations.cancelWarning; + break; + default: + message = ''; + } + + debugger; + if (!message) { + return ( + <> + + ); + } + + return ( + <> +
{message}
+ + ); +} diff --git a/views/js/src/back/transaction/components/refund/RefundForm.tsx b/views/js/src/back/transaction/components/refund/RefundForm.tsx index 77426dd87..6800ff23e 100644 --- a/views/js/src/back/transaction/components/refund/RefundForm.tsx +++ b/views/js/src/back/transaction/components/refund/RefundForm.tsx @@ -35,6 +35,7 @@ import xss from 'xss'; import { get } from 'lodash'; import { updatePayment } from '@transaction/store/actions'; +import { updateWarning } from '@transaction/store/actions'; import RefundButton from '@transaction/components/refund/RefundButton'; import PartialRefundButton from '@transaction/components/refund/PartialRefundButton'; import { refundPayment as refundPaymentAjax } from '@transaction/misc/ajax'; @@ -93,6 +94,7 @@ export default function RefundForm(): ReactElement<{}> { const { success = false, payment = null } = await refundPaymentAjax(transactionId, amount); if (success) { if (payment) { + dispatch(updateWarning('refunded')); dispatch(updatePayment(payment)); setRefundInput(''); } @@ -110,7 +112,6 @@ export default function RefundForm(): ReactElement<{}> { } } } - if (legacy) { return ( <> diff --git a/views/js/src/back/transaction/store/actions.ts b/views/js/src/back/transaction/store/actions.ts index 4c75ea033..5802fa448 100644 --- a/views/js/src/back/transaction/store/actions.ts +++ b/views/js/src/back/transaction/store/actions.ts @@ -38,6 +38,7 @@ export enum ReduxActionTypes { updateConfig = 'UPDATE_MOLLIE_ORDER_CONFIG', updateOrder = 'UPDATE_MOLLIE_ORDER', updatePayment = 'UPDATE_MOLLIE_PAYMENT', + updateWarning = 'UPDATE_MOLLIE_WARNING', updateCurrencies = 'UPDATE_MOLLIE_CURRENCIES', updateViewportWidth = 'UPDATE_MOLLIE_VIEWPORT_WIDTH', } @@ -63,6 +64,11 @@ export interface IUpdatePaymentAction { payment: IMollieApiPayment; } +export interface IUpdateWarningAction { + type: string; + orderWarning: string; +} + export interface IUpdateCurrenciesAction { type: string; currencies: ICurrencies; @@ -96,3 +102,7 @@ export function updatePayment(payment: IMollieApiPayment): IUpdatePaymentAction export function updateViewportWidth(width: number): IUpdateViewportWidthAction { return { type: ReduxActionTypes.updateViewportWidth, width }; } + +export function updateWarning(status: string): IUpdateWarningAction { + return { type: ReduxActionTypes.updateWarning, orderWarning: status }; +} \ No newline at end of file diff --git a/views/js/src/back/transaction/store/order.ts b/views/js/src/back/transaction/store/order.ts index b869c89d2..79fd22eba 100644 --- a/views/js/src/back/transaction/store/order.ts +++ b/views/js/src/back/transaction/store/order.ts @@ -37,7 +37,7 @@ import { IUpdateOrderAction, IUpdatePaymentAction, IUpdateTranslationsAction, - IUpdateViewportWidthAction, + IUpdateViewportWidthAction, IUpdateWarningAction, ReduxActionTypes } from '@transaction/store/actions'; import { ICurrencies, IMollieApiOrder, IMollieApiPayment, IMollieOrderConfig, ITranslations } from '@shared/globals'; @@ -50,6 +50,7 @@ declare global { order: IMollieApiOrder; payment: IMollieApiPayment; currencies: ICurrencies; + orderWarning: string; } } @@ -108,6 +109,15 @@ const viewportWidth = (state = initialViewportwidth, action: IUpdateViewportWidt } }; +const orderWarning = (state: any = {}, action: IUpdateWarningAction): string => { + switch (action.type) { + case ReduxActionTypes.updateWarning: + return action.orderWarning; + default: + return state; + } +}; + const checkoutApp = combineReducers({ translations, config, @@ -115,6 +125,7 @@ const checkoutApp = combineReducers({ payment, currencies, viewportWidth, + orderWarning, }); export default checkoutApp; From d155f1804d66e2349bf191aeae9d89bc93a3ceb7 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 15 Jan 2020 14:24:07 +0200 Subject: [PATCH 08/17] admin order Mollie messages added for payment API orders --- .../components/orderlines/OrderPanel.tsx | 85 ++++++++++--------- .../components/orderlines/WarningContent.tsx | 1 - .../components/refund/RefundPanel.tsx | 3 + views/js/src/back/transaction/index.tsx | 1 + 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx b/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx index fde16393c..a1aefd03d 100644 --- a/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx +++ b/views/js/src/back/transaction/components/orderlines/OrderPanel.tsx @@ -30,55 +30,56 @@ * @package Mollie * @link https://www.mollie.nl */ -import React, { ReactElement, useCallback } from 'react'; -import { useMappedState } from 'redux-react-hook'; +import React, {ReactElement, useCallback} from 'react'; +import {useMappedState} from 'redux-react-hook'; import OrderPanelContent from '@transaction/components/orderlines/OrderPanelContent'; import WarningContent from '@transaction/components/orderlines/WarningContent'; export default function OrderPanel(): ReactElement<{}> { - const { config: { legacy, moduleDir }, config } = useCallback(useMappedState((state: IMollieOrderState): any => ({ - translations: state.translations, - config: state.config, - order: state.order, - })), []); + const {config: {legacy, moduleDir}, config} = useCallback(useMappedState((state: IMollieOrderState): any => ({ + translations: state.translations, + config: state.config, + order: state.order, + })), []); - if (Object.keys(config).length <= 0) { - return null; - } + if (Object.keys(config).length <= 0) { + return null; + } + + if (legacy) { + return ( +
+ + Mollie logo +  Mollie  + + + +
+ ); + } - if (legacy) { return ( -
- - Mollie logo -  Mollie  - - -
+
+
+ Mollie logo +  Mollie  +
+ + +
); - } - - return ( -
-
- Mollie logo -  Mollie  -
- - -
- ); } diff --git a/views/js/src/back/transaction/components/orderlines/WarningContent.tsx b/views/js/src/back/transaction/components/orderlines/WarningContent.tsx index 928f5f59d..76f2a16e2 100644 --- a/views/js/src/back/transaction/components/orderlines/WarningContent.tsx +++ b/views/js/src/back/transaction/components/orderlines/WarningContent.tsx @@ -60,7 +60,6 @@ export default function WarningContent(): ReactElement<{}> { message = ''; } - debugger; if (!message) { return ( <> diff --git a/views/js/src/back/transaction/components/refund/RefundPanel.tsx b/views/js/src/back/transaction/components/refund/RefundPanel.tsx index fcf47e0d3..0315d7d91 100644 --- a/views/js/src/back/transaction/components/refund/RefundPanel.tsx +++ b/views/js/src/back/transaction/components/refund/RefundPanel.tsx @@ -36,6 +36,7 @@ import { useMappedState } from 'redux-react-hook'; import PaymentInfo from '@transaction/components/refund/PaymentInfo'; import RefundInfo from '@transaction/components/refund/RefundInfo'; import LoadingDots from '@shared/components/LoadingDots'; +import WarningContent from "@transaction/components/orderlines/WarningContent"; export default function RefundPanel(): ReactElement<{}> { const { payment, config }: Partial = useMappedState((state: IMollieOrderState): any => ({ @@ -61,6 +62,7 @@ export default function RefundPanel(): ReactElement<{}> { /> Mollie  + {!payment && } {!!payment && payment.status && ( <> @@ -83,6 +85,7 @@ export default function RefundPanel(): ReactElement<{}> { style={{ height: '16px', width: '16px', opacity: 0.8 }} /> Mollie  + {!payment && } {!!payment && payment.status && (
diff --git a/views/js/src/back/transaction/index.tsx b/views/js/src/back/transaction/index.tsx index 57592417f..60733874f 100644 --- a/views/js/src/back/transaction/index.tsx +++ b/views/js/src/back/transaction/index.tsx @@ -38,6 +38,7 @@ import { throttle } from 'lodash'; import { ICurrencies, IMollieOrderConfig, ITranslations } from '@shared/globals'; import LoadingDots from '@shared/components/LoadingDots'; +import {updateWarning} from "@transaction/store/actions"; const MolliePanel = lazy(() => import('@transaction/components/MolliePanel')); From f6b1c033d40af7162b0bb5cc6d96b5d4b296c1b5 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 15 Jan 2020 16:01:57 +0200 Subject: [PATCH 09/17] improved country restriction switch and selectors display, also improved profile display --- views/js/method_countries.js | 20 +++++++++++++------- views/js/validation.js | 21 +++++++++++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/views/js/method_countries.js b/views/js/method_countries.js index d4b6fc184..3100468f9 100644 --- a/views/js/method_countries.js +++ b/views/js/method_countries.js @@ -32,9 +32,9 @@ * @codingStandardsIgnoreStart */ -function toggleCountries(showCountries) +function toggleCountries(showCountries, countriesEnabledSwitch) { - if (showCountries.attr('checked')) { + if (showCountries.attr('checked') && countriesEnabledSwitch.attr('checked')) { $('div.js-country').closest('.form-group').show(); } else { $('div.js-country').closest('.form-group').fadeOut('slow'); @@ -53,10 +53,16 @@ $(document).ready(function() { } }); - var countriesSwitch = $('input[name="MOLLIE_METHOD_COUNTRIES_DISPLAY"]'); - toggleCountries(countriesSwitch); - countriesSwitch.on('change', function () { - toggleCountries(countriesSwitch); - }) + var $countriesEnabledSwitch = $('input[name="MOLLIE_METHOD_COUNTRIES"]'); + var $countriesSwitch = $('input[name="MOLLIE_METHOD_COUNTRIES_DISPLAY"]'); + toggleCountries($countriesSwitch, $countriesEnabledSwitch); + + $countriesSwitch.on('change', function () { + toggleCountries($countriesSwitch, $countriesEnabledSwitch); + }); + + $countriesEnabledSwitch.on('change', function () { + toggleCountries($countriesSwitch, $countriesEnabledSwitch); + }); }); diff --git a/views/js/validation.js b/views/js/validation.js index 099b070cb..514e96955 100644 --- a/views/js/validation.js +++ b/views/js/validation.js @@ -62,11 +62,24 @@ $(document).ready(function() { var $profileSwitch = $('input[name="MOLLIE_IFRAME"]'); var $profileId = $('#MOLLIE_PROFILE_ID'); + hideElementIfNotChecked($profileSwitch, $profileId); $profileSwitch.on('change', function () { - if ($profileSwitch.prop('checked')) { - $profileId.closest('.form-group').show(); + hideElementIfNotChecked($profileSwitch, $profileId); + }); + + var $enableCountriesSwitch = $('input[name="MOLLIE_METHOD_COUNTRIES"]'); + var $showCountriesSwitch = $('input[name="MOLLIE_METHOD_COUNTRIES_DISPLAY"]'); + hideElementIfNotChecked($enableCountriesSwitch, $showCountriesSwitch); + $enableCountriesSwitch.on('change', function () { + hideElementIfNotChecked($enableCountriesSwitch, $showCountriesSwitch); + }); + + function hideElementIfNotChecked($switch, $elementToHide) { + if ($switch.prop('checked')) { + $elementToHide.closest('.form-group').show(); } else { - $profileId.closest('.form-group').hide(); + $elementToHide.closest('.form-group').hide(); } - }) + } + }); From d9b19cad97e99dfc4b456780492aca3a02dadd1f Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 15 Jan 2020 16:11:23 +0200 Subject: [PATCH 10/17] fixed partially refunded payment status setting --- mollie.php | 2 +- views/templates/hook/order_info.tpl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mollie.php b/mollie.php index f17a2cff7..33fb1c689 100644 --- a/mollie.php +++ b/mollie.php @@ -179,7 +179,7 @@ class Mollie extends PaymentModule const MOLLIE_STATUS_PAID = 'MOLLIE_STATUS_PAID'; const MOLLIE_STATUS_CANCELED = 'MOLLIE_STATUS_CANCELED'; const MOLLIE_STATUS_EXPIRED = 'MOLLIE_STATUS_EXPIRED'; - const MOLLIE_STATUS_PARTIAL_REFUND = 'MOLLIE_PARTIAL_REFUND'; + const MOLLIE_STATUS_PARTIAL_REFUND = 'MOLLIE_STATUS_PARTIAL_REFUND'; const MOLLIE_STATUS_REFUNDED = 'MOLLIE_STATUS_REFUNDED'; const MOLLIE_MAIL_WHEN_OPEN = 'MOLLIE_MAIL_WHEN_OPEN'; const MOLLIE_MAIL_WHEN_PAID = 'MOLLIE_MAIL_WHEN_PAID'; diff --git a/views/templates/hook/order_info.tpl b/views/templates/hook/order_info.tpl index ac0b58181..1b0c4aee5 100644 --- a/views/templates/hook/order_info.tpl +++ b/views/templates/hook/order_info.tpl @@ -112,7 +112,10 @@ unableToShip: '{l s='Unable to ship' mod='mollie' js=1}', unableToRefund: '{l s='Unable to refund' mod='mollie' js=1}', unableToCancel: '{l s='Unable to cancel' mod='mollie' js=1}', - refundsAreCurrentlyUnavailable: '{l s='Refunds are currently unavailable' mod='mollie' js=1}' + refundsAreCurrentlyUnavailable: '{l s='Refunds are currently unavailable' mod='mollie' js=1}', + refundWarning: '{l s='Refund was made successfully!' mod='mollie' js=1}', + shipmentWarning: '{l s='Shipment was made successfully!' mod='mollie' js=1}', + cancelWarning: '{l s='Order was canceled successfully!' mod='mollie' js=1}' }, {$currencies|json_encode} ); From 7dd7f99698264795022cbcbcb914072938a1de01 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 15 Jan 2020 17:43:26 +0200 Subject: [PATCH 11/17] fixed custom css and view logs button to redirect to new page --- mollie.php | 12 ++++++++++-- views/templates/admin/view_logs.tpl | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mollie.php b/mollie.php index 33fb1c689..469feaf0c 100644 --- a/mollie.php +++ b/mollie.php @@ -2247,7 +2247,12 @@ protected function addCSSFile($file = null) $file = str_replace('{OVERRIDE}', _PS_THEME_OVERRIDE_DIR_, $file); } } - $this->context->controller->addCSS($file); + + return $file; + +// $this->context->controller->registerStylesheet(sha1($file), $file, ['media' => 'all', 'priority' => 80]); + +// $this->context->controller->addCSS($file); } // Hooks @@ -2257,7 +2262,6 @@ protected function addCSSFile($file = null) */ public function hookDisplayHeader() { - $this->addCSSFile($this->_path.'views/css/front.css'); if ($this->context->controller instanceof OrderControllerCore) { Media::addJsDef([ 'profileId' => Configuration::get(Mollie::MOLLIE_PROFILE_ID), @@ -2283,6 +2287,10 @@ public function hookDisplayHeader() if (Configuration::get('PS_SSL_ENABLED_EVERYWHERE')) { $this->context->controller->addJS($this->getPathUri() . 'views/js/apple_payment.js'); } + $this->context->smarty->assign(array( + 'custom_css' => Configuration::get(static::MOLLIE_CSS), + )); + return $this->display(__FILE__, 'views/templates/front/custom_css.tpl'); } } diff --git a/views/templates/admin/view_logs.tpl b/views/templates/admin/view_logs.tpl index e3b4263ae..49ef1adef 100644 --- a/views/templates/admin/view_logs.tpl +++ b/views/templates/admin/view_logs.tpl @@ -30,4 +30,4 @@ * @package Mollie * @link https://www.mollie.nl *} - \ No newline at end of file + \ No newline at end of file From 886209928f63d538ed0dab10ef9b82aae99b9bb7 Mon Sep 17 00:00:00 2001 From: marius Date: Thu, 16 Jan 2020 13:50:13 +0200 Subject: [PATCH 12/17] improved error messages in front office and translation fixes --- .gitignore | 1 + controllers/front/payment.php | 4 +- controllers/front/return.php | 23 +++++++++- controllers/front/webhook.php | 20 ++++----- mollie.php | 62 ++++++++++++-------------- tests/_support/Fake/Module.php | 8 ++-- upgrade/Upgrade-3.3.0.php | 2 +- views/css/mollie_iframe.css | 4 ++ views/templates/front/mollie_error.tpl | 2 +- 9 files changed, 73 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 44bdccbb3..869e8693d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ package-lock.json build/ prestashop/ .codecept.phar +/translations/ diff --git a/controllers/front/payment.php b/controllers/front/payment.php index 0c3088511..8f2efa84a 100644 --- a/controllers/front/payment.php +++ b/controllers/front/payment.php @@ -213,7 +213,7 @@ public function initContent() 'step' => 1, ] ); - $this->errors[] = $this->l('Failed to validate order'); + $this->errors[] = $this->l('Failed to validate order', 'payment'); $this->redirectWithNotifications($redirectLink); } } @@ -281,7 +281,7 @@ protected function createPayment($data) $payment = $this->module->api->payments->create($data); } } catch (Exception $e) { - throw new ApiException(); + throw new ApiException($e->getMessage()); } return $payment; } diff --git a/controllers/front/return.php b/controllers/front/return.php index 9890bed67..107244073 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -175,8 +175,8 @@ public function initContent() break; default: $data['msg_details'] = $this->module->lang('The transaction has an unexpected status.'); - if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) { - Logger::addLog(__METHOD__.'said: The transaction has an unexpected status ('.$data['mollie_info']['bank_status'].')', Mollie::WARNING); + if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) { + PrestaShopLogger::addLog(__METHOD__.'said: The transaction has an unexpected status ('.$data['mollie_info']['bank_status'].')', Mollie::WARNING); } break; } @@ -312,12 +312,27 @@ protected function processGetStatus() $_GET['module'] = $this->module->name; } $webhookController = new MollieWebhookModuleFrontController(); + if (Tools::substr($transactionId, 0, 3) === 'ord') { $apiPayment = $webhookController->processTransaction($this->module->api->orders->get($transactionId, array('embed' => 'payments'))); } else { $apiPayment = $webhookController->processTransaction($this->module->api->payments->get($transactionId)); } + if (!isset($apiPayment->status)) { + $status = static::DONE; + $href = $this->context->link->getPagelink('order', true, null, array('step' => 3)); + $tagMessage = str_replace(' ', '_', $apiPayment); + $href .= "#mollieMessage={$tagMessage}"; + + die(json_encode(array( + 'success' => true, + 'status' => $status, + 'response' => json_encode($apiPayment), + 'href' => $href + ))); + } + switch ($apiPayment->status) { case \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED: case \Mollie\Api\Types\PaymentStatus::STATUS_FAILED: @@ -327,6 +342,10 @@ protected function processGetStatus() if (isset($apiPayment->details->failureMessage)) { $tagMessage = str_replace(' ', '_', $apiPayment->details->failureMessage); $href .= "#mollieMessage={$tagMessage}"; + } else { + $message = $this->module->l('Payment was canceled', 'return'); + $tagMessage = str_replace(' ', '_', $message); + $href .= "#mollieMessage={$tagMessage}"; } die(json_encode(array( 'success' => true, diff --git a/controllers/front/webhook.php b/controllers/front/webhook.php index dd6489281..aa7f75863 100644 --- a/controllers/front/webhook.php +++ b/controllers/front/webhook.php @@ -79,7 +79,7 @@ protected function displayMaintenancePage() public function initContent() { if (Configuration::get(Mollie::DEBUG_LOG_ALL)) { - Logger::addLog('Mollie incoming webhook: '.Tools::file_get_contents('php://input')); + PrestaShopLogger::addLog('Mollie incoming webhook: '.Tools::file_get_contents('php://input')); } die($this->executeWebhook()); @@ -98,8 +98,8 @@ public function initContent() protected function executeWebhook() { if (Tools::getValue('testByMollie')) { - if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) { - Logger::addLog(__METHOD__.' said: Mollie webhook tester successfully communicated with the shop.', Mollie::NOTICE); + if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) { + PrestaShopLogger::addLog(__METHOD__.' said: Mollie webhook tester successfully communicated with the shop.', Mollie::NOTICE); } return 'OK'; @@ -136,11 +136,11 @@ protected function executeWebhook() public function processTransaction($transaction) { if (empty($transaction)) { - if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) { - Logger::addLog(__METHOD__.' said: Received webhook request without proper transaction ID.', Mollie::WARNING); + if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) { + PrestaShopLogger::addLog(__METHOD__.' said: Received webhook request without proper transaction ID.', Mollie::WARNING); } - return 'NO ID'; + return $this->module->l('Transaction failed', 'webhook'); } // Ensure that we are dealing with a Payment object, in case of transaction ID or Payment object w/ Order ID, convert @@ -205,7 +205,7 @@ public function processTransaction($transaction) } if (!isset($apiPayment)) { - return 'NOT OK'; + return $this->module->l('Transaction failed', 'webhook'); } $psPayment = Mollie::getPaymentBy('transaction_id', $transaction->id); @@ -270,14 +270,14 @@ public function processTransaction($transaction) $this->saveOrderTransactionData($apiPayment->id, $apiPayment->method, $orderId); if (!$this->savePaymentStatus($transaction->id, $apiPayment->status, $orderId)) { - if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) { - Logger::addLog(__METHOD__.' said: Could not save Mollie payment status for transaction "'.$transaction->id.'". Reason: '.Db::getInstance()->getMsgError(), Mollie::WARNING); + if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) { + PrestaShopLogger::addLog(__METHOD__.' said: Could not save Mollie payment status for transaction "'.$transaction->id.'". Reason: '.Db::getInstance()->getMsgError(), Mollie::WARNING); } } // Log successful webhook requests in extended log mode only if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ALL) { - Logger::addLog(__METHOD__.' said: Received webhook request for order '.(int) $orderId.' / transaction '.$transaction->id, Mollie::NOTICE); + PrestaShopLogger::addLog(__METHOD__.' said: Received webhook request for order '.(int) $orderId.' / transaction '.$transaction->id, Mollie::NOTICE); } Hook::exec('actionOrderStatusUpdate', array('newOrderStatus' => (int) $this->module->statuses[$apiPayment->status], 'id_order' => (int) $orderId)); diff --git a/mollie.php b/mollie.php index 469feaf0c..c81f6301a 100644 --- a/mollie.php +++ b/mollie.php @@ -305,10 +305,10 @@ public function __construct() $this->api->addVersionString("MolliePrestaShop/{$this->version}"); } } catch (\Mollie\Api\Exceptions\IncompatiblePlatform $e) { - Logger::addLog(__METHOD__.' - System incompatible: '.$e->getMessage(), static::CRASH); + PrestaShopLogger::addLog(__METHOD__.' - System incompatible: '.$e->getMessage(), static::CRASH); } catch (\Mollie\Api\Exceptions\ApiException $e) { $this->warning = $this->l('Payment error:').$e->getMessage(); - Logger::addLog(__METHOD__.' said: '.$this->warning, static::CRASH); + PrestaShopLogger::addLog(__METHOD__.' said: '.$this->warning, static::CRASH); } $this->statuses = array( @@ -2249,10 +2249,6 @@ protected function addCSSFile($file = null) } return $file; - -// $this->context->controller->registerStylesheet(sha1($file), $file, ['media' => 'all', 'priority' => 80]); - -// $this->context->controller->addCSS($file); } // Hooks @@ -4546,7 +4542,7 @@ public function validateMollieOrderLegacy( } } else { $error = Tools::displayError('Order creation failed'); - Logger::addLog($error, 4, '0000002', 'Cart', (int) $order->id_cart); + PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', (int) $order->id_cart); die($error); } } // End foreach $order_detail_list @@ -4556,7 +4552,7 @@ public function validateMollieOrderLegacy( return true; } else { $error = Tools::displayError('Cart cannot be loaded or an order has already been placed using this cart'); - Logger::addLog($error, 4, '0000001', 'Cart', (int) $this->context->cart->id); + PrestaShopLogger::addLog($error, 4, '0000001', 'Cart', (int) $this->context->cart->id); die($error); } } @@ -4607,7 +4603,7 @@ public function validateMollieOrder( } if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Function called', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Function called', 1, null, 'Cart', (int) $idCart, true); } if (!isset($this->context)) { $this->context = Context::getContext(); @@ -4630,17 +4626,17 @@ public function validateMollieOrder( } $orderStatus = new OrderState((int) $idOrderState, (int) $this->context->language->id); if (!Validate::isLoadedObject($orderStatus)) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Order Status cannot be loaded', 3, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Order Status cannot be loaded', 3, null, 'Cart', (int) $idCart, true); throw new PrestaShopException('Can\'t load Order status'); } if (!$this->active) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Module is not active', 3, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Module is not active', 3, null, 'Cart', (int) $idCart, true); die(Tools::displayError()); } // Does order already exists ? if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists() == false) { if ($secureKey !== false && $secureKey != $this->context->cart->secure_key) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Secure key does not match', 3, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Secure key does not match', 3, null, 'Cart', (int) $idCart, true); die(Tools::displayError()); } // For each package, generate an order @@ -4660,7 +4656,7 @@ public function validateMollieOrder( $orderDetailList = array(); if (!$this->currentOrderReference || Order::getByReference($this->currentOrderReference)->count()) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Order cannot be created', 3, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Order cannot be created', 3, null, 'Cart', (int) $idCart, true); throw new PrestaShopException('Order reference not set before call to '.__CLASS__.'::validateMollieOrder'); } $cartTotalPaid = (float) Tools::ps_round((float) $this->context->cart->getOrderTotal(true, Cart::BOTH), 2); @@ -4696,7 +4692,7 @@ public function validateMollieOrder( } else { $error = sprintf($this->l('The cart rule named "%1s" (ID %2s) used in this cart is not valid and has been withdrawn from cart'), array($ruleName, (int) $rule->id)); } - Logger::addLog($error, 3, '0000002', 'Cart', (int) $this->context->cart->id); + PrestaShopLogger::addLog($error, 3, '0000002', 'Cart', (int) $this->context->cart->id); } } } @@ -4767,12 +4763,12 @@ public function validateMollieOrder( $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Order is about to be added', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Order is about to be added', 1, null, 'Cart', (int) $idCart, true); } // Creating order $result = $order->add(); if (!$result) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Order cannot be created', 3, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Order cannot be created', 3, null, 'Cart', (int) $idCart, true); throw new PrestaShopException('Can\'t save Order'); } // Amount paid by customer is not the right one -> Status = payment error @@ -4784,14 +4780,14 @@ public function validateMollieOrder( } $orderList[] = $order; if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - OrderDetail is about to be added', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - OrderDetail is about to be added', 1, null, 'Cart', (int) $idCart, true); } // Insert new Order detail list using cart for the current order $orderDetail = new OrderDetail(null, null, $this->context); $orderDetail->createList($order, $this->context->cart, $idOrderState, $order->product_list, 0, true, $packageList[$idAddress][$idPackage]['id_warehouse']); $orderDetailList[] = $orderDetail; if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - OrderCarrier is about to be added', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - OrderCarrier is about to be added', 1, null, 'Cart', (int) $idCart, true); } // Adding an entry in order_carrier table if (!is_null($carrier)) { @@ -4810,11 +4806,11 @@ public function validateMollieOrder( $this->context->country = $context_country; } if (!$this->context->country->active) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Country is not active', 3, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Country is not active', 3, null, 'Cart', (int) $idCart, true); throw new PrestaShopException('The order address country is not active.'); } if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Payment is about to be added', 1, null, 'Cart', (int) $idCart, true); + 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) { @@ -4827,7 +4823,7 @@ public function validateMollieOrder( $transaction_id = null; } if (isset($order) && !$order->addOrderPayment($amountPaid, null, $transaction_id)) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Cannot save Order Payment', 3, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Cannot save Order Payment', 3, null, 'Cart', (int) $idCart, true); throw new PrestaShopException('Can\'t save Order Payment'); } } @@ -4848,7 +4844,7 @@ public function validateMollieOrder( $message = strip_tags($message, $this->display(__FILE__, 'views/templates/front/break.tpl')); if (Validate::isCleanHtml($message)) { if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Message is about to be added', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Message is about to be added', 1, null, 'Cart', (int) $idCart, true); } $msg->message = $message; $msg->id_cart = (int) $idCart; @@ -5137,7 +5133,7 @@ public function validateMollieOrder( } } if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Hook validateOrder is about to be called', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Hook validateOrder is about to be called', 1, null, 'Cart', (int) $idCart, true); } // Hook validate order Hook::exec('actionValidateOrder', array( @@ -5153,7 +5149,7 @@ public function validateMollieOrder( } } if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Order Status is about to be added', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Order Status is about to be added', 1, null, 'Cart', (int) $idCart, true); } // Switch to back order if needed if (Configuration::get('PS_STOCK_MANAGEMENT') && @@ -5253,7 +5249,7 @@ public function validateMollieOrder( $fileAttachment = null; } if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - Mail is about to be sent', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - Mail is about to be sent', 1, null, 'Cart', (int) $idCart, true); } $orderLanguage = new Language((int) $order->id_lang); if (Validate::isEmail($this->context->customer->email)) { @@ -5306,7 +5302,7 @@ public function validateMollieOrder( } } else { $error = $this->l('Order creation failed'); - Logger::addLog($error, 4, '0000002', 'Cart', (int) $order->id_cart); + PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', (int) $order->id_cart); die($error); } } // End foreach $order_detail_list @@ -5315,13 +5311,13 @@ public function validateMollieOrder( $this->currentOrder = (int) $order->id; } if (version_compare(_PS_VERSION_, '1.6.0.9', '>=') && static::DEBUG_MODE) { - Logger::addLog(__CLASS__.'::validateMollieOrder - End of validateOrder', 1, null, 'Cart', (int) $idCart, true); + PrestaShopLogger::addLog(__CLASS__.'::validateMollieOrder - End of validateOrder', 1, null, 'Cart', (int) $idCart, true); } return true; } else { $error = $this->l('Cart cannot be loaded or an order has already been placed using this cart'); - Logger::addLog($error, 4, '0000001', 'Cart', (int) $this->context->cart->id); + PrestaShopLogger::addLog($error, 4, '0000001', 'Cart', (int) $this->context->cart->id); die($error); } } @@ -5925,7 +5921,7 @@ public function displayAjaxMollieOrderInfo() } } } catch (Exception $e) { - Logger::addLog("Mollie module error: {$e->getMessage()}"); + PrestaShopLogger::addLog("Mollie module error: {$e->getMessage()}"); return array('success' => false); } @@ -6079,10 +6075,10 @@ public function hookActionOrderStatusUpdate($params = array()) try { $dbPayment = static::getPaymentBy('order_id', (int) $idOrder); } catch (PrestaShopDatabaseException $e) { - Logger::addLog("Mollie module error: {$e->getMessage()}"); + PrestaShopLogger::addLog("Mollie module error: {$e->getMessage()}"); return; } catch (PrestaShopException $e) { - Logger::addLog("Mollie module error: {$e->getMessage()}"); + PrestaShopLogger::addLog("Mollie module error: {$e->getMessage()}"); return; } if (empty($dbPayment) || !isset($dbPayment['transaction_id'])) { @@ -6109,10 +6105,10 @@ public function hookActionOrderStatusUpdate($params = array()) $apiOrder->shipAll($shipmentInfo); } catch (\Mollie\Api\Exceptions\ApiException $e) { - Logger::addLog("Mollie module error: {$e->getMessage()}"); + PrestaShopLogger::addLog("Mollie module error: {$e->getMessage()}"); return; } catch (Exception $e) { - Logger::addLog("Mollie module error: {$e->getMessage()}"); + PrestaShopLogger::addLog("Mollie module error: {$e->getMessage()}"); return; } } diff --git a/tests/_support/Fake/Module.php b/tests/_support/Fake/Module.php index d367e6ea1..943dfad01 100644 --- a/tests/_support/Fake/Module.php +++ b/tests/_support/Fake/Module.php @@ -114,8 +114,8 @@ public function uninstall() return true; } - public function l($string, $specific = false, $locale = null) - { - return $string; - } +// public function l($string, $specific = false, $locale = null) +// { +// return $string; +// } } diff --git a/upgrade/Upgrade-3.3.0.php b/upgrade/Upgrade-3.3.0.php index 1c694eb4f..0cd2fb6a7 100644 --- a/upgrade/Upgrade-3.3.0.php +++ b/upgrade/Upgrade-3.3.0.php @@ -58,7 +58,7 @@ function upgrade_module_3_3_0($module) ); } } catch (PrestaShopException $e) { - Logger::addLog("Mollie update error: {$e->getMessage()}"); + PrestaShopLogger::addLog("Mollie update error: {$e->getMessage()}"); } if (method_exists($module, 'setDefaultCarrierStatuses')) { diff --git a/views/css/mollie_iframe.css b/views/css/mollie_iframe.css index 986c0a632..96a4c6bc6 100644 --- a/views/css/mollie_iframe.css +++ b/views/css/mollie_iframe.css @@ -95,4 +95,8 @@ label.mollie-input-error { body#checkout .additional-information.mollie-addition-info { margin-left: 0; } +} + +#mollie-notifications { + margin-bottom: 0; } \ No newline at end of file diff --git a/views/templates/front/mollie_error.tpl b/views/templates/front/mollie_error.tpl index 88a8c41fb..78df11706 100644 --- a/views/templates/front/mollie_error.tpl +++ b/views/templates/front/mollie_error.tpl @@ -33,7 +33,7 @@
From 8c87001cccf779c67c5ced7cbc24efe656250abf Mon Sep 17 00:00:00 2001 From: marius Date: Thu, 16 Jan 2020 14:34:29 +0200 Subject: [PATCH 13/17] improved error display in front office --- controllers/front/return.php | 8 +++++--- views/js/front/mollie_error_handle.js | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index 107244073..e527e8073 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -142,10 +142,12 @@ public function initContent() $data['wait'] = true; break; case \Mollie\Api\Types\PaymentStatus::STATUS_FAILED: - Tools::redirect($this->context->link->getPagelink('order', true, null, array('step' => 3))); - break; case \Mollie\Api\Types\PaymentStatus::STATUS_CANCELED: - Tools::redirect($this->context->link->getPagelink('order', true, null, array('step' => 3))); + $message = $this->module->l('Payment was canceled', 'return'); + $tagMessage = str_replace(' ', '_', $message); + $href = $this->context->link->getPagelink('order', true, null, array('step' => 3)); + $href .= "#mollieMessage={$tagMessage}"; + Tools::redirect($href); break; case \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED: $data['msg_details'] = $this->module->lang('Unfortunately your payment was expired.'); diff --git a/views/js/front/mollie_error_handle.js b/views/js/front/mollie_error_handle.js index 371679513..8f37b0558 100644 --- a/views/js/front/mollie_error_handle.js +++ b/views/js/front/mollie_error_handle.js @@ -32,8 +32,9 @@ * @codingStandardsIgnoreStart */ $(document).ready(function () { - var hashTag = document.URL.substr(document.URL.indexOf('#')+1); - if (hashTag) { + var hasHashTag = document.URL.indexOf('#'); + if (hasHashTag >= 0) { + var hashTag = document.URL.substr(document.URL.indexOf('#')+1); parent.location.hash = ''; $.ajax({ url: ajaxUrl, From 85eb170d05d0065510bdeab128d0193145040d90 Mon Sep 17 00:00:00 2001 From: marius Date: Thu, 16 Jan 2020 14:46:02 +0200 Subject: [PATCH 14/17] changed order status calidation in front office --- controllers/front/return.php | 52 +----------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index e527e8073..05588d19a 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -131,57 +131,7 @@ public function initContent() ) { $data['msg_details'] = $this->module->lang('We have not received a definite payment status. You will be notified as soon as we receive a confirmation of the bank/merchant.'); } else { - switch ($data['mollie_info']['bank_status']) { - case 'created': - $data['wait'] = true; - break; - case \Mollie\Api\Types\PaymentStatus::STATUS_OPEN: - $data['wait'] = true; - break; - case \Mollie\Api\Types\PaymentStatus::STATUS_PENDING: - $data['wait'] = true; - break; - case \Mollie\Api\Types\PaymentStatus::STATUS_FAILED: - case \Mollie\Api\Types\PaymentStatus::STATUS_CANCELED: - $message = $this->module->l('Payment was canceled', 'return'); - $tagMessage = str_replace(' ', '_', $message); - $href = $this->context->link->getPagelink('order', true, null, array('step' => 3)); - $href .= "#mollieMessage={$tagMessage}"; - Tools::redirect($href); - break; - case \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED: - $data['msg_details'] = $this->module->lang('Unfortunately your payment was expired.'); - break; - case \Mollie\Api\Types\PaymentStatus::STATUS_PAID: - case \Mollie\Api\Types\PaymentStatus::STATUS_AUTHORIZED: - // Validate the Order - if (isset($cart) && Validate::isLoadedObject($cart)) { - Tools::redirect( - $this->context->link->getPageLink( - 'order-confirmation', - true, - null, - array( - 'id_cart' => (int) $cart->id, - 'id_module' => (int) $this->module->id, - 'id_order' => (int) version_compare(_PS_VERSION_, '1.7.1.0', '>=') - ? Order::getIdByCartId((int) $cart->id) - : Order::getOrderByCartId((int) $cart->id), - 'key' => $cart->secure_key, - ) - ) - ); - } - - $data['msg_details'] = $this->module->lang('Thank you. Your order has been received.'); - break; - default: - $data['msg_details'] = $this->module->lang('The transaction has an unexpected status.'); - if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) { - PrestaShopLogger::addLog(__METHOD__.'said: The transaction has an unexpected status ('.$data['mollie_info']['bank_status'].')', Mollie::WARNING); - } - break; - } + $data['wait'] = true; } } else { // Not allowed? Don't make query but redirect. From 4071ea1599b10df541f3a04af36118961027d7e6 Mon Sep 17 00:00:00 2001 From: marius Date: Fri, 24 Jan 2020 17:58:52 +0200 Subject: [PATCH 15/17] fixed issue where custom carrier url wouldnt be filled when trying to ship order --- mollie.php | 8 ++++---- views/js/src/back/carrierconfig/index.tsx | 1 + .../components/orderlines/ShipmentTrackingEditor.tsx | 12 ++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mollie.php b/mollie.php index c81f6301a..bf42c1be6 100644 --- a/mollie.php +++ b/mollie.php @@ -6206,10 +6206,10 @@ public static function getShipmentInformation($idOrder) $orderCarrier = new OrderCarrier($order->getIdOrderCarrier()); $shippingNumber = $orderCarrier->tracking_number; } - - if (!$shippingNumber || !$carrier->name) { - return array(); - } +// +// if (!$shippingNumber || !$carrier->name) { +// return array(); +// } $invoicePostcode = Tools::strtoupper(str_replace(' ', '', $invoiceAddress->postcode)); $invoiceCountryIso = Tools::strtoupper(Country::getIsoById($invoiceAddress->id_country)); diff --git a/views/js/src/back/carrierconfig/index.tsx b/views/js/src/back/carrierconfig/index.tsx index 2db19cddc..96b31f8ef 100644 --- a/views/js/src/back/carrierconfig/index.tsx +++ b/views/js/src/back/carrierconfig/index.tsx @@ -52,6 +52,7 @@ export default ( import(/* webpackChunkName: "carrierconfig" */ '@carrierconfig/components/CarrierConfig'), ]); + debugger; store.dispatch(updateConfig(config)); store.dispatch(updateTranslations(translations)); diff --git a/views/js/src/back/transaction/components/orderlines/ShipmentTrackingEditor.tsx b/views/js/src/back/transaction/components/orderlines/ShipmentTrackingEditor.tsx index a29617d92..a5d8f457d 100644 --- a/views/js/src/back/transaction/components/orderlines/ShipmentTrackingEditor.tsx +++ b/views/js/src/back/transaction/components/orderlines/ShipmentTrackingEditor.tsx @@ -35,6 +35,7 @@ import styled from 'styled-components'; import { get, isEmpty } from 'lodash'; import { IMollieOrderConfig, IMollieTracking, ITranslations } from '@shared/globals'; +import {useMappedState} from "redux-react-hook"; interface IProps { edited: (newLines: IMollieTracking) => void; @@ -70,13 +71,12 @@ text-align: left!important; export default function ShipmentTrackingEditor(props: IProps): ReactElement<{}> { const [skipTracking, setSkipTracking] = useState(false); - const [carrier, setCarrier] = useState(get(props, 'config.tracking.carrier', '')); - const [carrierChanged, setCarrierChanged] = useState(!!get(props, 'config.tracking.carrier', false)); - const [code, setCode] = useState(get(props, 'config.tracking.code', '')); - const [codeChanged, setCodeChanged] = useState(!!get(props, 'config.tracking.code', '')); - const [url, setUrl] = useState(get(props, 'config.tracking.url', '')); + const [carrier, setCarrier] = useState(get(props, 'config.tracking.tracking.carrier', '')); + const [carrierChanged, setCarrierChanged] = useState(!!get(props, 'config.tracking.tracking.carrier', false)); + const [code, setCode] = useState(get(props, 'config.tracking.tracking.code', '')); + const [codeChanged, setCodeChanged] = useState(!!get(props, 'config.tracking.tracking.code', '')); + const [url, setUrl] = useState(get(props, 'config.tracking.tracking.url', '')); const { translations, edited } = props; - function _getCarrierInvalid(): boolean { return !skipTracking && isEmpty(carrier.replace(/\s+/, '')) && carrierChanged; } From 72680846393873de4610f2f5fdc55012c2b26496 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 29 Jan 2020 15:19:43 +0200 Subject: [PATCH 16/17] improved label on credit card --- views/css/mollie_iframe.css | 1 + 1 file changed, 1 insertion(+) diff --git a/views/css/mollie_iframe.css b/views/css/mollie_iframe.css index 96a4c6bc6..209559481 100644 --- a/views/css/mollie_iframe.css +++ b/views/css/mollie_iframe.css @@ -16,6 +16,7 @@ label.mollie-input-error { position: absolute; left: 15px; color: #999; + pointer-events: none; } .mollie-input { From aa150a1960ba54cd8d58c9c78bd35c48ad3cf533 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 29 Jan 2020 16:57:31 +0200 Subject: [PATCH 17/17] removed possability to send mails on expired orders, small js and visual fixes --- mollie.php | 6 +++--- views/js/validation.js | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mollie.php b/mollie.php index bf42c1be6..542dc0846 100644 --- a/mollie.php +++ b/mollie.php @@ -315,7 +315,7 @@ public function __construct() \Mollie\Api\Types\PaymentStatus::STATUS_PAID => Configuration::get(static::MOLLIE_STATUS_PAID), \Mollie\Api\Types\PaymentStatus::STATUS_AUTHORIZED => Configuration::get(static::MOLLIE_STATUS_PAID), \Mollie\Api\Types\PaymentStatus::STATUS_CANCELED => Configuration::get(static::MOLLIE_STATUS_CANCELED), - \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED => Configuration::get(static::MOLLIE_STATUS_EXPIRED), +// \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED => Configuration::get(static::MOLLIE_STATUS_EXPIRED), \Mollie\Api\Types\RefundStatus::STATUS_REFUNDED => Configuration::get(static::MOLLIE_STATUS_REFUNDED), \Mollie\Api\Types\PaymentStatus::STATUS_OPEN => Configuration::get(static::MOLLIE_STATUS_OPEN), \Mollie\Api\Types\PaymentStatus::STATUS_FAILED => Configuration::get(static::MOLLIE_STATUS_CANCELED), @@ -1002,10 +1002,10 @@ protected function getAccountSettingsSection($isApiKeyProvided) ), array( 'type' => 'mollie-carrier-switch', - 'label' => $this->l('Automatically ship when marked as `shipped`'), + 'label' => $this->l('Automatically ship on marked statuses'), 'tab' => $generalSettings, 'name' => static::MOLLIE_AUTO_SHIP_MAIN, - 'desc' => $this->l('Enabling this feature will automatically send shipment information when an order has been marked as `shipped`'), + 'desc' => $this->l('Enabling this feature will automatically send shipment information when an order gets marked status'), 'is_bool' => true, 'values' => array( array( diff --git a/views/js/validation.js b/views/js/validation.js index 514e96955..a7eca52d3 100644 --- a/views/js/validation.js +++ b/views/js/validation.js @@ -67,6 +67,13 @@ $(document).ready(function() { hideElementIfNotChecked($profileSwitch, $profileId); }); + var $automaticallyShipSwitch = $('input[name="MOLLIE_AS_MAIN"]'); + var $statusesContainer = $('#MOLLIE_AS_STATUSES_container'); + hideElementIfNotChecked($automaticallyShipSwitch, $statusesContainer); + $automaticallyShipSwitch.on('change', function () { + hideElementIfNotChecked($automaticallyShipSwitch, $statusesContainer); + }); + var $enableCountriesSwitch = $('input[name="MOLLIE_METHOD_COUNTRIES"]'); var $showCountriesSwitch = $('input[name="MOLLIE_METHOD_COUNTRIES_DISPLAY"]'); hideElementIfNotChecked($enableCountriesSwitch, $showCountriesSwitch);