Skip to content

Commit

Permalink
Merge pull request #91 from mollie/1.4.0b
Browse files Browse the repository at this point in the history
1.4.0 - Klarna support, Payment Link & Order/Shipments API
  • Loading branch information
Marvin-Magmodules authored Nov 9, 2018
2 parents 8342ed9 + 994268b commit ba5d119
Show file tree
Hide file tree
Showing 113 changed files with 3,764 additions and 548 deletions.
14 changes: 11 additions & 3 deletions Block/Adminhtml/System/Config/Form/Apikey/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Mollie\Payment\Helper\General as MollieHelper;

/**
* Class Checker
Expand All @@ -26,18 +27,25 @@ class Checker extends Field
* @var \Magento\Framework\App\RequestInterface
*/
private $request;
/**
* @var MollieHelper
*/
private $mollieHelper;

/**
* Checker constructor.
*
* @param Context $context
* @param array $data
* @param Context $context
* @param MollieHelper $mollieHelper
* @param array $data
*/
public function __construct(
Context $context,
MollieHelper $mollieHelper,
array $data = []
) {
$this->request = $context->getRequest();
$this->mollieHelper = $mollieHelper;
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -81,7 +89,7 @@ public function getButtonHtml()
$button = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')->setData($buttonData);
return $button->toHtml();
} catch (\Exception $e) {
return '';
$this->mollieHelper->addTolog('error', $e->getMessage());
}
}
}
15 changes: 11 additions & 4 deletions Block/Adminhtml/System/Config/Form/Compatibility/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Mollie\Payment\Helper\General as MollieHelper;

/**
* Class Checker
Expand All @@ -26,18 +27,25 @@ class Checker extends Field
* @var \Magento\Framework\App\RequestInterface
*/
private $request;
/**
* @var MollieHelper
*/
private $mollieHelper;

/**
* Checker constructor.
*
* @param Context $context
* @param array $data
* @param Context $context
* @param MollieHelper $mollieHelper
* @param array $data
*/
public function __construct(
Context $context,
MollieHelper $mollieHelper,
array $data = []
) {
$this->request = $context->getRequest();
$this->mollieHelper = $mollieHelper;
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -80,10 +88,9 @@ public function getButtonHtml()
try {
$buttonData = ['id' => 'compatibility_button', 'label' => __('Self Test')];
$button = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')->setData($buttonData);

return $button->toHtml();
} catch (\Exception $e) {
return '';
$this->mollieHelper->addTolog('error', $e->getMessage());
}
}
}
115 changes: 84 additions & 31 deletions Block/Info/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,122 @@

use Magento\Payment\Block\Info;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Stdlib\DateTime;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Methods\Klarnapaylater;
use Mollie\Payment\Model\Methods\Klarnasliceit;

class Base extends Info
{

/**
* @var string
*/
protected $_template = 'Mollie_Payment::info/mollie_base.phtml';
/**
* @var MollieHelper
*/
private $mollieHelper;
/**
* @var TimezoneInterface
*/
private $timezone;

/**
* Info constructor.
* Base constructor.
*
* @param MollieHelper $mollieHelper
* @param Context $context
* @param array $data
* @param Context $context
* @param MollieHelper $mollieHelper
* @param TimezoneInterface $timezone
*/
public function __construct(
MollieHelper $mollieHelper,
Context $context,
$data = []
MollieHelper $mollieHelper,
TimezoneInterface $timezone
) {
parent::__construct($context, $data);
parent::__construct($context);
$this->mollieHelper = $mollieHelper;
$this->timezone = $timezone;
}

/**
* @param null $transport
*
* @return $this|\Magento\Framework\DataObject
* @throws \Magento\Framework\Exception\LocalizedException
* @return string
*/
protected function _prepareSpecificInformation($transport = null)
public function getCheckoutType()
{
if ($this->_paymentSpecificInformation !== null) {
return $this->_paymentSpecificInformation;
try {
$checkoutType = $this->getInfo()->getAdditionalInformation('checkout_type');
return $checkoutType;
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
}
}

$transport = parent::_prepareSpecificInformation($transport);
/**
* @return string
*/
public function getExpiresAt()
{
try {
if ($expiresAt = $this->getInfo()->getAdditionalInformation('expires_at')) {
return $this->timezone->date($expiresAt)->format(DateTime::DATETIME_PHP_FORMAT);
}
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
}
}

if ($this->_appState->getAreaCode() !== \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
return $transport;
/**
* @return string
*/
public function getPaymentLink()
{
if ($checkoutUrl = $this->getCheckoutUrl()) {
return $this->mollieHelper->getPaymentLinkMessage($checkoutUrl);
}
}

$showTransactionDetails = $this->mollieHelper->showTransactionDetails();
if (!$showTransactionDetails) {
return $transport;
/**
* @return string
*/
public function getCheckoutUrl()
{
try {
$checkoutUrl = $this->getInfo()->getAdditionalInformation('checkout_url');
return $checkoutUrl;
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
}
}

$transactionDetails = json_decode($this->getInfo()->getAdditionalInformation('details'), true);
if (!$transactionDetails) {
return $transport;
/**
* @return string
*/
public function getPaymentStatus()
{
try {
$paymentStatus = $this->getInfo()->getAdditionalInformation('payment_status');
return $paymentStatus;
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
}
}

$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 mixed
*/
public function isKlarnaMethod()
{
try {
$code = $this->getInfo()->getMethod();
if ($code == Klarnapaylater::METHOD_CODE || $code == Klarnasliceit::METHOD_CODE) {
return true;
}
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
}

return $transport->setData(array_merge($data, $transport->getData()));
return false;
}

}
}
16 changes: 16 additions & 0 deletions Block/Info/Paymentlink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Block\Info;

class Paymentlink extends Base
{

/**
* @var string
*/
protected $_template = 'Mollie_Payment::info/mollie_paymentlink.phtml';
}
1 change: 0 additions & 1 deletion Block/Loading.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ public function getBackUrl()
{
return $this->mollieHelper->getRestartUrl();
}

}
5 changes: 2 additions & 3 deletions Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function execute()
if ($methodInstance instanceof \Mollie\Payment\Model\Mollie) {
$storeId = $order->getStoreId();
$redirectUrl = $methodInstance->startTransaction($order);
$this->mollieHelper->addTolog('request', $redirectUrl);
if ($this->mollieHelper->useLoadingScreen($storeId)) {
$resultPage = $this->resultPageFactory->create();
$resultPage->getLayout()->initMessages();
Expand All @@ -97,7 +96,7 @@ public function execute()
$this->getResponse()->setRedirect($redirectUrl);
}
} else {
$msg = __('Paymentmethod not found.');
$msg = __('Payment Method not found');
$this->messageManager->addErrorMessage($msg);
$this->mollieHelper->addTolog('error', $msg);
$this->checkoutSession->restoreQuote();
Expand All @@ -110,4 +109,4 @@ public function execute()
$this->_redirect('checkout/cart');
}
}
}
}
11 changes: 5 additions & 6 deletions Controller/Checkout/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ public function __construct(
*/
public function execute()
{
$params = $this->getRequest()->getParams();

if (!isset($params['order_id'])) {
if (!$orderId = $this->getRequest()->getParam('order_id')) {
$this->mollieHelper->addTolog('error', __('Invalid return, missing order id.'));
$this->messageManager->addNoticeMessage(__('Invalid return from Mollie.'));
$this->_redirect('checkout/cart');
return;
}

try {
$status = $this->mollieModel->processTransaction($params['order_id'], 'success');
$paymentToken = $this->getRequest()->getParam('payment_token', null);
$status = $this->mollieModel->processTransaction($orderId, 'success', $paymentToken);
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
$this->messageManager->addExceptionMessage($e, __('There was an error checking the transaction status.'));
Expand All @@ -95,8 +94,8 @@ public function execute()
}
} else {
$this->checkoutSession->restoreQuote();
if (isset($status['status']) && $status['status'] == 'canceled') {
$this->messageManager->addNoticeMessage(__('Payment cancelled, please try again.'));
if (isset($status['status']) && ($status['status'] == 'canceled')) {
$this->messageManager->addNoticeMessage(__('Payment canceled, please try again.'));
} else {
$this->messageManager->addNoticeMessage(__('Something went wrong.'));
}
Expand Down
17 changes: 3 additions & 14 deletions Controller/Checkout/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use Mollie\Payment\Model\Mollie as MollieModel;
use Mollie\Payment\Helper\General as MollieHelper;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Checkout\Model\Session;
Expand All @@ -30,10 +29,6 @@ class Webhook extends Action
* @var ResultFactory
*/
protected $resultFactory;
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var MollieModel
*/
Expand All @@ -48,19 +43,16 @@ class Webhook extends Action
*
* @param Context $context
* @param Session $checkoutSession
* @param PaymentHelper $paymentHelper
* @param MollieModel $mollieModel
* @param MollieHelper $mollieHelper
*/
public function __construct(
Context $context,
Session $checkoutSession,
PaymentHelper $paymentHelper,
MollieModel $mollieModel,
MollieHelper $mollieHelper
) {
$this->checkoutSession = $checkoutSession;
$this->paymentHelper = $paymentHelper;
$this->resultFactory = $context->getResultFactory();
$this->mollieModel = $mollieModel;
$this->mollieHelper = $mollieHelper;
Expand All @@ -72,19 +64,16 @@ public function __construct(
*/
public function execute()
{
$params = $this->getRequest()->getParams();

if (!empty($params['testByMollie'])) {
if ($this->getRequest()->getParam('testByMollie')) {
$result = $this->resultFactory->create(ResultFactory::TYPE_RAW);
$result->setHeader('content-type', 'text/plain');
$result->setContents('OK', true);
return;
}

if (!empty($params['id'])) {
if ($transactionId = $this->getRequest()->getParam('id')) {
try {
$orderId = $this->mollieModel->getOrderIdByTransactionId($params['id']);
if ($orderId) {
if ($orderId = $this->mollieModel->getOrderIdByTransactionId($transactionId)) {
$this->mollieModel->processTransaction($orderId, 'webhook');
}
} catch (\Exception $e) {
Expand Down
Loading

0 comments on commit ba5d119

Please sign in to comment.