Skip to content

Commit

Permalink
Merge pull request #62 from mollie/1.3.3
Browse files Browse the repository at this point in the history
1.3.3 - Combined update
  • Loading branch information
Marvin-Magmodules authored Jun 6, 2018
2 parents 516bc08 + e52d70d commit 3a6f960
Show file tree
Hide file tree
Showing 20 changed files with 251 additions and 31 deletions.
76 changes: 76 additions & 0 deletions Block/Info/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Block\Info;

use Magento\Payment\Block\Info;
use Magento\Framework\View\Element\Template\Context;
use Mollie\Payment\Helper\General as MollieHelper;

class Base extends Info
{

/**
* @var MollieHelper
*/
private $mollieHelper;

/**
* Info constructor.
*
* @param MollieHelper $mollieHelper
* @param Context $context
* @param array $data
*/
public function __construct(
MollieHelper $mollieHelper,
Context $context,
$data = []
) {
parent::__construct($context, $data);
$this->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()));
}

}
9 changes: 9 additions & 0 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions Model/Adminhtml/Source/Processing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Adminhtml\Source;

use Magento\Sales\Model\Config\Source\Order\Status;

/**
* Class Pending
*
* @package Mollie\Payment\Model\Adminhtml\Source
*/
class Processing extends Status
{

/**
* @var string
*/
protected $_stateStatuses = \Magento\Sales\Model\Order::STATE_PROCESSING;

/**
* @return array
*/
public function toOptionArray()
{
$statuses = $this->_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;
}
}
7 changes: 7 additions & 0 deletions Model/Methods/Bancontact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Banktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Belfius.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
8 changes: 8 additions & 0 deletions Model/Methods/Creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
*/
class Creditcard extends Mollie
{

/**
* Payment method code
*
* @var string
*/
protected $_code = 'mollie_methods_creditcard';

/**
* Info instructions block path
*
* @var string
*/
protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base';

}
7 changes: 7 additions & 0 deletions Model/Methods/Giftcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions Model/Methods/Ideal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Inghomepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Kbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Paysafecard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
7 changes: 7 additions & 0 deletions Model/Methods/Sofort.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}
58 changes: 31 additions & 27 deletions Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,41 +385,51 @@ 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) {
$payment->setTransactionId($transactionId);
$payment->setCurrencyCode($order->getBaseCurrencyCode());
$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();
$this->orderRepository->save($order);

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)->save();
}
}
}

$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();
}
}
}

Expand Down Expand Up @@ -453,20 +463,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;
}
Expand All @@ -484,10 +485,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();

Expand Down
Loading

0 comments on commit 3a6f960

Please sign in to comment.