Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-1190: Add functions that provide details for the invoices. #105

Merged
merged 6 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Helpers/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ public function logTransaction($order, $response, $addons = null, $paymentMethod
'payment_method' => $paymentMethod,
'authorized_net_term' => $response['authorized_net_term'],
'is_confirmed' => 1,
'invoice_iban' => $response['merchant']['viban'] ?? null
'invoice_iban' => $response['merchant']['viban'] ?? null,
'external_data' => json_encode([
'merchant_company_name' => $response['merchant']['company_name'] ?: null,
'buyer_country_code' => $response['content_configuration']['buyer_country_code'] ?: null,
'bank_account' => $response['bank_account'] ?: null
])
];
$monduLogger->addData($logData);
$monduLogger->save();
Expand Down Expand Up @@ -311,8 +316,7 @@ public function canCreditMemo($orderUid)
$log['mondu_state'] === self::MONDU_STATE_SHIPPED ||
$log['mondu_state'] === self::MONDU_STATE_PARTIALLY_COMPLETE ||
$log['mondu_state'] === self::MONDU_STATE_COMPLETE
)
) {
)) {
return true;
}

Expand Down
176 changes: 176 additions & 0 deletions Plugin/AddTemplateVariable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php

namespace Mondu\Mondu\Plugin;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Mondu\Mondu\Helpers\Log as MonduLogger;
use Mondu\Mondu\Helpers\Logger\Logger as MonduFileLogger;

class AddTemplateVariable
{
const MONDU_UK_SORT_CODE = '185008';
const MONDU_EN_ACCOUNT_HOLDER = 'Mondu Capital S.à r.l.';
const MONDU_FR_DE_ACCOUNT_HOLDER = 'Mondu Capital Sàrl';
const MONDU_NL_ACCOUNT_HOLDER = 'Mondu Capital S.à r.l';
const MONDU_EN_BANK_NAME = 'Citibank N.A.';
const MONDU_EN_BIC = 'CITINL2X';
const MONDU_DE_NL_BIC = 'HYVEDEMME40';
const MONDU_FR_BIC = 'CITIFRPP';
const UK_COUNTRY_CODE = 'UK';
const DE_COUNTRY_CODE = 'DE';
const FR_COUNTRY_CODE = 'FR';
const NL_COUNTRY_CODE = 'NL';

/**
* @var MonduLogger
*/
private MonduLogger $monduLogger;

/**
* @var MonduFileLogger
*/
private MonduFileLogger $monduFileLogger;

/**
* @var ScopeConfigInterface
*/
private ScopeConfigInterface $scopeConfig;

/**
* @param MonduLogger $monduLogger
* @param MonduFileLogger $monduFileLogger
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
MonduLogger $monduLogger,
MonduFileLogger $monduFileLogger,
ScopeConfigInterface $scopeConfig
) {
$this->monduLogger = $monduLogger;
$this->monduFileLogger = $monduFileLogger;
$this->scopeConfig = $scopeConfig;
}

/**
* @param \Magento\Email\Model\Template $subject
* @param array $vars
*
* @return array[]
*/
public function beforeSetVars(
\Magento\Email\Model\Template $subject,
array $vars
) {
if (!$vars['order'] || !$vars['order']->getMonduReferenceId()) {
return [$vars];
}

try {
$vars['monduDetails'] = '';
$monduReferenceId = $vars['order']->getMonduReferenceId();
$monduLog = $this->monduLogger->getLogCollection($monduReferenceId);

if (!$monduLog) {
return [$vars];
}

if (!$monduLog['external_data'] || !is_string($monduLog['external_data'])) {
return [$vars];
}

$externalData = json_decode($monduLog['external_data'] , true);
if (json_last_error() !== JSON_ERROR_NONE) {
return [$vars];
}

$billingAddress = $vars['order']->getBillingAddress();
$vars['monduDetails'] = $this->getInvoiceDetails([
'countryId' => $externalData['buyer_country_code'] ?: $billingAddress->getCountryId(),
'merchant_company_name' => $externalData['merchant_company_name'],
'bank_account' => $externalData['bank_account'],
'invoiceId' => $vars['invoice']->getIncrementId(),
'iban' => $monduLog['invoice_iban'],
'paymentMethod' => $vars['order']->getPayment()->getMethodInstance()->getTitle(),
'netTerms' => isset($monduLog['authorized_net_term']) ? $monduLog['authorized_net_term'] : ''
]);
} catch (\Exception $e) {
$this->monduFileLogger->critical($e->getMessage());
}

return [$vars];
}

/**
* @param $invoiceDetails
*
* @return string
*/
protected function getInvoiceDetails($invoiceData): string
{
switch ($invoiceData['paymentMethod']) {
case $this->scopeConfig->getValue('payment/mondu/title', ScopeInterface::SCOPE_STORE):
$invoiceDetails = $this->getPayLaterViaBankTransferDetails($invoiceData);
break;
case $this->scopeConfig->getValue('payment/mondusepa/title', ScopeInterface::SCOPE_STORE):
$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/>';
$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/>';
$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/>';
break;
default:
$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/>';
$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/>';
$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/>';
break;
}

return $invoiceDetails;
}

/**
* @param $invoiceData
*
* @return string
*/
protected function getPayLaterViaBankTransferDetails($invoiceData)
{
$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/>';

switch ($invoiceData['countryId']) {
case self::UK_COUNTRY_CODE:
$invoiceDetails .= __('<strong>Account holder:</strong> %1', $invoiceData['bank_account']['account_holder'] ?: self::MONDU_EN_ACCOUNT_HOLDER) . '<br/>';
$invoiceDetails .= __('<strong>Bank:</strong> %1', $invoiceData['bank_account']['bank'] ?: self::MONDU_EN_BANK_NAME) . '<br/>';
$invoiceDetails .= __('<strong>Sort Code:</strong> %1', $invoiceData['bank_account']['sort_code'] ?: self::MONDU_UK_SORT_CODE) . '<br/>';
$invoiceDetails .= __('<strong>Account Number:</strong> %1', $invoiceData['bank_account']['account_number']) . '<br/>';
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_EN_BIC) . '<br/>';
break;
case self::DE_COUNTRY_CODE:
$invoiceDetails .= __('<strong>Account holder:</strong> %1', self::MONDU_FR_DE_ACCOUNT_HOLDER) . '<br/>';
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_DE_NL_BIC) . '<br/>';
break;
case self::FR_COUNTRY_CODE:
$invoiceDetails .= __('<strong>Account holder:</strong> %1', self::MONDU_FR_DE_ACCOUNT_HOLDER) . '<br/>';
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_FR_BIC) . '<br/>';
break;
case self::NL_COUNTRY_CODE:
$invoiceDetails .= __('<strong>Account holder:</strong> %1', self::MONDU_NL_ACCOUNT_HOLDER) . '<br/>';
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_DE_NL_BIC) . '<br/>';
break;
default:
$invoiceDetails .= __('<strong>Account holder:</strong> %1', $invoiceData['bank_account']['account_holder'] ?: self::MONDU_EN_ACCOUNT_HOLDER) . '<br/>';
$invoiceDetails .= __('<strong>Bank:</strong> %1', $invoiceData['bank_account']['bank'] ?: self::MONDU_EN_BANK_NAME) . '<br/>';
$invoiceDetails .= __('<strong>IBAN:</strong> %1', $invoiceData['iban']) . '<br/>';
$invoiceDetails .= __('<strong>BIC:</strong> %1', $invoiceData['bank_account']['bic'] ?: self::MONDU_EN_BIC) . '<br/>';
break;
}

$invoiceDetails .= __('<strong>Payment reference:</strong> %1', $invoiceData['invoiceId']) . '<br/>';
$invoiceDetails .= __('<strong>Payment term:</strong> %1 days', $invoiceData['netTerms']) . '<br/>';

return $invoiceDetails;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mondu_gmbh/magento2-payment",
"description": "Mondu payment method for magento 2",
"type": "magento2-module",
"version": "2.3.3",
"version": "2.3.4",
"license": [
"MIT"
],
Expand Down
1 change: 1 addition & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<column xsi:type="smallint" name="is_confirmed" unsigned="true" nullable="false" default="0" comment="Is order was confirmed"/>
<column xsi:type="varchar" name="payment_method" comment="Mondu payment method"/>
<column xsi:type="int" name="authorized_net_term" unsigned="true" nullable="true" comment="Mondu authorized net term"/>
<column xsi:type="text" name="external_data" comment="External Data"/>

<index referenceId="MONDU_TRANSACTIONS_CUSTOMER_ID" indexType="btree">
<column name="customer_id"/>
Expand Down
5 changes: 3 additions & 2 deletions etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"skip_ship_observer": true,
"is_confirmed": true,
"payment_method": true,
"authorized_net_term": true
"authorized_net_term": true,
"external_data": true
},
"index": {
"MONDU_TRANSACTIONS_CUSTOMER_ID": true
Expand All @@ -40,4 +41,4 @@
"mondu_reference_id": true
}
}
}
}
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
<type name="Magento\Payment\Helper\Data">
<plugin sortOrder="10" name="monduPaymentData" type="Mondu\Mondu\Helpers\DataPlugin"/>
</type>
<type name="Magento\Email\Model\Template">
<plugin sortOrder="10" name="addTemplateVariable" type="Mondu\Mondu\Plugin\AddTemplateVariable"/>
</type>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mondu_Mondu" setup_version="2.3.3">
<module name="Mondu_Mondu" setup_version="2.3.4">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
14 changes: 13 additions & 1 deletion i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Mondu: order id %1,Mondu: Bestellnummer %1
Mondu: Invalid shipment amount,Mondu: Ungültige Versandkosten
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.
Mondu: Invoice is required to ship the order.,Mondu: Eine Rechnung ist für den Versand der Bestellung erforderlich.
Mondu: invoice created with id %1,Mondu: Rechnung mit Rechnungsnummer %1 erstellt
Mondu: invoice created with id %1,Mondu: Rechnung mit Rechnungsnummer %1 erstellt
Mondu: You cant partially refund order before shipment,Mondu: Sie können keine Teilstornierung der Bestellung vor Versand vornehmen
Mondu: Something went wrong,Mondu: Etwas ist falsch gelaufen
Mondu: The order with the id %1 was successfully canceled.,Mondu: Die Bestellung mit der Nummer %1 wurde erfolgreich storniert.
Expand All @@ -35,3 +35,15 @@ Pay later via SEPA Direct Debit,"SEPA-Lastschrift - jetzt kaufen, später per Ba
Split Payments,Ratenzahlung - Bequem in Raten per Bankeinzug zahlen
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>
"Require invoice for shipment","Für den Versand ein Rechnungsdokument verlangen"
"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."
"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."
"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."
"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:"
"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."
"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."
"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."
<strong>Account holder:</strong> %1,<strong>Kontoinhaber:</strong> %1
<strong>IBAN:</strong> %1,<strong>IBAN:</strong> %1.
<strong>BIC:</strong> %1,<strong>BIC:</strong> %1
<strong>Payment reference:</strong> %1,<strong>Verwendungszweck:</strong> %1.
<strong>Payment term:</strong> %1 days,<strong>Zahlungsziel:</strong> %1 Tage
12 changes: 12 additions & 0 deletions i18n/fr_BE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ Actions,Actions
Pay later via bank transfer,"Payez plus tard par virement"
Pay later via SEPA Direct Debit,"SEPA - Payer plus tard par prélèvement automatique"
Split Payments,Paiements Fractionnés - Payer facilement en plusieurs fois par prélèvement automatique
"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."
"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."
"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."
"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:"
"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."
"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."
"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."
<strong>Account holder:</strong> %1,<strong>Titulaire du compte:</strong> %1
<strong>IBAN:</strong> %1,<strong>IBAN:</strong> %1.
<strong>BIC:</strong> %1,<strong>BIC:</strong> %1
<strong>Payment reference:</strong> %1,<strong>Objet:</strong> %1.
<strong>Payment term:</strong> %1 days,<strong>Date limite de paiement:</strong> %1 jours
Loading
Loading