English Deutsch

Implement protocol version H003

To support EBICS protocol version H003 you must generate the required order ids by yourself. Therefore you have to subclass EbicsBank as follows:

import fintech
fintech.register()

from fintech.ebics import EbicsBank

class MyBank(EbicsBank):

    def _next_order_id(self, partnerid):
        # Generate an order id uniquely for each partner id
        # Must be a string between 'A000' and 'ZZZZ'
        return generate_order_id(partnerid)

Here is a working example storing all order ids in a JSON file (be aware that this example is not thread-save):

import os
import json

import fintech
fintech.register()

from fintech.ebics import EbicsBank


def b36encode(number):
    chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    base36 = ''
    while number:
        number, i = divmod(number, 36)
        base36 = chars[i] + base36
    return base36 or '0'

def b36decode(number):
    return int(number, 36)


class MyBank(EbicsBank):

    order_ids_path = '/path/to/order_ids.json'

    def _next_order_id(self, partnerid):
        """
        Generate an order id uniquely for each partner id
        Must be a string between 'A000' and 'ZZZZ'
        """
        if not os.path.exists(self.order_ids_path):
            with open(self.order_ids_path, 'w') as fh:
                fh.write('{}')

        with open(self.order_ids_path, 'r+') as fh:
            order_ids = json.load(fh)
            order_id = order_ids.setdefault(partnerid, 'A000')
            diff = (b36decode(order_id) - 466559) % 1213056
            order_ids[partnerid] = b36encode(466560 + diff)
            fh.truncate(0)
            fh.seek(0)
            json.dump(order_ids, fh, indent=4)

        return order_id