コード例 #1
0
    def wrapper(transaction_data):
        terminal_id = transaction_data['terminal_id']
        session = database.get_session(terminal_id)
        if session is None:
            _process_unregistered_terminal_id(transaction_data)

        return f(transaction_data)
コード例 #2
0
def _process_test_rq(transaction_data):
    """ Handle TO, create session for terminal or
    respond with '00' if one created earlier """

    terminal_id = transaction_data['terminal_id']
    session = database.get_session(terminal_id)
    if session is None:
        database.post_session(Session(terminal_id))

    transaction_data['bitmap'] = Bitmap.test_rs()
    transaction_data['transaction_id'] = action_codes['test']
    return _process_accepted_and_implemented(transaction_data)
コード例 #3
0
def _process_refund_rs(transaction_data):
    transaction_data['bitmap'] = Bitmap.sale_rs()
    terminal_id = transaction_data['terminal_id']

    card = database.get_card(transaction_data['PAN'])
    amount = transaction_data['amount']
    refund_amount = int(amount[:-2]) + float(amount[-2:]) / 100

    session = database.get_session(terminal_id)
    session.add_refund(refund_amount)
    card.deposit(refund_amount)
    database.save_state()

    transaction_data['transaction_id'] = action_codes['refund']
    return _process_accepted_and_implemented(transaction_data)
コード例 #4
0
def _process_settlement_rq(transaction_data):
    transaction_data['bitmap'] = Bitmap.settlement_rs()
    transaction_data['transaction_id'] = action_codes['settlement']

    terminal_id = transaction_data['terminal_id']
    text_data = transaction_data['text_data']

    session = database.get_session(terminal_id)
    session_text_data = Transaction._format_text_data(session.sales_count,
                                                      session.sales_amount,
                                                      session.refund_count,
                                                      session.refund_amount)
    if session_text_data != text_data:
        _process_revision_error(transaction_data)

    _process_accepted_and_implemented(transaction_data)
コード例 #5
0
def _process_sale_rq(transaction_data):
    transaction_data['bitmap'] = Bitmap.sale_rs()
    terminal_id = transaction_data['terminal_id']

    card = database.get_card(transaction_data['PAN'])
    amount = transaction_data['amount']
    sell_amount = int(amount[:-2]) + float(amount[-2:]) / 100

    if card.balance < sell_amount:
        return _process_insufficient_funds(transaction_data)

    session = database.get_session(terminal_id)
    session.add_sell(sell_amount)
    card.buy(sell_amount)
    database.save_state()

    transaction_data['transaction_id'] = action_codes['sale']
    return _process_accepted_and_implemented(transaction_data)