Skip to content

Commit f047b67

Browse files
Merge branch 'feature/payment-fee' into 1.8.0
2 parents 69c0aad + 5110bc3 commit f047b67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1884
-22
lines changed

Block/PaymentFee/Sales/Creditmemo.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright Magmodules.eu. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Mollie\Payment\Block\PaymentFee\Sales;
8+
9+
use Magento\Framework\DataObject;
10+
use Magento\Framework\View\Element\Template;
11+
use Magento\Sales\Block\Adminhtml\Order\Creditmemo\Totals;
12+
13+
class Creditmemo extends Template
14+
{
15+
public function initTotals()
16+
{
17+
/** @var Totals $parentBlock */
18+
$parentBlock = $this->getParentBlock();
19+
$creditmemo = $parentBlock->getCreditmemo();
20+
21+
if (!(int)$creditmemo->getBaseMolliePaymentFee()) {
22+
return;
23+
}
24+
25+
$total = new DataObject([
26+
'code' => 'mollie_payment_fee',
27+
'value' => $creditmemo->getMolliePaymentFee() + $creditmemo->getMolliePaymentFeeTax(),
28+
'label' => __('Payment Fee'),
29+
]);
30+
31+
$parentBlock->addTotalBefore($total, 'tax');
32+
}
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright Magmodules.eu. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Mollie\Payment\Block\PaymentFee\Sales;
8+
9+
use Magento\Framework\DataObject;
10+
use Magento\Framework\View\Element\Template;
11+
use Magento\Sales\Block\Adminhtml\Order\Creditmemo\Totals;
12+
use Mollie\Payment\Service\Order\Creditmemo as CreditmemoService;
13+
14+
class CreditmemoNew extends Template
15+
{
16+
/**
17+
* @var CreditmemoService
18+
*/
19+
private $creditmemoService;
20+
21+
public function __construct(
22+
Template\Context $context,
23+
CreditmemoService $creditmemoService,
24+
array $data = []
25+
) {
26+
parent::__construct($context, $data);
27+
28+
$this->creditmemoService = $creditmemoService;
29+
}
30+
31+
public function initTotals()
32+
{
33+
/** @var Totals $parentBlock */
34+
$parentBlock = $this->getParentBlock();
35+
$order = $parentBlock->getOrder();
36+
$creditmemo = $parentBlock->getCreditmemo();
37+
38+
if (!($order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax())) {
39+
return;
40+
}
41+
42+
if (!$this->creditmemoService->isFullOrLastPartialCreditmemo($creditmemo)) {
43+
return;
44+
}
45+
46+
$total = new DataObject([
47+
'code' => 'mollie_payment_fee',
48+
'value' => $order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax(),
49+
'label' => __('Payment Fee'),
50+
]);
51+
52+
$parentBlock->addTotalBefore($total, 'tax');
53+
}
54+
}

Block/PaymentFee/Sales/Order.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright Magmodules.eu. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Mollie\Payment\Block\PaymentFee\Sales;
8+
9+
use Magento\Framework\DataObject;
10+
use Magento\Framework\View\Element\Template;
11+
use Magento\Sales\Block\Adminhtml\Order\Totals;
12+
13+
class Order extends Template
14+
{
15+
public function initTotals()
16+
{
17+
/** @var Totals $parentBlock */
18+
$parentBlock = $this->getParentBlock();
19+
$order = $parentBlock->getOrder();
20+
21+
if (!($order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax())) {
22+
return;
23+
}
24+
25+
$total = new DataObject([
26+
'code' => 'mollie_payment_fee',
27+
'value' => $order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax(),
28+
'label' => __('Payment Fee'),
29+
]);
30+
31+
$parentBlock->addTotalBefore($total, 'tax');
32+
}
33+
}

Config.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
/**
3+
* Copyright Magmodules.eu. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
26

37
namespace Mollie\Payment;
48

@@ -9,6 +13,10 @@ class Config
913
{
1014
const XML_PATH_STATUS_PENDING_BANKTRANSFER = 'payment/mollie_methods_banktransfer/order_status_pending';
1115
const XML_PATH_STATUS_NEW_PAYMENT_LINK = 'payment/mollie_methods_paymentlink/order_status_new';
16+
const PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE = 'payment/mollie_methods_klarnapaylater/payment_surcharge';
17+
const PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE_TAX_CLASS = 'payment/mollie_methods_klarnapaylater/payment_surcharge_tax_class';
18+
const PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE = 'payment/mollie_methods_klarnasliceit/payment_surcharge';
19+
const PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE_TAX_CLASS = 'payment/mollie_methods_klarnasliceit/payment_surcharge_tax_class';
1220

1321
/**
1422
* @var ScopeConfigInterface
@@ -21,6 +29,16 @@ public function __construct(
2129
$this->config = $config;
2230
}
2331

32+
/**
33+
* @param $path
34+
* @param $storeId
35+
* @return string
36+
*/
37+
private function getPath($path, $storeId)
38+
{
39+
return $this->config->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
40+
}
41+
2442
public function statusPendingBanktransfer($storeId = null)
2543
{
2644
return $this->config->getValue(
@@ -38,4 +56,40 @@ public function statusNewPaymentLink($storeId = null)
3856
$storeId
3957
);
4058
}
59+
60+
/**
61+
* @param int|null $storeId
62+
* @return string
63+
*/
64+
public function klarnaPaylaterPaymentSurcharge($storeId = null)
65+
{
66+
return $this->getPath(static::PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE, $storeId);
67+
}
68+
69+
/**
70+
* @param int|null $storeId
71+
* @return string
72+
*/
73+
public function klarnaPaylaterPaymentSurchargeTaxClass($storeId = null)
74+
{
75+
return $this->getPath(static::PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE_TAX_CLASS, $storeId);
76+
}
77+
78+
/**
79+
* @param int|null $storeId
80+
* @return string
81+
*/
82+
public function klarnaSliceitPaymentSurcharge($storeId = null)
83+
{
84+
return $this->getPath(static::PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE, $storeId);
85+
}
86+
87+
/**
88+
* @param int|null $storeId
89+
* @return string
90+
*/
91+
public function klarnaSliceitPaymentSurchargeTaxClass($storeId = null)
92+
{
93+
return $this->getPath(static::PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE_TAX_CLASS, $storeId);
94+
}
4195
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright Magmodules.eu. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Mollie\Payment\Model\Adminhtml\Backend;
8+
9+
use Magento\Framework\App\Cache\TypeListInterface;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\Config\Value;
12+
use Magento\Framework\Data\Collection\AbstractDb;
13+
use Magento\Framework\Exception\ValidatorException;
14+
use Magento\Framework\Model\Context;
15+
use Magento\Framework\Model\ResourceModel\AbstractResource;
16+
use Magento\Framework\Pricing\PriceCurrencyInterface;
17+
use Magento\Framework\Registry;
18+
19+
class VerifiyPaymentFee extends Value
20+
{
21+
const MAXIMUM_PAYMENT_FEE_AMOUNT = 1.95;
22+
23+
/**
24+
* @var PriceCurrencyInterface
25+
*/
26+
private $priceCurrency;
27+
28+
public function __construct(
29+
Context $context,
30+
Registry $registry,
31+
ScopeConfigInterface $config,
32+
TypeListInterface $cacheTypeList,
33+
PriceCurrencyInterface $priceCurrency,
34+
AbstractResource $resource = null,
35+
AbstractDb $resourceCollection = null,
36+
array $data = []
37+
) {
38+
parent::__construct(
39+
$context,
40+
$registry,
41+
$config,
42+
$cacheTypeList,
43+
$resource,
44+
$resourceCollection,
45+
$data
46+
);
47+
48+
$this->priceCurrency = $priceCurrency;
49+
}
50+
51+
public function beforeSave()
52+
{
53+
$value = $this->getValue();
54+
$this->setValue(str_replace(',', '.', $value));
55+
56+
if ((double)$value > static::MAXIMUM_PAYMENT_FEE_AMOUNT) {
57+
$message = __(
58+
'Please make sure the payment surcharge does not exceed %1.',
59+
$this->priceCurrency->format(static::MAXIMUM_PAYMENT_FEE_AMOUNT)
60+
);
61+
62+
throw new ValidatorException($message);
63+
}
64+
}
65+
}

Model/Adminhtml/Source/NewStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2018 Magmodules.eu. All rights reserved.
3+
* Copyright Magmodules.eu. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

Model/Client/Orders.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ public function createShipment(Order\Shipment $shipment, Order $order)
621621
$shipment->setMollieShipmentId($mollieShipmentId);
622622

623623
/**
624-
* Check if Transactions needs to be captures (eg. Klarna methods)
624+
* Check if Transactions needs to be captured (eg. Klarna methods)
625625
*/
626626
$payment = $order->getPayment();
627627
if (!$payment->getIsTransactionClosed()) {
@@ -630,8 +630,9 @@ public function createShipment(Order\Shipment $shipment, Order $order)
630630
$invoice = $this->partialInvoice->createFromShipment($shipment);
631631
}
632632

633-
$captureAmount = $this->getCaptureAmount($order, $invoice);
633+
$captureAmount = $this->getCaptureAmount($order, $invoice->getId() ? $invoice : null);
634634

635+
$payment->setTransactionId($transactionId);
635636
$payment->registerCaptureNotification($captureAmount, true);
636637
$this->orderRepository->save($order);
637638

Model/OrderLines.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Mollie\Payment\Model\ResourceModel\OrderLines\CollectionFactory as OrderLinesCollectionFactory;
1919
use Mollie\Payment\Helper\General as MollieHelper;
2020
use Magento\Framework\Exception\LocalizedException;
21+
use Mollie\Payment\Service\Order\Creditmemo as CreditmemoService;
22+
use Mollie\Payment\Service\Order\Lines\PaymentFee;
2123
use Mollie\Payment\Service\Order\Lines\StoreCredit;
2224

2325
class OrderLines extends AbstractModel
@@ -39,6 +41,14 @@ class OrderLines extends AbstractModel
3941
* @var StoreCredit
4042
*/
4143
private $storeCredit;
44+
/**
45+
* @var PaymentFee
46+
*/
47+
private $paymentFee;
48+
/**
49+
* @var CreditmemoService
50+
*/
51+
private $creditmemoService;
4252

4353
/**
4454
* OrderLines constructor.
@@ -49,6 +59,8 @@ class OrderLines extends AbstractModel
4959
* @param Context $context
5060
* @param Registry $registry
5161
* @param StoreCredit $storeCredit
62+
* @param PaymentFee $paymentFee
63+
* @param CreditmemoService $creditmemoService
5264
* @param AbstractResource|null $resource
5365
* @param AbstractDb|null $resourceCollection
5466
* @param array $data
@@ -60,6 +72,8 @@ public function __construct(
6072
Context $context,
6173
Registry $registry,
6274
StoreCredit $storeCredit,
75+
PaymentFee $paymentFee,
76+
CreditmemoService $creditmemoService,
6377
AbstractResource $resource = null,
6478
AbstractDb $resourceCollection = null,
6579
array $data = []
@@ -68,6 +82,8 @@ public function __construct(
6882
$this->orderLinesFactory = $orderLinesFactory;
6983
$this->orderLinesCollection = $orderLinesCollection;
7084
$this->storeCredit = $storeCredit;
85+
$this->paymentFee = $paymentFee;
86+
$this->creditmemoService = $creditmemoService;
7187
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
7288
}
7389

@@ -187,6 +203,10 @@ public function getOrderLines(Order $order)
187203
$orderLines[] = $this->storeCredit->getOrderLine($order, $forceBaseCurrency);
188204
}
189205

206+
if ($this->paymentFee->orderHasPaymentFee($order)) {
207+
$orderLines[] = $this->paymentFee->getOrderLine($order, $forceBaseCurrency);
208+
}
209+
190210
$this->saveOrderLines($orderLines, $order);
191211
foreach ($orderLines as &$orderLine) {
192212
unset($orderLine['item_id']);
@@ -425,6 +445,11 @@ public function getCreditmemoOrderLines($creditmemo, $addShipping)
425445
$orderLines[] = ['id' => $storeCreditLine->getLineId(), 'quantity' => 1];
426446
}
427447

448+
$paymentFeeCreditLine = $this->getPaymentFeeCreditItemLineOrder($orderId);
449+
if ($paymentFeeCreditLine->getId() && !$this->creditmemoService->hasItemsLeftToRefund($creditmemo)) {
450+
$orderLines[] = ['id' => $paymentFeeCreditLine->getLineId(), 'quantity' => 1];
451+
}
452+
428453
return ['lines' => $orderLines];
429454
}
430455

@@ -458,6 +483,19 @@ public function getStoreCreditItemLineOrder($orderId)
458483
return $storeCreditLine;
459484
}
460485

486+
/**
487+
* @param $orderId
488+
*
489+
* @return OrderLines
490+
*/
491+
public function getPaymentFeeCreditItemLineOrder($orderId)
492+
{
493+
return $this->orderLinesCollection->create()
494+
->addFieldToFilter('order_id', ['eq' => $orderId])
495+
->addFieldToFilter('type', ['eq' => 'surcharge'])
496+
->getLastItem();
497+
}
498+
461499
/**
462500
* @param $orderId
463501
*

0 commit comments

Comments
 (0)