Skip to content

Commit 00a5e75

Browse files
PT-3034: Add Pay Now payment method. Version bump (#118)
1 parent fc8a122 commit 00a5e75

File tree

16 files changed

+153
-20
lines changed

16 files changed

+153
-20
lines changed

Helpers/Logger/Handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
namespace Mondu\Mondu\Helpers\Logger;
66

77
use Magento\Framework\Logger\Handler\Base;
8-
use Monolog\Level;
8+
use Monolog\Logger;
99

1010
class Handler extends Base
1111
{
1212
/**
1313
* @var int
1414
*/
15-
protected $loggerType = Level::Info;
15+
protected $loggerType = Logger::INFO;
1616

1717
/**
1818
* @var string

Helpers/Logger/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
* @param array $context
3838
* @return void
3939
*/
40-
public function info(string|Stringable $message, array $context = []): void
40+
public function info($message, array $context = []): void
4141
{
4242
if (!$this->monduConfig->isDebugModeEnabled()) {
4343
return;

Helpers/PaymentMethod.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ class PaymentMethod
1515
public const DIRECT_DEBIT = 'direct_debit';
1616
public const INSTALLMENT = 'installment';
1717
public const INSTALLMENT_BY_INVOICE = 'installment_by_invoice';
18+
public const PAY_NOW = 'pay_now';
1819

19-
public const PAYMENTS = ['mondu', 'mondusepa', 'monduinstallment', 'monduinstallmentbyinvoice'];
20+
public const PAYMENTS = ['mondu', 'mondusepa', 'monduinstallment', 'monduinstallmentbyinvoice', 'mondupaynow'];
2021

2122
public const LABELS = [
2223
'mondu' => 'Rechnungskauf',
2324
'mondusepa' => 'SEPA Direct Debit',
2425
'monduinstallment' => 'Installment',
2526
'monduinstallmentbyinvoice' => 'Installment By Invoice',
27+
'mondupaynow' => 'Pay Now',
2628
];
2729

2830
public const MAPPING = [
2931
'invoice' => 'mondu',
3032
self::DIRECT_DEBIT => 'mondusepa',
3133
self::INSTALLMENT => 'monduinstallment',
3234
self::INSTALLMENT_BY_INVOICE => 'monduinstallmentbyinvoice',
35+
self::PAY_NOW => 'mondupaynow',
3336
];
3437
private const CACHE_KEY_PREFIX = 'mondu_payment_methods_';
3538
private const CACHE_LIFETIME = 3600;

Model/Payment/MonduPayNow.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Mondu\Mondu\Model\Payment;
6+
7+
use Magento\Payment\Model\InfoInterface;
8+
use Magento\Payment\Model\Method\AbstractMethod;
9+
use Magento\Store\Model\ScopeInterface;
10+
11+
class MonduPayNow extends AbstractMethod
12+
{
13+
public const PAYMENT_METHOD_MONDU_CODE = 'mondupaynow';
14+
15+
/**
16+
* @var string
17+
*/
18+
protected $_code = 'mondupaynow';
19+
20+
/**
21+
* Authorize.
22+
*
23+
* @param InfoInterface $payment
24+
* @param float $amount
25+
* @return $this|MonduPayNow
26+
*/
27+
public function authorize(InfoInterface $payment, $amount)
28+
{
29+
return $this;
30+
}
31+
32+
/**
33+
* SetCode.
34+
*
35+
* @param string $code
36+
* @return $this
37+
*/
38+
public function setCode($code)
39+
{
40+
$this->_code = $code;
41+
return $this;
42+
}
43+
44+
/**
45+
* CanUseForCountry.
46+
*
47+
* @param string $country
48+
* @return bool
49+
*/
50+
public function canUseForCountry($country)
51+
{
52+
$storeId = $this->getStore();
53+
54+
$path = 'payment/' . 'mondu' . '/' . 'specificcountry';
55+
$availableCountries = $this->_scopeConfig
56+
->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
57+
$allowSpecific = $this->_scopeConfig
58+
->getValue('payment/mondu/allowspecific', ScopeInterface::SCOPE_STORE, $storeId);
59+
60+
if ($allowSpecific == 1) {
61+
$availableCountries = explode(',', $availableCountries);
62+
if (!in_array($country, $availableCountries, true)) {
63+
return false;
64+
}
65+
}
66+
67+
return true;
68+
}
69+
}

Model/Request/Transactions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function request($params = []): array
7373
PaymentMethod::DIRECT_DEBIT,
7474
PaymentMethod::INSTALLMENT,
7575
PaymentMethod::INSTALLMENT_BY_INVOICE,
76+
PaymentMethod::PAY_NOW,
7677
];
7778

7879
if (in_array($params['payment_method'], $monduMethods, true)) {

Model/ResourceModel/Log/Grid/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Collection extends LogCollection implements SearchResultInterface
3131
* @param ManagerInterface $eventManager
3232
* @param string $mainTable
3333
* @param string $eventPrefix
34-
* @param string $eventObject
35-
* @param string $resourceModel
34+
* @param string|null $eventObject
35+
* @param string|null $resourceModel
3636
* @param string $model
3737
* @param AdapterInterface|null $connection
3838
* @param AbstractDb|null $resource
@@ -45,8 +45,8 @@ public function __construct(
4545
ManagerInterface $eventManager,
4646
string $mainTable,
4747
string $eventPrefix,
48-
string $eventObject,
49-
string $resourceModel,
48+
?string $eventObject,
49+
?string $resourceModel,
5050
string $model = Document::class,
5151
?AdapterInterface $connection = null,
5252
?AbstractDb $resource = null,

Model/Ui/ConfigProvider.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ConfigProvider implements ConfigProviderInterface
1919
public const SEPA_CODE = 'mondusepa';
2020
public const INSTALLMENT_CODE = 'monduinstallment';
2121
public const INSTALLMENT_BY_INVOICE_CODE = 'monduinstallmentbyinvoice';
22+
public const PAY_NOW_CODE = 'mondupaynow';
2223

2324
public const API_URL = 'https://api.mondu.ai/api/v1';
2425
public const SANDBOX_API_URL = 'https://api.demo.mondu.ai/api/v1';
@@ -120,7 +121,8 @@ public function isActive(): bool
120121
return $this->scopeConfig->isSetFlag('payment/mondu/active')
121122
|| $this->scopeConfig->isSetFlag('payment/mondusepa/active')
122123
|| $this->scopeConfig->isSetFlag('payment/monduinstallment/active')
123-
|| $this->scopeConfig->isSetFlag('payment/monduinstallmentbyinvoice/active');
124+
|| $this->scopeConfig->isSetFlag('payment/monduinstallmentbyinvoice/active')
125+
|| $this->scopeConfig->isSetFlag('payment/mondupaynow/active');
124126
}
125127

126128
/**
@@ -184,6 +186,8 @@ public function getConfig(): array
184186
->getValue('payment/monduinstallment/description', ScopeInterface::SCOPE_STORE);
185187
$descriptionConfigMonduinstallmentByInvoice = $this->scopeConfig
186188
->getValue('payment/monduinstallmentbyinvoice/description', ScopeInterface::SCOPE_STORE);
189+
$descriptionConfigMonduPayNow = $this->scopeConfig
190+
->getValue('payment/mondupaynow/description', ScopeInterface::SCOPE_STORE);
187191

188192
$descriptionMondu = $descriptionConfigMondu
189193
? __($descriptionConfigMondu) . '<br><br>' . $privacyText
@@ -197,6 +201,9 @@ public function getConfig(): array
197201
$descriptionMonduinstallmentByInvoice = $descriptionConfigMonduinstallmentByInvoice
198202
? __($descriptionConfigMonduinstallmentByInvoice) . '<br><br>' . $privacyText
199203
: $privacyText;
204+
$descriptionMonduPayNow = $descriptionConfigMonduPayNow
205+
? __($descriptionConfigMonduPayNow) . '<br><br>' . $privacyText
206+
: $privacyText;
200207

201208
return [
202209
'payment' => [
@@ -226,6 +233,13 @@ public function getConfig(): array
226233
'title' => __($this->scopeConfig
227234
->getValue('payment/monduinstallmentbyinvoice/title', ScopeInterface::SCOPE_STORE)),
228235
],
236+
self::PAY_NOW_CODE => [
237+
'sdkUrl' => $this->getSdkUrl(),
238+
'monduCheckoutTokenUrl' => $this->urlBuilder->getUrl('mondu/payment_checkout/token'),
239+
'description' => $descriptionMonduPayNow,
240+
'title' => __($this->scopeConfig
241+
->getValue('payment/mondupaynow/title', ScopeInterface::SCOPE_STORE)),
242+
],
229243
],
230244
];
231245
}
@@ -268,6 +282,7 @@ public function updateNewOrderStatus(): void
268282
$this->writer->save('payment/mondusepa/order_status', $status);
269283
$this->writer->save('payment/monduinstallment/order_status', $status);
270284
$this->writer->save('payment/monduinstallmentbyinvoice/order_status', $status);
285+
$this->writer->save('payment/mondupaynow/order_status', $status);
271286
}
272287

273288
/**

Plugin/Magento/Email/Model/Template.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ protected function getInvoiceDetails(array $invoiceData): string
108108
$invoiceDetails .= __('Since you have chosen the payment method to purchase on account with payment via SEPA direct debit through Mondu, the invoice amount will be debited from your bank account on the due date.') . '<br/>';
109109
$invoiceDetails .= __('Before the amount is debited from your account, you will receive notice of the direct debit. Kindly make sure you have sufficient funds in your account.') . '<br/>';
110110
break;
111+
case $this->scopeConfig->getValue('payment/mondupaynow/title', ScopeInterface::SCOPE_STORE):
112+
$invoiceDetails = __('This invoice was created in accordance with the general terms and conditions of <strong>%1</strong> and <strong>Mondu GmbH</strong> for the purchase on account payment model.', $invoiceData['merchant_company_name']) . '<br/>';
113+
break;
111114
default:
112115
$invoiceDetails = __('This invoice was created in accordance with the general terms and conditions of <strong>%1</strong> and <strong>Mondu GmbH</strong> for the instalment payment model.', $invoiceData['merchant_company_name']) . '<br/>';
113116
$invoiceDetails .= __('Since you have chosen the instalment payment method via SEPA direct debit through Mondu, the individual installments will be debited from your bank account on the due date.') . '<br/>';

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mondu_gmbh/magento2-payment",
33
"description": "Mondu payment method for magento 2",
44
"type": "magento2-module",
5-
"version": "2.5.0",
5+
"version": "2.6.0",
66
"license": "MIT",
77
"require": {
88
"php": ">=8.1",

etc/adminhtml/system.xml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,43 +103,65 @@
103103
<label>Installments by Invoice Description</label>
104104
<config_path>payment/monduinstallmentbyinvoice/description</config_path>
105105
</field>
106-
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="14" showInDefault="9"
106+
<field id="activepaynow" translate="label" type="select" sortOrder="13" showInDefault="1"
107+
showInWebsite="1" showInStore="1" canRestore="1">
108+
<label>Enable Pay Now</label>
109+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
110+
<config_path>payment/mondupaynow/active</config_path>
111+
</field>
112+
<field id="paynow_title" translate="label" type="text" sortOrder="14" showInDefault="1"
113+
showInWebsite="1" showInStore="1" canRestore="1">
114+
<label>Pay Now Title</label>
115+
<config_path>payment/mondupaynow/title</config_path>
116+
</field>
117+
<field id="paynow_description" translate="label" type="textarea" sortOrder="15" showInDefault="1"
118+
showInWebsite="1" showInStore="1" canRestore="1">
119+
<label>Pay Now Description</label>
120+
<config_path>payment/mondupaynow/description</config_path>
121+
</field>
122+
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="16" showInDefault="9"
107123
showInWebsite="1" showInStore="1" canRestore="1">
108124
<label>Payment From Applicable Countries</label>
109125
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
110126
<config_path>payment/mondu/allowspecific</config_path>
111127
</field>
112-
<field id="specificcountry" translate="label" type="multiselect" sortOrder="15" showInDefault="1"
128+
<field id="specificcountry" translate="label" type="multiselect" sortOrder="17" showInDefault="1"
113129
showInWebsite="1" showInStore="1" canRestore="1">
114130
<label>Payment From Specific Countries</label>
115131
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
116132
<config_path>payment/mondu/specificcountry</config_path>
117133
</field>
118-
<field id="mondusortorder" translate="label" type="text" sortOrder="16" showInDefault="1"
134+
<field id="mondusortorder" translate="label" type="text" sortOrder="18" showInDefault="1"
119135
showInWebsite="1" showInStore="1" canRestore="1">
120136
<label>Bank Transfer Sort Order</label>
121137
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
122138
<config_path>payment/mondu/sort_order</config_path>
123139
</field>
124-
<field id="mondusepasortorder" translate="label" type="text" sortOrder="17" showInDefault="1"
140+
<field id="mondusepasortorder" translate="label" type="text" sortOrder="19" showInDefault="1"
125141
showInWebsite="1" showInStore="1" canRestore="1">
126142
<label>SEPA Direct Debit Sort Order</label>
127143
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
128144
<config_path>payment/mondusepa/sort_order</config_path>
129145
</field>
130-
<field id="monduinstallmentsortorder" translate="label" type="text" sortOrder="18"
146+
<field id="monduinstallmentsortorder" translate="label" type="text" sortOrder="20"
131147
showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
132148
<label>Split Payments Sort Order</label>
133149
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
134150
<config_path>payment/monduinstallment/sort_order</config_path>
135151
</field>
136-
<field id="monduinstallmentbyinvoicesortorder" translate="label" type="text" sortOrder="19"
152+
<field id="monduinstallmentbyinvoicesortorder" translate="label" type="text" sortOrder="21"
137153
showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
138154
<label>Installments By Invoice Sort Order</label>
139155
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
140156
<config_path>payment/monduinstallmentbyinvoice/sort_order</config_path>
141157
</field>
142-
<field id="debug" translate="label" type="select" sortOrder="20" showInDefault="1"
158+
<field id="mondupaynowsortorder" translate="label" type="text" sortOrder="22" showInDefault="1"
159+
showInWebsite="1" showInStore="1" canRestore="1">
160+
<label>Pay Now Sort Order</label>
161+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
162+
<config_path>payment/mondupaynow/sort_order</config_path>
163+
</field>
164+
<field id="debug" translate="label" type="select" sortOrder="23" showInDefault="1"
143165
showInWebsite="1" showInStore="1" canRestore="1">
144166
<label>Enable Logs</label>
145167
<config_path>payment/mondu/debug</config_path>

0 commit comments

Comments
 (0)