Getting Started
Bank Mails Parser reads the payment notification emails of Slovak and Czech banks (Tatra banka, VÚB, ČSOB Slovensko and ČSOB Česká republika) and returns the transaction as a typed, immutable MailContent object: the amount as Money in minor units, the date, the accounts, the variable, specific and constant symbols, and the payer's message. Your application finds the order and books the payment.
Requirements
- PHP 8.4 or newer (tested on 8.4, 8.5 and 8.6)
ext-mbstring- Composer
Installation
composer require tomaj/bank-mails-parsersingpolyma/openpgp-php comes with it; it decrypts Tatra banka statements in pure PHP.
Your first mail
A Tatra banka b-mail notification, as the decoded plain-text body:
Vazeny klient,
16.1.2015 12:51 bol zostatok Vasho uctu SK9812353347235 zvyseny o 12,31 EUR.
uctovny zostatok: 142,11 EUR
aktualny zostatok: 142,11 EUR
disponibilny zostatok: 142,11 EUR
Popis transakcie: CCINT 1100/000000-261426464
Referencia platitela: /VS1234056789/SS/KS
Informacia pre prijemcu: test-spravaGive it to BankMailsParser with the sender address. The facade finds the bank on its own:
<?php
use Tomaj\BankMailsParser\BankMailsParser;
require 'vendor/autoload.php';
$parser = new BankMailsParser();
$mailContent = $parser->parse($emailBody, 'b-mail@tatrabanka.sk');
echo $mailContent->money?->format() . "\n";
echo $mailContent->vs . "\n";
echo $mailContent->accountNumber . "\n";
echo $mailContent->transactionDate?->format('Y-m-d H:i') . "\n";12.31 EUR
1234056789
SK9812353347235
2015-01-16 12:51parse()returns one transaction or throws:UnsupportedBankExceptionwhen no bank recognises the mail,InvalidEmailFormatExceptionwhen a bank recognises it but it cannot be read,MultipleTransactionsExceptionwhen it holds several transactions.tryParse()returnsnullinstead of throwing a parse error.parseAll()returns a list with every transaction. Use it when you process a mailbox: ČSOB mails and statements can contain more than one.
See Bank Detection and Exceptions.
Supported banks
| Bank | Parser | |
|---|---|---|
| Tatra banka (SK) | b-mail notification of an account movement | TatraBankaMailParser |
| Tatra banka (SK) | CardPay / ComfortPay card payment result | TatraBankaSimpleMailParser |
| Tatra banka (SK) | PGP-encrypted card statement | TatraBankaStatementMailParser |
| ČSOB (CZ) | transaction notification, one or more per mail | CsobMailParser |
| ČSOB (SK) | SEPA transaction notification, one or more per mail | SkCsobMailParser |
| VÚB (SK) | payment notification | VubMailParser |
Pass the decoded plain text of the mail. ČSOB bodies with <br>, <p> or <div> line breaks are normalised; other HTML is not parsed.
Before you book a payment
A parsed mail is not yet a verified payment. Check that the mail really comes from the bank (DKIM), verify CardPay signatures, and match the order by the variable symbol and the amount. Security explains why.
Next Steps
- Examples: runnable recipes for every bank, a whole mailbox and error handling
- Configuration reference: every constructor and method argument
- Bank guides: TatraBanka, ČSOB CZ, ČSOB SK, VÚB
- API Reference and FAQ
- Add a new bank