Skip to content

Commit b3310d9

Browse files
PT-1190: Add functions that provide details for the invoices. (#105)
1 parent 9f85dbf commit b3310d9

File tree

12 files changed

+253
-8
lines changed

12 files changed

+253
-8
lines changed

Helpers/Log.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ public function logTransaction($order, $response, $addons = null, $paymentMethod
114114
'payment_method' => $paymentMethod,
115115
'authorized_net_term' => $response['authorized_net_term'],
116116
'is_confirmed' => 1,
117-
'invoice_iban' => $response['merchant']['viban'] ?? null
117+
'invoice_iban' => $response['merchant']['viban'] ?? null,
118+
'external_data' => json_encode([
119+
'merchant_company_name' => $response['merchant']['company_name'] ?: null,
120+
'buyer_country_code' => $response['content_configuration']['buyer_country_code'] ?: null,
121+
'bank_account' => $response['bank_account'] ?: null
122+
])
118123
];
119124
$monduLogger->addData($logData);
120125
$monduLogger->save();
@@ -311,8 +316,7 @@ public function canCreditMemo($orderUid)
311316
$log['mondu_state'] === self::MONDU_STATE_SHIPPED ||
312317
$log['mondu_state'] === self::MONDU_STATE_PARTIALLY_COMPLETE ||
313318
$log['mondu_state'] === self::MONDU_STATE_COMPLETE
314-
)
315-
) {
319+
)) {
316320
return true;
317321
}
318322

Plugin/AddTemplateVariable.php

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?php
2+
3+
namespace Mondu\Mondu\Plugin;
4+
5+
use Magento\Framework\App\Config\ScopeConfigInterface;
6+
use Magento\Store\Model\ScopeInterface;
7+
use Mondu\Mondu\Helpers\Log as MonduLogger;
8+
use Mondu\Mondu\Helpers\Logger\Logger as MonduFileLogger;
9+
10+
class AddTemplateVariable
11+
{
12+
const MONDU_UK_SORT_CODE = '185008';
13+
const MONDU_EN_ACCOUNT_HOLDER = 'Mondu Capital S.à r.l.';
14+
const MONDU_FR_DE_ACCOUNT_HOLDER = 'Mondu Capital Sàrl';
15+
const MONDU_NL_ACCOUNT_HOLDER = 'Mondu Capital S.à r.l';
16+
const MONDU_EN_BANK_NAME = 'Citibank N.A.';
17+
const MONDU_EN_BIC = 'CITINL2X';
18+
const MONDU_DE_NL_BIC = 'HYVEDEMME40';
19+
const MONDU_FR_BIC = 'CITIFRPP';
20+
const UK_COUNTRY_CODE = 'UK';
21+
const DE_COUNTRY_CODE = 'DE';
22+
const FR_COUNTRY_CODE = 'FR';
23+
const NL_COUNTRY_CODE = 'NL';
24+
25+
/**
26+
* @var MonduLogger
27+
*/
28+
private MonduLogger $monduLogger;
29+
30+
/**
31+
* @var MonduFileLogger
32+
*/
33+
private MonduFileLogger $monduFileLogger;
34+
35+
/**
36+
* @var ScopeConfigInterface
37+
*/
38+
private ScopeConfigInterface $scopeConfig;
39+
40+
/**
41+
* @param MonduLogger $monduLogger
42+
* @param MonduFileLogger $monduFileLogger
43+
* @param ScopeConfigInterface $scopeConfig
44+
*/
45+
public function __construct(
46+
MonduLogger $monduLogger,
47+
MonduFileLogger $monduFileLogger,
48+
ScopeConfigInterface $scopeConfig
49+
) {
50+
$this->monduLogger = $monduLogger;
51+
$this->monduFileLogger = $monduFileLogger;
52+
$this->scopeConfig = $scopeConfig;
53+
}
54+
55+
/**
56+
* @param \Magento\Email\Model\Template $subject
57+
* @param array $vars
58+
*
59+
* @return array[]
60+
*/
61+
public function beforeSetVars(
62+
\Magento\Email\Model\Template $subject,
63+
array $vars
64+
) {
65+
if (!$vars['order'] || !$vars['order']->getMonduReferenceId()) {
66+
return [$vars];
67+
}
68+
69+
try {
70+
$vars['monduDetails'] = '';
71+
$monduReferenceId = $vars['order']->getMonduReferenceId();
72+
$monduLog = $this->monduLogger->getLogCollection($monduReferenceId);
73+
74+
if (!$monduLog) {
75+
return [$vars];
76+
}
77+
78+
if (!$monduLog['external_data'] || !is_string($monduLog['external_data'])) {
79+
return [$vars];
80+
}
81+
82+
$externalData = json_decode($monduLog['external_data'] , true);
83+
if (json_last_error() !== JSON_ERROR_NONE) {
84+
return [$vars];
85+
}
86+
87+
$billingAddress = $vars['order']->getBillingAddress();
88+
$vars['monduDetails'] = $this->getInvoiceDetails([
89+
'countryId' => $externalData['buyer_country_code'] ?: $billingAddress->getCountryId(),
90+
'merchant_company_name' => $externalData['merchant_company_name'],
91+
'bank_account' => $externalData['bank_account'],
92+
'invoiceId' => $vars['invoice']->getIncrementId(),
93+
'iban' => $monduLog['invoice_iban'],
94+
'paymentMethod' => $vars['order']->getPayment()->getMethodInstance()->getTitle(),
95+
'netTerms' => isset($monduLog['authorized_net_term']) ? $monduLog['authorized_net_term'] : ''
96+
]);
97+
} catch (\Exception $e) {
98+
$this->monduFileLogger->critical($e->getMessage());
99+
}
100+
101+
return [$vars];
102+
}
103+
104+
/**
105+
* @param $invoiceDetails
106+
*
107+
* @return string
108+
*/
109+
protected function getInvoiceDetails($invoiceData): string
110+
{
111+
switch ($invoiceData['paymentMethod']) {
112+
case $this->scopeConfig->getValue('payment/mondu/title', ScopeInterface::SCOPE_STORE):
113+
$invoiceDetails = $this->getPayLaterViaBankTransferDetails($invoiceData);
114+
break;
115+
case $this->scopeConfig->getValue('payment/mondusepa/title', ScopeInterface::SCOPE_STORE):
116+
$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/>';
117+
$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/>';
118+
$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/>';
119+
break;
120+
default:
121+
$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/>';
122+
$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/>';
123+
$invoiceDetails .= __('Before the amounts are debited from your account, you will receive notice regarding the direct debit. Kindly make sure you have sufficient funds in your account. In the event of changes to your order, the instalment plan will be adjusted to reflect the new order total.') . '<br/>';
124+
break;
125+
}
126+
127+
return $invoiceDetails;
128+
}
129+
130+
/**
131+
* @param $invoiceData
132+
*
133+
* @return string
134+
*/
135+
protected function getPayLaterViaBankTransferDetails($invoiceData)
136+
{
137+
$invoiceDetails = __('This invoice is created in accordance with the terms and conditions of <strong>%1</strong> modified by <strong>Mondu GmbH</strong> payment terms. Please pay to the following account:', $invoiceData['merchant_company_name']) . '<br/>';
138+
139+
switch ($invoiceData['countryId']) {
140+
case self::UK_COUNTRY_CODE:
141+
$invoiceDetails .= __('<strong>Account holder:</strong> %1', $invoiceData['bank_account']['account_holder'] ?: self::MONDU_EN_ACCOUNT_HOLDER) . '<br/>';
142+
$invoiceDetails .= __('<strong>Bank:</strong> %1', $invoiceData['bank_account']['bank'] ?: self::MONDU_EN_BANK_NAME) . '<br/>';
143+
$invoiceDetails .= __('<strong>Sort Code:</strong> %1', $invoiceData['bank_account']['sort_code'] ?: self::MONDU_UK_SORT_CODE) . '<br/>';
144+
$invoiceDetails .= __('<strong>Account Number:</strong> %1', $invoiceData['bank_account']['account_number']) . '<br/>';
145+
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
146+
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_EN_BIC) . '<br/>';
147+
break;
148+
case self::DE_COUNTRY_CODE:
149+
$invoiceDetails .= __('<strong>Account holder:</strong> %1', self::MONDU_FR_DE_ACCOUNT_HOLDER) . '<br/>';
150+
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
151+
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_DE_NL_BIC) . '<br/>';
152+
break;
153+
case self::FR_COUNTRY_CODE:
154+
$invoiceDetails .= __('<strong>Account holder:</strong> %1', self::MONDU_FR_DE_ACCOUNT_HOLDER) . '<br/>';
155+
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
156+
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_FR_BIC) . '<br/>';
157+
break;
158+
case self::NL_COUNTRY_CODE:
159+
$invoiceDetails .= __('<strong>Account holder:</strong> %1', self::MONDU_NL_ACCOUNT_HOLDER) . '<br/>';
160+
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
161+
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_DE_NL_BIC) . '<br/>';
162+
break;
163+
default:
164+
$invoiceDetails .= __('<strong>Account holder:</strong> %1', $invoiceData['bank_account']['account_holder'] ?: self::MONDU_EN_ACCOUNT_HOLDER) . '<br/>';
165+
$invoiceDetails .= __('<strong>Bank:</strong> %1', $invoiceData['bank_account']['bank'] ?: self::MONDU_EN_BANK_NAME) . '<br/>';
166+
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
167+
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_EN_BIC) . '<br/>';
168+
break;
169+
}
170+
171+
$invoiceDetails .= __('<strong>Payment reference:</strong> %1', $invoiceData['invoiceId']) . '<br/>';
172+
$invoiceDetails .= __('<strong>Payment term:</strong> %1 days', $invoiceData['netTerms']) . '<br/>';
173+
174+
return $invoiceDetails;
175+
}
176+
}

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.3.3",
5+
"version": "2.3.4",
66
"license": [
77
"MIT"
88
],

etc/db_schema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<column xsi:type="smallint" name="is_confirmed" unsigned="true" nullable="false" default="0" comment="Is order was confirmed"/>
1515
<column xsi:type="varchar" name="payment_method" comment="Mondu payment method"/>
1616
<column xsi:type="int" name="authorized_net_term" unsigned="true" nullable="true" comment="Mondu authorized net term"/>
17+
<column xsi:type="text" name="external_data" comment="External Data"/>
1718

1819
<index referenceId="MONDU_TRANSACTIONS_CUSTOMER_ID" indexType="btree">
1920
<column name="customer_id"/>

etc/db_schema_whitelist.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"skip_ship_observer": true,
1515
"is_confirmed": true,
1616
"payment_method": true,
17-
"authorized_net_term": true
17+
"authorized_net_term": true,
18+
"external_data": true
1819
},
1920
"index": {
2021
"MONDU_TRANSACTIONS_CUSTOMER_ID": true
@@ -40,4 +41,4 @@
4041
"mondu_reference_id": true
4142
}
4243
}
43-
}
44+
}

etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@
3636
<type name="Magento\Payment\Helper\Data">
3737
<plugin sortOrder="10" name="monduPaymentData" type="Mondu\Mondu\Helpers\DataPlugin"/>
3838
</type>
39+
<type name="Magento\Email\Model\Template">
40+
<plugin sortOrder="10" name="addTemplateVariable" type="Mondu\Mondu\Plugin\AddTemplateVariable"/>
41+
</type>
3942
</config>

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Mondu_Mondu" setup_version="2.3.3">
3+
<module name="Mondu_Mondu" setup_version="2.3.4">
44
<sequence>
55
<module name="Magento_Sales"/>
66
<module name="Magento_Payment"/>

i18n/de_DE.csv

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Mondu: order id %1,Mondu: Bestellnummer %1
1010
Mondu: Invalid shipment amount,Mondu: Ungültige Versandkosten
1111
Can't ship order: Mondu order state must be confirmed or partially_shipped,Bestellung kann nicht versendet werden: Der Status der Mondu-Bestellung muss bestätigt oder teilweise versandt sein.
1212
Mondu: Invoice is required to ship the order.,Mondu: Eine Rechnung ist für den Versand der Bestellung erforderlich.
13-
Mondu: invoice created with id %1,Mondu: Rechnung mit Rechnungsnummer %1 erstellt
13+
Mondu: invoice created with id %1,Mondu: Rechnung mit Rechnungsnummer %1 erstellt
1414
Mondu: You cant partially refund order before shipment,Mondu: Sie können keine Teilstornierung der Bestellung vor Versand vornehmen
1515
Mondu: Something went wrong,Mondu: Etwas ist falsch gelaufen
1616
Mondu: The order with the id %1 was successfully canceled.,Mondu: Die Bestellung mit der Nummer %1 wurde erfolgreich storniert.
@@ -35,3 +35,15 @@ Pay later via SEPA Direct Debit,"SEPA-Lastschrift - jetzt kaufen, später per Ba
3535
Split Payments,Ratenzahlung - Bequem in Raten per Bankeinzug zahlen
3636
Information on the processing of your personal data by Mondu GmbH can be found <a href='https://www.mondu.ai/de/datenschutzgrundverordnung-kaeufer/' target='_blank'>here.</a>,Hinweise zur Verarbeitung Ihrer personenbezogenen Daten durch die Mondu GmbH finden Sie <a href='https://www.mondu.ai/de/datenschutzgrundverordnung-kaeufer/' target='_blank'>hier.</a>
3737
"Require invoice for shipment","Für den Versand ein Rechnungsdokument verlangen"
38+
"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.","Diese Rechnung wurde abgetreten gemäß den Allgemeinen Bedingungen von <strong>%1</strong> und <strong>Mondu GmbH</strong> zum Modell Kauf auf Rechnung."
39+
"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.","Da Sie die Zahlart Rechnungskauf mit Begleichung via SEPA-Lastschrift über Mondu gewählt haben, wird die Rechnungssumme am Fälligkeitstag von Ihrem Bankkonto abgebucht."
40+
"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.","Bevor der Betrag von Ihrem Konto abgebucht wird, erhalten Sie eine Lastschriftankündigung. Bitte achten Sie auf eine ausreichende Kontodeckung."
41+
"This invoice is created in accordance with the terms and conditions of <strong>%1</strong> modified by <strong>Mondu GmbH</strong> payment terms. Please pay to the following account:","Diese Rechnung wurde abgetreten gemäß den Allgemeinen Bedingungen von <strong>%1</strong> und <strong>Mondu GmbH</strong> zum Modell Kauf auf Rechnung. Wir bitten um schuldbefreiende Zahlung auf folgendes Konto:"
42+
"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.","Diese Rechnung wurde gemäß den Allgemeinen Bedingungen von <strong>%1</strong> und <strong>Mondu GmbH</strong> zum Zahlungsmodell Ratenkauf abgetreten."
43+
"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.","Da Sie die Zahlart Ratenkauf mit Begleichung via SEPA-Lastschrift über Mondu gewählt haben, werden die einzelnen Raten an ihrem jeweiligen Fälligkeitstag von Ihrem Bankkonto abgebucht."
44+
"Before the amounts are debited from your account, you will receive notice regarding the direct debit. Kindly make sure you have sufficient funds in your account. In the event of changes to your order, the instalment plan will be adjusted to reflect the new order total.","Bevor die Beträge von Ihrem Konto abgebucht werden, erhalten Sie bezüglich der Lastschrift eine Vorankündigung. Bitte achten Sie auf eine ausreichende Kontodeckung. Im Falle von Änderungen an Ihrer Bestellung wird der Ratenplan an die neue Bestellsumme angepasst."
45+
<strong>Account holder:</strong> %1,<strong>Kontoinhaber:</strong> %1
46+
<strong>IBAN:</strong> %1,<strong>IBAN:</strong> %1.
47+
<strong>BIC:</strong> %1,<strong>BIC:</strong> %1
48+
<strong>Payment reference:</strong> %1,<strong>Verwendungszweck:</strong> %1.
49+
<strong>Payment term:</strong> %1 days,<strong>Zahlungsziel:</strong> %1 Tage

i18n/fr_BE.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@ Actions,Actions
6161
Pay later via bank transfer,"Payez plus tard par virement"
6262
Pay later via SEPA Direct Debit,"SEPA - Payer plus tard par prélèvement automatique"
6363
Split Payments,Paiements Fractionnés - Payer facilement en plusieurs fois par prélèvement automatique
64+
"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.","Cette facture a été cédée conformément aux conditions générales de <strong>%1</strong> et de <strong>Mondu GmbH</strong> pour le modèle d'achat sur facture."
65+
"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.","Comme vous avez choisi le mode de paiement de l'achat sur facture avec règlement via prélèvement SEPA via Mondu, le montant de la facture sera débité de votre compte bancaire à la date d'échéance."
66+
"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.","Vous recevrez un avis avant le prélèvement automatique sur votre compte. Veuillez alors vous assurer que votre compte contient les fonds suffisants pour assurer la transaction à la date du prélèvement."
67+
"This invoice is created in accordance with the terms and conditions of <strong>%1</strong> modified by <strong>Mondu GmbH</strong> payment terms. Please pay to the following account:","Cette facture a été cédée conformément aux conditions générales de <strong>%1</strong> et de <strong>Mondu GmbH</strong> pour le modèle d'achat sur facture. Nous vous demandons de verser le montant dû sur le compte suivant:"
68+
"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.","Cette facture a été cédée conformément aux conditions générales de <strong>%1</strong> et de <strong>Mondu GmbH</strong> pour le modèle de paiement en plusieurs fois."
69+
"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.","Comme vous avez choisi le mode de paiement en plusieurs fois avec règlement via prélèvement SEPA via Mondu, chaque versement sera prélevé sur votre compte bancaire à sa date d'échéance."
70+
"Before the amounts are debited from your account, you will receive notice regarding the direct debit. Kindly make sure you have sufficient funds in your account. In the event of changes to your order, the instalment plan will be adjusted to reflect the new order total.","Vous recevrez un avis avant le prélèvement automatique sur votre compte. Veuillez alors vous assurer que votre compte contient les fonds suffisants pour assurer la transaction à la date du prélèvement. En cas de modifications apportées à votre commande, le plan de versements sera adapté au nouveau montant de la commande."
71+
<strong>Account holder:</strong> %1,<strong>Titulaire du compte:</strong> %1
72+
<strong>IBAN:</strong> %1,<strong>IBAN:</strong> %1.
73+
<strong>BIC:</strong> %1,<strong>BIC:</strong> %1
74+
<strong>Payment reference:</strong> %1,<strong>Objet:</strong> %1.
75+
<strong>Payment term:</strong> %1 days,<strong>Date limite de paiement:</strong> %1 jours

0 commit comments

Comments
 (0)