From d5e01994b747b36f3fdc14cc2c6dede9535ade8f Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Wed, 6 Jun 2018 08:17:16 +0200 Subject: [PATCH 1/5] Settlement Amount not available for Paypal & Giftcards --- Model/Mollie.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Model/Mollie.php b/Model/Mollie.php index 8edc8986f26..e87e6692dab 100644 --- a/Model/Mollie.php +++ b/Model/Mollie.php @@ -393,11 +393,15 @@ public function processTransaction($orderId, $type = 'webhook') $payment->setIsTransactionClosed(true); $payment->registerCaptureNotification($order->getBaseGrandTotal(), true); - if ($paymentData->amount->currency != $paymentData->settlementAmount->currency) { - $message = __('Mollie: Captured %1, Settlement Amount %2', - $paymentData->amount->currency . ' ' . $paymentData->amount->value, - $paymentData->settlementAmount->currency . ' ' . $paymentData->settlementAmount->value); - $order->addStatusToHistory($order->getState(), $message, false)->save(); + if ($paymentData->settlementAmount !== null) { + if ($paymentData->amount->currency != $paymentData->settlementAmount->currency) { + $message = __( + 'Mollie: Captured %1, Settlement Amount %2', + $paymentData->amount->currency . ' ' . $paymentData->amount->value, + $paymentData->settlementAmount->currency . ' ' . $paymentData->settlementAmount->value + ); + $order->addStatusHistoryComment($message); + } } } From c9786fdd6ed77886aeb1ef220f8d4dff21a5aae7 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Wed, 6 Jun 2018 09:07:25 +0200 Subject: [PATCH 2/5] Option to use default processing status --- Model/Adminhtml/Source/Processing.php | 39 +++++++++++++++++++++++++++ Model/Mollie.php | 20 +++++++------- etc/adminhtml/system.xml | 2 +- 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 Model/Adminhtml/Source/Processing.php diff --git a/Model/Adminhtml/Source/Processing.php b/Model/Adminhtml/Source/Processing.php new file mode 100644 index 00000000000..402ddb7b109 --- /dev/null +++ b/Model/Adminhtml/Source/Processing.php @@ -0,0 +1,39 @@ +_stateStatuses + ? $this->_orderConfig->getStateStatuses($this->_stateStatuses) + : $this->_orderConfig->getStatuses(); + + $options = [['value' => '', 'label' => __('-- Use Default --')]]; + foreach ($statuses as $code => $label) { + $options[] = ['value' => $code, 'label' => $label]; + } + return $options; + } +} diff --git a/Model/Mollie.php b/Model/Mollie.php index e87e6692dab..543b477e2bb 100644 --- a/Model/Mollie.php +++ b/Model/Mollie.php @@ -392,6 +392,7 @@ public function processTransaction($orderId, $type = 'webhook') $payment->setCurrencyCode($order->getBaseCurrencyCode()); $payment->setIsTransactionClosed(true); $payment->registerCaptureNotification($order->getBaseGrandTotal(), true); + $this->orderRepository->save($order); if ($paymentData->settlementAmount !== null) { if ($paymentData->amount->currency != $paymentData->settlementAmount->currency) { @@ -400,7 +401,7 @@ public function processTransaction($orderId, $type = 'webhook') $paymentData->amount->currency . ' ' . $paymentData->amount->value, $paymentData->settlementAmount->currency . ' ' . $paymentData->settlementAmount->value ); - $order->addStatusHistoryComment($message); + $order->addStatusHistoryComment($message)->save(); } } } @@ -408,22 +409,23 @@ public function processTransaction($orderId, $type = 'webhook') $invoice = $payment->getCreatedInvoice(); $sendInvoice = $this->mollieHelper->sendInvoice($storeId); - if ($order->getIsVirtual()) { - $status = $order->getStatus(); - } else { - $status = $this->mollieHelper->getStatusProcessing($storeId); - } - if (!$order->getEmailSent()) { $this->orderSender->send($order); $message = __('New order email sent'); - $order->addStatusToHistory($status, $message, true)->save(); + $order->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save(); } if ($invoice && !$invoice->getEmailSent() && $sendInvoice) { $this->invoiceSender->send($invoice); $message = __('Notified customer about invoice #%1', $invoice->getIncrementId()); - $order->addStatusToHistory($status, $message, true)->save(); + $order->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save(); + } + + if (!$order->getIsVirtual()) { + $defaultStatusProcessing = $this->mollieHelper->getStatusProcessing($storeId); + if ($defaultStatusProcessing && ($defaultStatusProcessing != $order->getStatus())) { + $order->setStatus($defaultStatusProcessing)->save(); + } } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 530b468d7aa..fefbf68be19 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -91,7 +91,7 @@ - Magento\Sales\Model\Config\Source\Order\Status\Processing + Mollie\Payment\Model\Adminhtml\Source\Processing payment/mollie_general/order_status_processing From d0d33b9a3ae5ad3d46570b67468ce2be94e23419 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Wed, 6 Jun 2018 09:16:18 +0200 Subject: [PATCH 3/5] Cancel orders with expired transactions --- Model/Mollie.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Model/Mollie.php b/Model/Mollie.php index 543b477e2bb..1f196fb71a8 100644 --- a/Model/Mollie.php +++ b/Model/Mollie.php @@ -459,20 +459,11 @@ public function processTransaction($orderId, $type = 'webhook') return $msg; } - if ($status == 'canceled') { + if ($status == 'canceled' || $status == 'failed' || $status == 'expired') { if ($type == 'webhook') { $this->cancelOrder($order, $status); } - $msg = ['success' => false, 'status' => 'cancel', 'order_id' => $orderId, 'type' => $type]; - $this->mollieHelper->addTolog('success', $msg); - return $msg; - } - - if ($status == 'failed') { - if ($type == 'webhook') { - $this->cancelOrder($order, $status); - } - $msg = ['success' => false, 'status' => 'failed', 'order_id' => $orderId, 'type' => $type]; + $msg = ['success' => false, 'status' => $status, 'order_id' => $orderId, 'type' => $type]; $this->mollieHelper->addTolog('success', $msg); return $msg; } @@ -490,10 +481,13 @@ public function processTransaction($orderId, $type = 'webhook') * @throws \Exception * @throws \Magento\Framework\Exception\LocalizedException */ - protected function cancelOrder($order, $status) + protected function cancelOrder($order, $status = null) { if ($order->getId() && $order->getState() != Order::STATE_CANCELED) { - $comment = __("The order was %1", $status); + $comment = __('The order was canceled'); + if ($status !== null) { + $comment = __('The order was canceled, reason: payment %1', $status); + } $this->mollieHelper->addTolog('info', $order->getIncrementId() . ' ' . $comment); $order->registerCancellation($comment)->save(); From b39190e65c430fa3c3c2734bd99355a9739f1990 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Wed, 6 Jun 2018 11:56:25 +0200 Subject: [PATCH 4/5] Option to show transaction details in order view --- Block/Info/Base.php | 76 ++++++++++++++++++++++++++++++++++ Helper/General.php | 9 ++++ Model/Methods/Bancontact.php | 7 ++++ Model/Methods/Banktransfer.php | 7 ++++ Model/Methods/Belfius.php | 7 ++++ Model/Methods/Bitcoin.php | 7 ++++ Model/Methods/Creditcard.php | 8 ++++ Model/Methods/Giftcard.php | 7 ++++ Model/Methods/Ideal.php | 7 ++++ Model/Methods/Inghomepay.php | 7 ++++ Model/Methods/Kbc.php | 7 ++++ Model/Methods/Paypal.php | 7 ++++ Model/Methods/Paysafecard.php | 7 ++++ Model/Methods/Sofort.php | 7 ++++ Model/Mollie.php | 4 ++ etc/adminhtml/system.xml | 7 ++++ 16 files changed, 181 insertions(+) create mode 100644 Block/Info/Base.php diff --git a/Block/Info/Base.php b/Block/Info/Base.php new file mode 100644 index 00000000000..6190d3bce5f --- /dev/null +++ b/Block/Info/Base.php @@ -0,0 +1,76 @@ +mollieHelper = $mollieHelper; + } + + /** + * @param null $transport + * + * @return $this|\Magento\Framework\DataObject + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function _prepareSpecificInformation($transport = null) + { + if ($this->_paymentSpecificInformation !== null) { + return $this->_paymentSpecificInformation; + } + + $transport = parent::_prepareSpecificInformation($transport); + + if ($this->_appState->getAreaCode() !== \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { + return $transport; + } + + $showTransactionDetails = $this->mollieHelper->showTransactionDetails(); + if (!$showTransactionDetails) { + return $transport; + } + + $transactionDetails = json_decode($this->getInfo()->getAdditionalInformation('details'), true); + if (!$transactionDetails) { + return $transport; + } + + $data = []; + foreach ($transactionDetails as $k => $v) { + if ($v !== null && !is_array($v)) { + $label = ucwords(trim(preg_replace('/(?=[A-Z])/', " $1", $k))); + $data[(string)__($label)] = $v; + } + } + + return $transport->setData(array_merge($data, $transport->getData())); + } + +} \ No newline at end of file diff --git a/Helper/General.php b/Helper/General.php index 78e612ab4b1..1dd3581dce7 100644 --- a/Helper/General.php +++ b/Helper/General.php @@ -42,6 +42,7 @@ class General extends AbstractHelper const XML_PATH_LOCALE = 'payment/mollie_general/locale'; const XML_PATH_IMAGES = 'payment/mollie_general/payment_images'; const XML_PATH_USE_BASE_CURRENCY = 'payment/mollie_general/currency'; + const XML_PATH_SHOW_TRANSACTION_DETAILS = 'payment/mollie_general/transaction_details'; /** * @var ProductMetadataInterface @@ -239,6 +240,14 @@ public function useImage($storeId = null) return $this->getStoreConfig(self::XML_PATH_IMAGES, $storeId); } + /** + * @return mixed + */ + public function showTransactionDetails() + { + return $this->getStoreConfig(self::XML_PATH_SHOW_TRANSACTION_DETAILS); + } + /** * Disable extension function. * Used when Mollie API is not installed diff --git a/Model/Methods/Bancontact.php b/Model/Methods/Bancontact.php index 347d148f634..a0d3c19052e 100644 --- a/Model/Methods/Bancontact.php +++ b/Model/Methods/Bancontact.php @@ -23,4 +23,11 @@ class Bancontact extends Mollie */ protected $_code = 'mollie_methods_bancontact'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Banktransfer.php b/Model/Methods/Banktransfer.php index 0a05702957c..492f44f05bc 100644 --- a/Model/Methods/Banktransfer.php +++ b/Model/Methods/Banktransfer.php @@ -23,4 +23,11 @@ class Banktransfer extends Mollie */ protected $_code = 'mollie_methods_banktransfer'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Belfius.php b/Model/Methods/Belfius.php index 06c53e188b3..2d0ca2e8a5f 100644 --- a/Model/Methods/Belfius.php +++ b/Model/Methods/Belfius.php @@ -23,4 +23,11 @@ class Belfius extends Mollie */ protected $_code = 'mollie_methods_belfius'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Bitcoin.php b/Model/Methods/Bitcoin.php index 318649e5451..a51ae5eb51d 100644 --- a/Model/Methods/Bitcoin.php +++ b/Model/Methods/Bitcoin.php @@ -22,4 +22,11 @@ class Bitcoin extends Mollie */ protected $_code = 'mollie_methods_bitcoin'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Creditcard.php b/Model/Methods/Creditcard.php index 502bb8c4c09..00fdd718189 100644 --- a/Model/Methods/Creditcard.php +++ b/Model/Methods/Creditcard.php @@ -15,6 +15,7 @@ */ class Creditcard extends Mollie { + /** * Payment method code * @@ -22,4 +23,11 @@ class Creditcard extends Mollie */ protected $_code = 'mollie_methods_creditcard'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Giftcard.php b/Model/Methods/Giftcard.php index 372d3f964dc..2001a7e9c98 100644 --- a/Model/Methods/Giftcard.php +++ b/Model/Methods/Giftcard.php @@ -23,6 +23,13 @@ class Giftcard extends Mollie */ protected $_code = 'mollie_methods_giftcard'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + /** * Disable refund for Giftcard * diff --git a/Model/Methods/Ideal.php b/Model/Methods/Ideal.php index 98fcb42505c..22de600506f 100644 --- a/Model/Methods/Ideal.php +++ b/Model/Methods/Ideal.php @@ -23,4 +23,11 @@ class Ideal extends Mollie */ protected $_code = 'mollie_methods_ideal'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Inghomepay.php b/Model/Methods/Inghomepay.php index ef214233116..ad3f1bb791d 100644 --- a/Model/Methods/Inghomepay.php +++ b/Model/Methods/Inghomepay.php @@ -23,4 +23,11 @@ class Inghomepay extends Mollie */ protected $_code = 'mollie_methods_inghomepay'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Kbc.php b/Model/Methods/Kbc.php index 09df27eb83c..be965bfbd53 100644 --- a/Model/Methods/Kbc.php +++ b/Model/Methods/Kbc.php @@ -23,4 +23,11 @@ class Kbc extends Mollie */ protected $_code = 'mollie_methods_kbc'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Paypal.php b/Model/Methods/Paypal.php index 33cfa3e4aa1..330696b3d86 100644 --- a/Model/Methods/Paypal.php +++ b/Model/Methods/Paypal.php @@ -23,4 +23,11 @@ class Paypal extends Mollie */ protected $_code = 'mollie_methods_paypal'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Paysafecard.php b/Model/Methods/Paysafecard.php index df65bdc6eb6..3663f7e6b5b 100644 --- a/Model/Methods/Paysafecard.php +++ b/Model/Methods/Paysafecard.php @@ -23,4 +23,11 @@ class Paysafecard extends Mollie */ protected $_code = 'mollie_methods_paysafecard'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Methods/Sofort.php b/Model/Methods/Sofort.php index 2b618107c4b..66456b31c88 100644 --- a/Model/Methods/Sofort.php +++ b/Model/Methods/Sofort.php @@ -23,4 +23,11 @@ class Sofort extends Mollie */ protected $_code = 'mollie_methods_sofort'; + /** + * Info instructions block path + * + * @var string + */ + protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base'; + } diff --git a/Model/Mollie.php b/Model/Mollie.php index 1f196fb71a8..5d585b6a8a2 100644 --- a/Model/Mollie.php +++ b/Model/Mollie.php @@ -385,6 +385,10 @@ public function processTransaction($orderId, $type = 'webhook') } $payment = $order->getPayment(); + if ($paymentData->details !== null) { + $payment->setAdditionalInformation('details', json_encode($paymentData->details)); + } + if (!$payment->getIsTransactionClosed() && $type == 'webhook') { if (abs($amount - $orderAmount['value']) < 0.01) { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index fefbf68be19..b7dab0c7adf 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -116,6 +116,13 @@ payment/mollie_general/currency Force use of base currency for the payment request. Is set to no the selected currency of the storeview will be used for request. + + + Magento\Config\Model\Config\Source\Yesno + payment/mollie_general/transaction_details + Display Transaction Details like e.g. IBAN, BIC, Paypal Reference, Card Holder etc. + From e52d70d3b8183e225d058cebe07db728fe0922b0 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Wed, 6 Jun 2018 13:03:23 +0200 Subject: [PATCH 5/5] Version bump --- Model/MollieConfigProvider.php | 2 +- composer.json | 2 +- etc/module.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/MollieConfigProvider.php b/Model/MollieConfigProvider.php index 781372a4e52..a044ffb4ba8 100644 --- a/Model/MollieConfigProvider.php +++ b/Model/MollieConfigProvider.php @@ -141,7 +141,7 @@ public function getConfig() foreach ($this->methodCodes as $code) { - if ($this->methods[$code]->isAvailable()) { + if (!empty($this->methods[$code]) && $this->methods[$code]->isAvailable()) { if (!empty($activeMethods[$code])) { $config['payment']['isActive'][$code] = true; $config['payment']['instructions'][$code] = $this->getInstructions($code); diff --git a/composer.json b/composer.json index 3dee3a23930..a31932eace9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/magento2", "description": "Mollie Payment Module for Magento 2", - "version": "1.3.2", + "version": "1.3.3", "require": { "php": "~5.6.5|7.0.2|7.0.4|~7.0.6|~7.1.0", "mollie/mollie-api-php": "^2.0" diff --git a/etc/module.xml b/etc/module.xml index 42b53d62d13..c68729c7f89 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - +