mBank API for getting transactions and make payments - PHP script

mBank logo

PHP library can do the following:

  • Login to mBank

  • List accounts (personal and business) and balances

  • List transactions as PHP array

  • Export transactions in CSV / ABO / PDF format

  • List favorite contacts from address book

  • Make payment with any amount/text/VS/SS/KS at favorite contact's account, which is marked as trustworthy (doesn't need SMS confirmation)

Script simulates standard access to the bank over web, not mobile web, which tends to be unrealiable and have no possibility to do exports.

Works for Czech, Slovak and Polish mBank. PHP 5.3+, PHP 7

class_mbank.php
Order
(only for your own usage; forbidden for further sharing/resale; updates are for free upon request)

Invoice and script is being sent right away.
Thank you, I'll make sure you're satisfied with the purchase.

Usage example

<?php
/**
* Example of mBank API usage
*/
include 'class_mbank.php';

$mb = new mBank("username", "password");
// $mb = new mBank("username", "password", "SK"); // if Slovak mBank
// $mb = new mBank("username", "password", "PL"); // if Poland mBank

$mb->setProfile(1); // sets business profile (needed only if you have personal and business account)

$accounts = $mb->getAccounts(); // lists of accounts and balances
print_r($accounts);

$account = '1234567890'// specific account number

$transactions = $mb->getTransactions($account, -14); // list of transactions for last 14 days

$transactions = $mb->getTransactions($account, '2017-01-01', '2017-12-31'); // list of transactions in 2017

/*
$transactions looks like this
[1] => Array
(
   [date] => 2017-08-02 // datum uskutečnění
   [date_accounting] => 2017-08-02 // datum zaúčtování
   [payer_receiver] => JAN NOVÁK
   [payer_receiver_account] => 000000-1109080801/4000
   [description] => PŘÍCHOZÍ PLATBA Z JINÉ BANKY
   [message] => 
   [ks] => 
   [vs] => 2111498
   [ss] => 
   [amount] => 3500
   [balance] => 2190751,32
)
*/

// original CSV export for last 31 days
$csv_content = $mb->getTransactionsCSV($account, -31);

// PDF export
$content = $mb->getTransactionsPDF($account, '2017-01-01');
file_put_contents('export.pdf', $content);


//---------- PAYMENT
$contacts = $mb->getFavoriteContacts(); // list of favorite contacts with account numbers
$contacts[0]->amount(100.5)->pay(); // sends 100,50 CZK to first contact

// OR this way:
$contact = $mb->findContact("John Novak"); // finds contact with this name
print_r($contact);

// sends 50 CZK to "John Novak"
$contact->vs("012016")->title("my automated payment")->amount(50)->pay();

// sends 120 CZK to "John Novak"
$contact->vs("022016")->title("my automated payment 2")->amount(120)->pay();


/**
* FUNCTION LIST SUMMARY
*/
bool $mb->setProfile( int $profile_id ) // sets personal or company profile
array $mb->getAccounts() // list of account numbers and totals
array $mb->getTransactions( string $account_number, int $x_days_ago ) // gets all the transactions
array $mb->getTransactions( string $account_number, string $date_from )
array
$mb->getTransactions( string $account_number, string $date_from, string $date_to )
string $mb->getTransactionsCSV( ... ) // same parameters as transactions() - returns CSV text
string $mb->getTransactionsPDF( ... ) // same parameters as transactions() - returns PDF file
string $mb->getTransactionsABO( ... ) // same parameters as transactions() - returns ABO file
array $mb->getFavoriteContacts() // returns favorite contacts

// Finds favorite contact (if that contact name has more bank accounts also input $bankAccountName)
object $contact = $mb->findContact( string $contactName, string $bankAccountName = null)
$contact->from( string $account_number) // sets payer account (not needed, first available will be used)
$contact->ss( string $specific_symbol ) // sets specific symbol
$contact->vs( string $variable_symbol ) // sets variable symbol
$contact->ks( string $constant_symbol ) // sets constant symbol
$contact->title( string $payment_description ) // sets payment text
$contact->amount( float $amount) // sets payment amount
$contact->pay() // executes the payment

Safety

Safety is ensured by the bank's requirement to use SMS confirmations for most operations.

Of course, anybody with access to the script will also gain access to password, and thus your banking.

History Log

14.08.2017 - Payment process updated
26.06.2017 - Slight changes in name functions, all is working
15.02.2017 - Little fix if switching too much between personal/business account
16.03.2016 - You can now send payments to favorite accounts that are marked as "Trusted" in your addressbook (don't require SMS verification) ... not tested for PL and SK yet, but should work
30.11.2015 - mBank PL login page has been changed - fixed
21.10.2015 - CSV format of PL mBank updated
19.12.2014 - Added PL and tested for poland mBank
18.11.2014 - Added SK and tested for slovak mBank
27.10.2014 - New API available for fee
12.02.2014 - mBank has new internet banking
30.07.2013 - Changed CSV format
10.09.2012 - Fixed if date was bigger then today, mBank returned error
17.01.2012 - Fixed long variable symbols + added PDF export
08.12.2011 - Few fixes in transaction mesasage
25.07.2011 - CSV format changed
24.03.2011 - Fixed CSV parser
03.01.2011 - getTransactions() allows listing from several account numbers at once
02.01.2011 - Accounting date in timestamp format
12.12.2010 - Little bugs
10.12.2010 - Works in SAFE_MODE
09.12.2010 - Added to download for free

Backlinks