Documentation fintech.sepa
SEPA module of the Python FinTech package.
This module defines functions and classes to work with SEPA.
Index- Account
- Amount
- SEPATransaction
- SEPACreditTransfer
- SEPADirectDebit
- CAMTDocument
- Mandate
- MandateManager
- class fintech.sepa.Account(iban, name, country=None, city=None, postcode=None, street=None)
Account class
Initializes the account instance.
- Parameters
- iban – Either the IBAN or a 2-tuple in the form of either (IBAN, BIC) or (ACCOUNT_NUMBER, BANK_CODE). The latter will be converted to the corresponding IBAN automatically. An IBAN is checked for validity.
- name – The name of the account holder.
- country – The country (ISO-3166 ALPHA 2) of the account holder (optional).
- city – The city of the account holder (optional).
- postcode – The postcode of the account holder (optional).
- street – The street of the account holder (optional).
- is_sepa()
Checks if this account seems to be valid within the Single Euro Payments Area. (added in v6.2.0)
- set_mandate(mref, signed, recurrent=False)
Sets the SEPA mandate for this account.
- Parameters
- mref – The mandate reference.
- signed – The date of signature. Can be a date object or an ISO8601 formatted string.
- recurrent – Flag whether this is a recurrent mandate or not.
- Returns
- A
Mandate
object.
- set_originator_id(cid=None, cuc=None)
Sets the originator id of the account holder (new in v6.1.1).
- Parameters
- cid – The SEPA creditor id. Required for direct debits and in some countries also for credit transfers.
- cuc – The CBI unique code (only required in Italy).
- set_ultimate_name(name)
Sets the ultimate name used for SEPA transactions and by the
MandateManager
.
- class fintech.sepa.Amount(value, currency=None)
The Amount class with an integrated currency converter.
Arithmetic operations can be performed directly on this object.
Initializes the Amount instance.
- Parameters
- value – The amount value.
- currency – An ISO-4217 currency code. If not specified,
it is set to the value of the class attribute
default_currency
which is initially set to EUR.
- convert(currency)
Converts the amount to another currency on the bases of the current exchange rates provided by the European Central Bank. The exchange rates are automatically updated once a day and cached in memory for further usage.
- Parameters
- currency – The ISO-4217 code of the target currency.
- Returns
- An
Amount
object in the requested currency.
- property decimals
The number of decimal places (at least 2). Use the built-in
round
to adjust the decimal places.
- classmethod update_exchange_rates()
Updates the exchange rates based on the data provided by the European Central Bank and stores it in the class attribute
exchange_rates
. Usually it is not required to call this method directly, since it is called automatically by the methodconvert()
.- Returns
- A boolean flag whether updated exchange rates were available or not.
- class fintech.sepa.SEPATransaction(*args, **kwargs)
The SEPATransaction class
This class cannot be instantiated directly. An instance is returned by the method
add_transaction()
of a SEPA document instance or by the iterator of aCAMTDocument
instance.If it is a batch of other transactions, the instance can be treated as an iterable over all underlying transactions.
- property amount
The transaction amount of type
Amount
. Debits are always signed negative.
- property classification
The transaction classification. For German banks it is a tuple in the form of (SWIFTCODE, GVC, PRIMANOTA, TEXTKEY), for Frensh banks a tuple in the form of (DOMAINCODE, FAMILYCODE, SUBFAMILYCODE, TRANSACTIONCODE), otherwise a plain string.
- get_account()
Returns an
Account
instance of the remote account.
- class fintech.sepa.SEPACreditTransfer(account, type='NORM', cutoff=14, batch=True, cat_purpose=None, scheme=None, currency=None)
SEPACreditTransfer class
Initializes the SEPA credit transfer instance.
- Parameters
- account – The local debtor account.
- type – The credit transfer priority (NORM, HIGH, URGP or INST). At time Instant Payments are only supported with scheme pain.001.001.03 (new in v6.2.0: INST, new in v7.0.0: URGP)
- cutoff – The cut-off time of the debtor’s bank.
- batch – Flag whether SEPA batch mode is enabled or not.
- cat_purpose – The SEPA category purpose code. This code is used for special treatments by the local bank and is not forwarded to the remote bank. See module attribute CATEGORY_PURPOSE_CODES for possible values.
- scheme – The PAIN scheme of the document. If not specified, the scheme is set to pain.001.001.03. In Switzerland it is set to pain.001.001.03.ch.02, in Italy to CBIPaymentRequest.00.04.00.
- currency – The ISO-4217 code of the currency to use. It must match with the currency of the local account. If not specified, it defaults to the currency of the country the local IBAN belongs to.
- add_transaction(account, amount, purpose, eref=None, ext_purpose=None, due_date=None)
Adds a transaction to the SEPACreditTransfer document. If
scl_check
is set toTrue
, it is verified that the transaction can be routed to the target bank.- Parameters
- account – The remote creditor account.
- amount – The transaction amount as floating point number
or an instance of
Amount
. In the latter case the currency must match the currency of the document. - purpose – The transaction purpose text. If the value matches a valid ISO creditor reference number (starting with “RF…”), it is added as a structured reference. For other structured references a tuple can be passed in the form of (REFERENCE_NUMBER, PURPOSE_TEXT).
- eref – The end-to-end reference (optional).
- ext_purpose – The SEPA external purpose code (optional). This code is forwarded to the remote bank and the account holder. See module attribute EXTERNAL_PURPOSE_CODES for possible values.
- due_date – The due date. If it is an integer or
None
, the next possible date is calculated starting from today plus the given number of days (considering holidays and the given cut-off time). If it is a date object or an ISO8601 formatted string, this date is used without further validation.
- Returns
- A
SEPATransaction
instance.
- new_batch(kref=None)
After calling this method additional transactions are added to a new batch (
PmtInf
block). This could be useful if you want to divide transactions into different batches with unique KREF ids.- Parameters
- kref – It is possible to set a custom KREF (
PmtInfId
) for the new batch (new in v7.2). Be aware that KREF ids should be unique over time and that all transactions must be grouped by particular SEPA specifications (date, sequence type, etc.) into separate batches. This is done automatically if you do not pass a custom KREF.
- property scl_check
Flag whether remote accounts should be verified against the SEPA Clearing Directory or not. The initial value is set to
True
if the kontocheck library is available and the local account is originated in Germany, otherwise it is set toFalse
.
- send(ebics_client, use_ful=None)
Sends the SEPA document using the passed EBICS instance.
- Parameters
- ebics_client – The
fintech.ebics.EbicsClient
instance. - use_ful – Flag, whether to use the order type
fintech.ebics.EbicsClient.FUL()
for uploading the document or one of the suitable order typesfintech.ebics.EbicsClient.CCT()
,fintech.ebics.EbicsClient.CDD()
orfintech.ebics.EbicsClient.CDB()
. If not specified, use_ful is set toFalse
if the local account is originated in Germany, otherwise it is set toTrue
. With EBICS v3.0 the document is always uploaded viafintech.ebics.EbicsClient.BTU()
.
- ebics_client – The
- Returns
- The EBICS order id.
- class fintech.sepa.SEPADirectDebit(account, type='CORE', cutoff=36, batch=True, cat_purpose=None, scheme=None, currency=None)
SEPADirectDebit class
Initializes the SEPA direct debit instance.
- Parameters
- account – The local creditor account with an appointed creditor id.
- type – The direct debit type (CORE or B2B).
- cutoff – The cut-off time of the creditor’s bank.
- batch – Flag if SEPA batch mode is enabled or not.
- cat_purpose – The SEPA category purpose code. This code is used for special treatments by the local bank and is not forwarded to the remote bank. See module attribute CATEGORY_PURPOSE_CODES for possible values.
- scheme – The PAIN scheme of the document. If not specified, the scheme is set to pain.008.001.02. In Switzerland it is set to pain.008.001.02.ch.01, in Italy to CBISDDReqLogMsg.00.01.00.
- currency – The ISO-4217 code of the currency to use. It must match with the currency of the local account. If not specified, it defaults to the currency of the country the local IBAN belongs to.
- add_transaction(account, amount, purpose, eref=None, ext_purpose=None, due_date=None)
Adds a transaction to the SEPADirectDebit document. If
scl_check
is set toTrue
, it is verified that the transaction can be routed to the target bank.- Parameters
- account – The remote debtor account with a valid mandate.
- amount – The transaction amount as floating point number
or an instance of
Amount
. In the latter case the currency must match the currency of the document. - purpose – The transaction purpose text. If the value matches a valid ISO creditor reference number (starting with “RF…”), it is added as a structured reference. For other structured references a tuple can be passed in the form of (REFERENCE_NUMBER, PURPOSE_TEXT).
- eref – The end-to-end reference (optional).
- ext_purpose – The SEPA external purpose code (optional). This code is forwarded to the remote bank and the account holder. See module attribute EXTERNAL_PURPOSE_CODES for possible values.
- due_date – The due date. If it is an integer or
None
, the next possible date is calculated starting from today plus the given number of days (considering holidays, the lead time and the given cut-off time). If it is a date object or an ISO8601 formatted string, this date is used without further validation.
- Returns
- A
SEPATransaction
instance.
- new_batch(kref=None)
After calling this method additional transactions are added to a new batch (
PmtInf
block). This could be useful if you want to divide transactions into different batches with unique KREF ids.- Parameters
- kref – It is possible to set a custom KREF (
PmtInfId
) for the new batch (new in v7.2). Be aware that KREF ids should be unique over time and that all transactions must be grouped by particular SEPA specifications (date, sequence type, etc.) into separate batches. This is done automatically if you do not pass a custom KREF.
- property scl_check
Flag whether remote accounts should be verified against the SEPA Clearing Directory or not. The initial value is set to
True
if the kontocheck library is available and the local account is originated in Germany, otherwise it is set toFalse
.
- send(ebics_client, use_ful=None)
Sends the SEPA document using the passed EBICS instance.
- Parameters
- ebics_client – The
fintech.ebics.EbicsClient
instance. - use_ful – Flag, whether to use the order type
fintech.ebics.EbicsClient.FUL()
for uploading the document or one of the suitable order typesfintech.ebics.EbicsClient.CCT()
,fintech.ebics.EbicsClient.CDD()
orfintech.ebics.EbicsClient.CDB()
. If not specified, use_ful is set toFalse
if the local account is originated in Germany, otherwise it is set toTrue
. With EBICS v3.0 the document is always uploaded viafintech.ebics.EbicsClient.BTU()
.
- ebics_client – The
- Returns
- The EBICS order id.
- class fintech.sepa.CAMTDocument(xml, camt54=None)
The CAMTDocument class is used to parse CAMT52, CAMT53 or CAMT54 documents. An instance can be treated as an iterable over its transactions, each represented as an instance of type
SEPATransaction
.Note: If orders were submitted in batch mode, there are three methods to resolve the underlying transactions. Either (A) directly within the CAMT52/CAMT53 document, (B) within a separate CAMT54 document or (C) by a reference to the originally transfered PAIN message. The applied method depends on the bank (method B is most commonly used).
Initializes the CAMTDocument instance.
- Parameters
- xml – The XML string of a CAMT document to be parsed (either CAMT52, CAMT53 or CAMT54).
- camt54 – In case xml is a CAMT52 or CAMT53 document, an additional CAMT54 document or a sequence of such documents can be passed which are automatically merged with the corresponding batch transactions.
- property balance_close
The closing balance of type
Amount
(read-only).
- property balance_open
The opening balance of type
Amount
(read-only).
- class fintech.sepa.Mandate(path)
SEPA mandate class.
Initializes the SEPA mandate instance.
- Parameters
- path – The path to a SEPA PDF file.
- class fintech.sepa.MandateManager(path, account)
A MandateManager manages all SEPA mandates that are required for SEPA direct debit transactions.
It stores all mandates as PDF files in a given directory.
Warning
The MandateManager is still BETA. Don’t use for production!
Initializes the mandate manager instance.
- Parameters
- path – The path to a directory where all mandates are stored. If it does not exist it will be created.
- account – The creditor account with the full address and an appointed creditor id.
- add_mandate(account, mref=None, signature=None, recurrent=True, b2b=False, lang=None)
Adds a new SEPA mandate and creates the corresponding PDF file. If
scl_check
is set toTrue
, it is verified that a direct debit transaction can be routed to the target bank.- Parameters
- account – The debtor account with the full address.
- mref – The mandate reference. If not specified, a new reference number will be created.
- signature – The signature which must be the full name
of the account holder. If given, the mandate is marked
as signed. Otherwise the method
sign_mandate()
must be called before the mandate can be used for a direct debit. - recurrent – Flag if it is a recurrent mandate or not.
- b2b – Flag if it is a B2B mandate or not.
- lang – ISO 639-1 language code of the mandate to create. Defaults to the language of the account holder’s country.
- Returns
- The created or passed mandate reference.
- archive_mandates(zipfile)
Archives all closed SEPA mandates.
Currently not implemented!
- Parameters
- zipfile – The path to a zip file.
- get_account(mref)
Get the debtor account of a SEPA mandate.
- Parameters
- mref – The mandate reference.
- Returns
- A
Account
object.
- get_mandate(mref)
Get a stored SEPA mandate.
- Parameters
- mref – The mandate reference.
- Returns
- A
Mandate
object.
- get_pdf(mref, save_as=None)
Get the PDF document of a SEPA mandate.
All SEPA meta data is removed from the PDF.
- Parameters
- mref – The mandate reference.
- save_as – If given, it must be the destination path where the PDF file is saved.
- Returns
- The raw PDF data.
- property scl_check
Flag whether remote accounts should be verified against the SEPA Clearing Directory or not. The initial value is set to
True
if the kontocheck library is available and the local account is originated in Germany, otherwise it is set toFalse
.
- sign_mandate(document, mref=None, signed=None)
Updates a SEPA mandate with a signed document.
- Parameters
- document – The path to the signed document, which can be an image or PDF file.
- mref – The mandate reference. If not specified and document points to an image, the image is scanned for a Code39 barcode which represents the mandate reference.
- signed – The date of signature. If not specified, the current date is used.
- Returns
- The mandate reference.