Skip to content

Commit a1a5624

Browse files
refactor buckaroo fee
1 parent 13076c0 commit a1a5624

File tree

30 files changed

+963
-1064
lines changed

30 files changed

+963
-1064
lines changed

Block/Adminhtml/Sales/Totals.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,9 @@ public function __construct(
5555
public function initTotals()
5656
{
5757
$parent = $this->getParentBlock();
58-
/**
59-
* @noinspection PhpUndefinedMethodInspection
60-
*/
6158
$source = $parent->getSource();
6259
$totals = $this->getTotalsForCreditmemo($source);
6360
foreach ($totals as $total) {
64-
/**
65-
* @noinspection PhpUndefinedMethodInspection
66-
*/
6761
$this->getParentBlock()->addTotalBefore(new \Magento\Framework\DataObject($total), 'grand_total');
6862
}
6963
return $this;
@@ -72,12 +66,9 @@ public function initTotals()
7266
public function getTotals()
7367
{
7468
$parent = $this->getParentBlock();
75-
/**
76-
* @noinspection PhpUndefinedMethodInspection
77-
*/
7869
$source = $parent->getSource();
7970

80-
71+
8172
return $this->getTotalsForCreditmemo($source);
8273
}
8374

@@ -92,7 +83,7 @@ public function getCurrentCurrencySymbol()
9283
}
9384

9485
/**
95-
* For credit memo display the fees from invoice/order,
86+
* For credit memo display the fees from invoice/order,
9687
* check if invoice has that fee and set selected
9788
*
9889
* @param mixed $source
@@ -107,7 +98,7 @@ protected function getTotalsForCreditmemo($source)
10798
$invoice = $source->getInvoice();
10899
$salesModel = ($invoice != null? $invoice : $order);
109100
$saleTotals = $this->helper->getTotals($salesModel);
110-
101+
111102
$saleTotals = array_map(function($saleTotal) use($creditTotals) {
112103
if (in_array($saleTotal['code'],['buckaroo_fee', 'buckaroo_fee_excl'] )) {
113104
$saleTotal['block_name'] = "buckaroo_fee";
@@ -116,12 +107,12 @@ protected function getTotalsForCreditmemo($source)
116107
return $saleTotal;
117108
}, $saleTotals);
118109

119-
110+
120111
return array_merge(
121112
$this->getTotalsByCode($creditTotals, 'buckaroo_already_paid'),
122113
$this->getTotalsExceptCode($saleTotals, 'buckaroo_already_paid')
123114
);
124-
115+
125116
}
126117
return $this->helper->getTotals($source);
127118
}

Block/Cart/BuckarooConfig.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,58 @@
11
<?php
22
/**
3-
* Copyright © 2015 Magento. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* NOTICE OF LICENSE
4+
*
5+
* This source file is subject to the MIT License
6+
* It is available through the world-wide-web at this URL:
7+
* https://tldrlegal.com/license/mit-license
8+
* If you are unable to obtain it through the world-wide-web, please send an email
9+
* to support@buckaroo.nl so we can send you a copy immediately.
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this module to newer
14+
* versions in the future. If you wish to customize this module for your
15+
* needs please contact support@buckaroo.nl for more information.
16+
*
17+
* @copyright Copyright (c) Buckaroo B.V.
18+
* @license https://tldrlegal.com/license/mit-license
519
*/
20+
621
namespace Buckaroo\Magento2\Block\Cart;
722

8-
class BuckarooConfig extends \Magento\Backend\Block\Template
23+
use Buckaroo\Magento2\Exception;
24+
use Buckaroo\Magento2\Model\ConfigProvider\Factory;
25+
use Magento\Backend\Block\Template;
26+
use Magento\Backend\Block\Template\Context;
27+
use Magento\Framework\Serialize\Serializer\Json;
28+
29+
class BuckarooConfig extends Template
930
{
1031
/**
1132
* @var bool
1233
*/
1334
protected $_isScopePrivate = false;
1435

1536
/**
16-
* @var \Buckaroo\Magento2\Model\ConfigProvider\Factory
37+
* @var Factory
1738
*/
1839
protected $configProviderFactory;
1940

2041
/**
21-
* @var \Magento\Framework\Json\Encoder
42+
* @var Json
2243
*/
2344
protected $jsonEncoder;
2445

2546
/**
26-
* @param \Magento\Backend\Block\Template\Context $context
27-
* @param \Magento\Framework\Json\Encoder $jsonEncoder
28-
* @param \Buckaroo\Magento2\Model\ConfigProvider\Factory $configProviderFactory
29-
* @param array $data
47+
* @param Context $context
48+
* @param Json $jsonEncoder
49+
* @param Factory $configProviderFactory
50+
* @param array $data
3051
*/
3152
public function __construct(
32-
\Magento\Backend\Block\Template\Context $context,
33-
\Magento\Framework\Json\Encoder $jsonEncoder,
34-
\Buckaroo\Magento2\Model\ConfigProvider\Factory $configProviderFactory,
53+
Context $context,
54+
Json $jsonEncoder,
55+
Factory $configProviderFactory,
3556
array $data = []
3657
) {
3758
parent::__construct($context, $data);
@@ -42,11 +63,12 @@ public function __construct(
4263
/**
4364
* Retrieve buckaroo configuration
4465
*
45-
* @return array
66+
* @return string
67+
* @throws Exception
4668
*/
4769
public function getBuckarooConfigJson()
4870
{
4971
$configProvider = $this->configProviderFactory->get('buckaroo_fee');
50-
return $this->jsonEncoder->encode($configProvider->getConfig());
72+
return $this->jsonEncoder->serialize($configProvider->getConfig());
5173
}
5274
}

Helper/Data.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ public function getOriginalTransactionKey($orderId)
261261
return $this->groupTransaction->getGroupTransactionOriginalTransactionKey($orderId);
262262
}
263263

264+
public function getAlreadyPaid()
265+
{
266+
return $this->groupTransaction->getAlreadyPaid($this->getOrderId());
267+
}
268+
264269
public function getOrderId()
265270
{
266271
$orderId = $this->_checkoutSession->getQuote()->getReservedOrderId();

0 commit comments

Comments
 (0)