Skip to content

Commit 22c9b9d

Browse files
Merge pull request #94 from buckaroo-it/refactor
Update, Test & Release v2.0.0
2 parents a224cef + d74c55f commit 22c9b9d

23 files changed

Lines changed: 306 additions & 57 deletions

File tree

Block/Totals/Fee.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
class Fee extends \Magento\Framework\View\Element\Template
1212
{
1313
protected PaymentFee $feeHelper;
14+
protected SessionCheckout $sessionCheckout;
1415

1516
public function __construct(
16-
Context $context,
17-
array $data,
18-
PaymentFee $feeHelper,
19-
)
20-
{
17+
Context $context,
18+
array $data,
19+
PaymentFee $feeHelper,
20+
SessionCheckout $sessionCheckout
21+
) {
2122
parent::__construct($context, $data);
2223
$this->feeHelper = $feeHelper;
24+
$this->sessionCheckout = $sessionCheckout;
2325
}
2426

2527
/**
@@ -35,4 +37,21 @@ public function getTitle(): string
3537
return 'Payment Fee';
3638
}
3739
}
40+
41+
/**
42+
* Get segment data for the fee
43+
*
44+
* @return array
45+
*/
46+
public function getSegment(): array
47+
{
48+
$quote = $this->sessionCheckout->getQuote();
49+
$fee = $quote->getBuckarooFee();
50+
51+
return [
52+
'code' => 'buckaroo_fee',
53+
'title' => $this->getTitle(),
54+
'value' => $fee ? (float)$fee : 0
55+
];
56+
}
3857
}

Magewire/Payment/Method/Afterpay20.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ private function getQuote(): ?Quote
251251
} catch (LocalizedException $exception) {
252252
$this->dispatchErrorMessage($exception->getMessage());
253253
}
254+
255+
return null;
254256
}
255257

256258
/**
@@ -452,4 +454,24 @@ public function showPhone(): bool
452454

453455
return $validation->fails();
454456
}
457+
458+
/**
459+
* Show financial warning for Netherlands customers
460+
*
461+
* @return bool
462+
*/
463+
public function showFinancialWarning(): bool
464+
{
465+
$quote = $this->getQuote();
466+
467+
if ($quote === null) {
468+
return false;
469+
}
470+
471+
$billingAddress = $quote->getBillingAddress();
472+
473+
return $billingAddress !== null &&
474+
$billingAddress->getCountryId() === 'NL' &&
475+
$this->methodConfigProvider->canShowFinancialWarning();
476+
}
455477
}

Magewire/Payment/Method/AfterpayBase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ private function getQuote(): ?Quote
281281
} catch (LocalizedException $exception) {
282282
$this->dispatchErrorMessage($exception->getMessage());
283283
}
284+
285+
return null;
284286
}
285287

286288
/**

Magewire/Payment/Method/Applepay.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public function getJsSdkUrl()
124124
} catch (LocalizedException $exception) {
125125
$this->dispatchErrorMessage($exception->getMessage());
126126
}
127+
128+
return '';
127129
}
128130

129131

Magewire/Payment/Method/Billink.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
1818
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultInterface;
1919
use Buckaroo\Magento2\Helper\Data as HelperData;
20+
use Buckaroo\Magento2\Model\ConfigProvider\Method\Billink as MethodConfigProvider;
2021

2122

2223
class Billink extends Component\Form implements EvaluationInterface
@@ -56,11 +57,14 @@ class Billink extends Component\Form implements EvaluationInterface
5657

5758
protected HelperData $helper;
5859

60+
protected MethodConfigProvider $methodConfigProvider;
61+
5962
public function __construct(
6063
Validator $validator,
6164
SessionCheckout $sessionCheckout,
6265
CartRepositoryInterface $quoteRepository,
63-
HelperData $helper
66+
HelperData $helper,
67+
MethodConfigProvider $methodConfigProvider
6468
) {
6569
if($validator->getValidator("nlBeDePhone") === null) {
6670
$validator->addValidator("nlBeDePhone", new NlBeDePhone());
@@ -71,6 +75,7 @@ public function __construct(
7175
$this->sessionCheckout = $sessionCheckout;
7276
$this->quoteRepository = $quoteRepository;
7377
$this->helper = $helper;
78+
$this->methodConfigProvider = $methodConfigProvider;
7479
}
7580

7681
/**
@@ -255,6 +260,8 @@ private function getQuote(): ?Quote
255260
} catch (LocalizedException $exception) {
256261
$this->dispatchErrorMessage($exception->getMessage());
257262
}
263+
264+
return null;
258265
}
259266

260267
/**
@@ -410,4 +417,34 @@ function($gender) {
410417

411418
return ["required", "in:".implode(",", $genderValues)];
412419
}
420+
421+
/**
422+
* Show financial warning for Netherlands customers
423+
*
424+
* @return bool
425+
*/
426+
public function showFinancialWarning(): bool
427+
{
428+
$quote = $this->getQuote();
429+
430+
if ($quote === null) {
431+
return false;
432+
}
433+
434+
$billingAddress = $quote->getBillingAddress();
435+
436+
return $billingAddress !== null &&
437+
$billingAddress->getCountryId() === 'NL' &&
438+
$this->methodConfigProvider->canShowFinancialWarning();
439+
}
440+
441+
/**
442+
* Get payment method title
443+
*
444+
* @return string
445+
*/
446+
public function getPaymentMethodTitle(): string
447+
{
448+
return $this->methodConfigProvider->getTitle();
449+
}
413450
}

Magewire/Payment/Method/Creditcard.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Hyva\Checkout\Model\Magewire\Component\EvaluationInterface;
1515
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
1616
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultInterface;
17-
use Buckaroo\Magento2\Model\ConfigProvider\Method\Ideal as MethodIdeal;
1817
use Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard as MethodConfigProvider;
1918

2019
class Creditcard extends Component\Form implements EvaluationInterface
@@ -106,9 +105,9 @@ public function getIssuers(): array
106105
public function displayAsSelect($storeId = null): bool
107106
{
108107
return $this->scopeConfig->getValue(
109-
MethodIdeal::XPATH_IDEAL_SELECTION_TYPE,
110-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
111-
$storeId
112-
) === '2';
108+
MethodConfigProvider::XPATH_SELECTION_TYPE,
109+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
110+
$storeId
111+
) === '2';
113112
}
114113
}

Magewire/Payment/Method/In3.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Hyva\Checkout\Model\Magewire\Component\EvaluationInterface;
1717
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
1818
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultInterface;
19+
use Buckaroo\Magento2\Model\ConfigProvider\Method\CapayableIn3 as MethodConfigProvider;
1920

2021
class In3 extends Component\Form implements EvaluationInterface
2122
{
@@ -40,11 +41,13 @@ class In3 extends Component\Form implements EvaluationInterface
4041

4142
protected ScopeConfigInterface $scopeConfig;
4243

44+
protected MethodConfigProvider $methodConfigProvider;
4345

4446
public function __construct(
4547
Validator $validator,
4648
SessionCheckout $sessionCheckout,
47-
CartRepositoryInterface $quoteRepository
49+
CartRepositoryInterface $quoteRepository,
50+
MethodConfigProvider $methodConfigProvider
4851
) {
4952
if($validator->getValidator("nlBeDePhone") === null) {
5053
$validator->addValidator("nlBeDePhone", new NlBeDePhone());
@@ -54,6 +57,7 @@ public function __construct(
5457

5558
$this->sessionCheckout = $sessionCheckout;
5659
$this->quoteRepository = $quoteRepository;
60+
$this->methodConfigProvider = $methodConfigProvider;
5761
}
5862

5963
/**
@@ -99,7 +103,7 @@ private function validateField(
99103

100104
$this->validateOnly([$name => $rules], $messageArray, [$name => $value]);
101105
}
102-
106+
103107
public function updatedPhone(string $value): ?string
104108
{
105109
$this->validateField('phone', $this->getPhoneRules(), $value);
@@ -194,6 +198,8 @@ private function getQuote(): ?Quote
194198
} catch (LocalizedException $exception) {
195199
$this->dispatchErrorMessage($exception->getMessage());
196200
}
201+
202+
return null;
197203
}
198204

199205
/**
@@ -281,4 +287,34 @@ public function showPhone(): bool
281287

282288
return $validation->fails();
283289
}
290+
291+
/**
292+
* Show financial warning for Netherlands customers
293+
*
294+
* @return bool
295+
*/
296+
public function showFinancialWarning(): bool
297+
{
298+
$quote = $this->getQuote();
299+
300+
if ($quote === null) {
301+
return false;
302+
}
303+
304+
$billingAddress = $quote->getBillingAddress();
305+
306+
return $billingAddress !== null &&
307+
$billingAddress->getCountryId() === 'NL' &&
308+
$this->methodConfigProvider->canShowFinancialWarning();
309+
}
310+
311+
/**
312+
* Get payment method title
313+
*
314+
* @return string
315+
*/
316+
public function getPaymentMethodTitle(): string
317+
{
318+
return $this->methodConfigProvider->getTitle();
319+
}
284320
}

Magewire/Payment/Method/Klarna.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Hyva\Checkout\Model\Magewire\Component\EvaluationInterface;
1414
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
1515
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultInterface;
16+
use Buckaroo\Magento2\Model\ConfigProvider\Method\Klarna as MethodConfigProvider;
1617

1718
class Klarna extends Component\Form implements EvaluationInterface
1819
{
@@ -34,15 +35,19 @@ class Klarna extends Component\Form implements EvaluationInterface
3435

3536
protected CartRepositoryInterface $quoteRepository;
3637

38+
protected MethodConfigProvider $methodConfigProvider;
39+
3740
public function __construct(
3841
Validator $validator,
3942
SessionCheckout $sessionCheckout,
40-
CartRepositoryInterface $quoteRepository
43+
CartRepositoryInterface $quoteRepository,
44+
MethodConfigProvider $methodConfigProvider
4145
) {
4246
parent::__construct($validator);
4347

4448
$this->sessionCheckout = $sessionCheckout;
4549
$this->quoteRepository = $quoteRepository;
50+
$this->methodConfigProvider = $methodConfigProvider;
4651
}
4752

4853
/**
@@ -92,4 +97,48 @@ public function getGenderList(): array
9297
['code' => 'female', 'name' => __('She/her')]
9398
];
9499
}
100+
101+
/**
102+
* Get payment method title
103+
*
104+
* @return string
105+
*/
106+
public function getPaymentMethodTitle(): string
107+
{
108+
return $this->methodConfigProvider->getTitle() ?: 'Klarna: Pay later';
109+
}
110+
111+
/**
112+
* Show financial warning for Netherlands customers
113+
*
114+
* @return bool
115+
*/
116+
public function showFinancialWarning(): bool
117+
{
118+
$quote = $this->getQuote();
119+
120+
if ($quote === null) {
121+
return false;
122+
}
123+
124+
$billingAddress = $quote->getBillingAddress();
125+
126+
return $billingAddress !== null &&
127+
$billingAddress->getCountryId() === 'NL' &&
128+
$this->methodConfigProvider->canShowFinancialWarning();
129+
}
130+
131+
/**
132+
* Get quote from session
133+
*
134+
* @return \Magento\Quote\Model\Quote|null
135+
*/
136+
private function getQuote(): ?\Magento\Quote\Model\Quote
137+
{
138+
try {
139+
return $this->sessionCheckout->getQuote();
140+
} catch (LocalizedException $e) {
141+
return null;
142+
}
143+
}
95144
}

Magewire/Payment/Method/PayByBank.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function getImageUrl(string $issuerImage): string
176176
public function displayAsSelect($storeId = null): bool
177177
{
178178
return $this->scopeConfig->getValue(
179-
MethodPayByBank::XPATH_PAYBYBANK_SELECTION_TYPE,
179+
MethodPayByBank::XPATH_ACCOUNT_SELECTION_TYPE,
180180
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
181181
$storeId
182182
) === '2';

Magewire/Payment/Method/SepaDirect.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ private function getQuote(): ?Quote
184184
} catch (LocalizedException $exception) {
185185
$this->dispatchErrorMessage($exception->getMessage());
186186
}
187+
188+
return null;
187189
}
188190

189191
/**

0 commit comments

Comments
 (0)