예제 #1
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)
예제 #2
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)