def refill(card,amount): ''' Refills card with journey contract inside reader field. `card` argument should be valid card in active state with transport_card.validate performed on it. `amount` - summ in cents to be added to transport purse, converted to journeys and subsequently removed from transport purse. ''' sector = card.sector(num=SECTOR,key=KEY,enc=ENCRYPTION) contract = CONTRACT_A.validate(sector,CONTRACT1_STATIC,CONTRACT1_DYNAMIC) purse_value = purse.change_value(card,amount) if purse_value < JOURNEY_COST: return 0 amount_used = contract.dynamic.refill(purse_value) purse.change_value(card,-amount_used) event = EVENT_CONTRACT_ADD2(card) event.AID,event.PIX = AID,PIX event.Value = contract.dynamic.journeys event.TransactionValue = amount_used / JOURNEY_COST event.Amount = amount_used event.LocalTransactions = contract.dynamic.transaction try: card.auth(sector) contract.commit(low_endian = 1) sector.write(blocks=(1,2)) except Exception as e: event.set_error_code(e); raise finally: event.save(card) return amount_used
def change_value(card,amount): event = EVENT_WALLET_OPERATION2(card,amount) purse_sector = card.sector(num=10,key=5,method='full') contract = CONTRACT_A.validate(purse_sector,PURSE_STATIC_DATA,PURSE_DYNAMIC_DATA) if not amount: return contract.dynamic.value contract.dynamic.refill(amount) event.LocalTransactions = contract.dynamic.transaction event.Value = contract.dynamic.value try: contract.commit(low_endian=0) purse_sector.write(blocks=(1,2)) return contract.dynamic.value except Exception as e: event.set_error_code(e) raise finally: if event.Amount: event.save(card)
def read(card): sector = card.sector(num=SECTOR,key=KEY,enc=ENCRYPTION) contract = CONTRACT_A.validate(sector,CONTRACT1_STATIC,CONTRACT1_DYNAMIC) return contract.dynamic.to_dict()
def read(card): sector = card.sector(num = SECTOR, key = KEY, method = 'full') contract = CONTRACT_A.validate(sector, CONTRACT0_STATIC, CONTRACT0_DYNAMIC) return contract.static.to_dict()
def get_value(card): purse_sector = card.sector(num=SECTOR,key=KEY,method='full') contract = CONTRACT_A.validate(purse_sector,PURSE_STATIC_DATA,PURSE_DYNAMIC_DATA) return contract.dynamic.value