-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from tillhub/feature/UNTIL-12204/s-pos_impleme…
…ntation [UNTIL-12204] SPOS implementation
- Loading branch information
Showing
53 changed files
with
3,641 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
payment-engine/src/main/java/de/tillhub/paymentengine/ConnectionManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.tillhub.paymentengine | ||
|
||
import androidx.activity.result.ActivityResultCaller | ||
import androidx.activity.result.ActivityResultLauncher | ||
import de.tillhub.paymentengine.contract.TerminalConnectContract | ||
import de.tillhub.paymentengine.contract.TerminalDisconnectContract | ||
import de.tillhub.paymentengine.data.Terminal | ||
import de.tillhub.paymentengine.data.TerminalOperationStatus | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
|
||
/** | ||
* This is called to start of S-POS terminal connect and disconnect, | ||
* it sets up the manager so the connection to the terminal is viable. | ||
*/ | ||
interface ConnectionManager : CardManager { | ||
fun startSPOSConnect() | ||
fun startSPOSConnect(configName: String) | ||
fun startSPOSConnect(config: Terminal) | ||
|
||
fun startSPOSDisconnect() | ||
fun startSPOSDisconnect(configName: String) | ||
fun startSPOSDisconnect(config: Terminal) | ||
} | ||
|
||
internal class ConnectionManagerImpl( | ||
configs: MutableMap<String, Terminal>, | ||
terminalState: MutableStateFlow<TerminalOperationStatus>, | ||
resultCaller: ActivityResultCaller, | ||
private val connectContract: ActivityResultLauncher<Terminal> = | ||
resultCaller.registerForActivityResult(TerminalConnectContract()) { result -> | ||
terminalState.tryEmit(result) | ||
}, | ||
private val disconnectContract: ActivityResultLauncher<Terminal> = | ||
resultCaller.registerForActivityResult(TerminalDisconnectContract()) { result -> | ||
terminalState.tryEmit(result) | ||
} | ||
) : CardManagerImpl(configs, terminalState), ConnectionManager { | ||
|
||
override fun startSPOSConnect() { | ||
val configName = configs.values.firstOrNull()?.name.orEmpty() | ||
startSPOSConnect(configName) | ||
} | ||
|
||
override fun startSPOSConnect(configName: String) { | ||
val terminalConfig = configs.getOrDefault(configName, defaultConfig) | ||
startSPOSConnect(terminalConfig) | ||
} | ||
|
||
override fun startSPOSConnect(config: Terminal) { | ||
terminalState.tryEmit(TerminalOperationStatus.Pending.Connecting) | ||
connectContract.launch(config) | ||
} | ||
|
||
override fun startSPOSDisconnect() { | ||
val configName = configs.values.firstOrNull()?.name.orEmpty() | ||
startSPOSDisconnect(configName) | ||
} | ||
|
||
override fun startSPOSDisconnect(configName: String) { | ||
val terminalConfig = configs.getOrDefault(configName, defaultConfig) | ||
startSPOSDisconnect(terminalConfig) | ||
} | ||
|
||
override fun startSPOSDisconnect(config: Terminal) { | ||
terminalState.tryEmit(TerminalOperationStatus.Pending.Disconnecting) | ||
disconnectContract.launch(config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.