TerminalClientMock.kt (3900B)
1 // This file is part of taler-cashless2ecash. 2 // Copyright (C) 2024 Joel Häberli 3 // 4 // taler-cashless2ecash is free software: you can redistribute it and/or modify it 5 // under the terms of the GNU Affero General Public License as published 6 // by the Free Software Foundation, either version 3 of the License, 7 // or (at your option) any later version. 8 // 9 // taler-cashless2ecash is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // 17 // SPDX-License-Identifier: AGPL3.0-or-later 18 19 package ch.bfh.habej2.wallee_c2ec.client.taler 20 21 import ch.bfh.habej2.wallee_c2ec.client.taler.encoding.CyptoUtils.encodeCrock 22 import ch.bfh.habej2.wallee_c2ec.client.taler.model.BankWithdrawalOperationStatus 23 import ch.bfh.habej2.wallee_c2ec.client.taler.model.TerminalApiConfig 24 import ch.bfh.habej2.wallee_c2ec.client.taler.model.TerminalWithdrawalConfirmationRequest 25 import ch.bfh.habej2.wallee_c2ec.client.taler.model.TerminalWithdrawalSetup 26 import ch.bfh.habej2.wallee_c2ec.client.taler.model.TerminalWithdrawalSetupResponse 27 import ch.bfh.habej2.wallee_c2ec.client.taler.model.WithdrawalOperationStatus 28 import java.security.SecureRandom 29 import java.util.Optional 30 31 class TerminalClientMock: TerminalClient { 32 33 override fun terminalsConfig(callback: (Optional<TerminalApiConfig>) -> Unit) = callback.invoke( 34 Optional.of( 35 TerminalApiConfig( 36 "taler-terminal", 37 "0:0:0", 38 "Wallee", 39 "CHF", 40 "CHF:0", 41 "wallee-transaction" 42 ) 43 ) 44 ) 45 46 override fun setupWithdrawal( 47 setupReq: TerminalWithdrawalSetup, 48 callback: (Optional<TerminalWithdrawalSetupResponse>) -> Unit 49 ) = callback.invoke( 50 Optional.of( 51 TerminalWithdrawalSetupResponse( 52 mockWopidOrReservePubKey() 53 ) 54 ) 55 ) 56 57 override fun retrieveWithdrawalStatus( 58 wopid: String, 59 longPollMs: Int, 60 oldState: WithdrawalOperationStatus, 61 callback: (Optional<BankWithdrawalOperationStatus>) -> Unit 62 ) { 63 64 Thread.sleep(longPollMs.toLong()) 65 callback.invoke( 66 Optional.of( 67 BankWithdrawalOperationStatus( 68 WithdrawalOperationStatus.selected, 69 "CHF:10", 70 // Amount(10,0), 71 // Amount(0,0), 72 // Amount(0,0), 73 "wallee-transaction", 74 // "http://mock.com/api", 75 // "http://mock.com/api", 76 // "", 77 "payto://IBAN/CH1111111111111", 78 mockWopidOrReservePubKey(), 79 "http://test.com", 80 Array(0) {""}, 81 mockWopidOrReservePubKey(), 82 false, 83 false, 84 false 85 ) 86 ) 87 ) 88 } 89 90 override fun sendConfirmationRequest( 91 encodedWopid: String, 92 confirmationRequest: TerminalWithdrawalConfirmationRequest, 93 callback: (Boolean) -> Unit 94 ) { 95 println("sending confirmation request") 96 } 97 98 override fun abortWithdrawal( 99 encodedWopid: String, 100 callback: (Boolean) -> Unit 101 ) { 102 println("aborting withdrawal") 103 } 104 105 override fun shutdownDispatcher() { 106 println("shutting down dispatcher") 107 } 108 109 private fun mockWopidOrReservePubKey(): String { 110 111 val wopid = ByteArray(32) 112 SecureRandom().nextBytes(wopid) 113 return encodeCrock(wopid) 114 } 115 }