Skip to content

Commit

Permalink
added handling of SPOS app not being present
Browse files Browse the repository at this point in the history
  • Loading branch information
SloInfinity committed Nov 22, 2024
1 parent 35ce605 commit 4566199
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 23 deletions.
2 changes: 1 addition & 1 deletion payment-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ afterEvaluate {
create<MavenPublication>("payment-engine") {
groupId = "de.tillhub.paymentengine"
artifactId = "payment-engine"
version = "3.0.0"
version = "3.0.1"

from(components.getByName("release"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package de.tillhub.paymentengine

import android.content.ActivityNotFoundException
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.ResultCodeSets
import de.tillhub.paymentengine.data.Terminal
import de.tillhub.paymentengine.data.TerminalOperationStatus
import kotlinx.coroutines.flow.MutableStateFlow
import java.time.Instant

/**
* This is called to start of S-POS terminal connect and disconnect,
Expand Down Expand Up @@ -48,7 +51,20 @@ internal class ConnectionManagerImpl(

override fun startSPOSConnect(config: Terminal) {
terminalState.tryEmit(TerminalOperationStatus.Pending.Connecting)
connectContract.launch(config)
try {
connectContract.launch(config)
} catch (_: ActivityNotFoundException) {
terminalState.tryEmit(
TerminalOperationStatus.Error.SPOS(
date = Instant.now(),
customerReceipt = "",
merchantReceipt = "",
rawData = "",
data = null,
resultCode = ResultCodeSets.APP_NOT_FOUND_ERROR
)
)
}
}

override fun startSPOSDisconnect() {
Expand All @@ -63,6 +79,19 @@ internal class ConnectionManagerImpl(

override fun startSPOSDisconnect(config: Terminal) {
terminalState.tryEmit(TerminalOperationStatus.Pending.Disconnecting)
disconnectContract.launch(config)
try {
disconnectContract.launch(config)
} catch (_: ActivityNotFoundException) {
terminalState.tryEmit(
TerminalOperationStatus.Error.SPOS(
date = Instant.now(),
customerReceipt = "",
merchantReceipt = "",
rawData = "",
data = null,
resultCode = ResultCodeSets.APP_NOT_FOUND_ERROR
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package de.tillhub.paymentengine

import android.content.ActivityNotFoundException
import androidx.activity.result.ActivityResultCaller
import androidx.activity.result.ActivityResultLauncher
import de.tillhub.paymentengine.contract.PaymentRequest
import de.tillhub.paymentengine.contract.PaymentResultContract
import de.tillhub.paymentengine.data.ISOAlphaCurrency
import de.tillhub.paymentengine.data.ResultCodeSets
import de.tillhub.paymentengine.data.Terminal
import de.tillhub.paymentengine.data.TerminalOperationStatus
import kotlinx.coroutines.flow.MutableStateFlow
import java.math.BigDecimal
import java.time.Instant

/**
* This is called to start of a card payment transaction,
Expand Down Expand Up @@ -78,8 +81,21 @@ internal class PaymentManagerImpl(
config: Terminal
) {
terminalState.tryEmit(TerminalOperationStatus.Pending.Payment(amount, currency))
paymentResultContract.launch(
PaymentRequest(config, transactionId, amount, tip, currency)
)
try {
paymentResultContract.launch(
PaymentRequest(config, transactionId, amount, tip, currency)
)
} catch (_: ActivityNotFoundException) {
terminalState.tryEmit(
TerminalOperationStatus.Error.SPOS(
date = Instant.now(),
customerReceipt = "",
merchantReceipt = "",
rawData = "",
data = null,
resultCode = ResultCodeSets.APP_NOT_FOUND_ERROR
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package de.tillhub.paymentengine

import android.content.ActivityNotFoundException
import androidx.activity.result.ActivityResultCaller
import androidx.activity.result.ActivityResultLauncher
import de.tillhub.paymentengine.contract.TerminalReconciliationContract
import de.tillhub.paymentengine.data.ResultCodeSets
import de.tillhub.paymentengine.data.Terminal
import de.tillhub.paymentengine.data.TerminalOperationStatus
import kotlinx.coroutines.flow.MutableStateFlow
import java.time.Instant

/**
* This is called to start of a terminal reconciliation,
Expand Down Expand Up @@ -39,6 +42,19 @@ internal class ReconciliationManagerImpl(

override fun startReconciliation(config: Terminal) {
terminalState.tryEmit(TerminalOperationStatus.Pending.Reconciliation)
reconciliationContract.launch(config)
try {
reconciliationContract.launch(config)
} catch (_: ActivityNotFoundException) {
terminalState.tryEmit(
TerminalOperationStatus.Error.SPOS(
date = Instant.now(),
customerReceipt = "",
merchantReceipt = "",
rawData = "",
data = null,
resultCode = ResultCodeSets.APP_NOT_FOUND_ERROR
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package de.tillhub.paymentengine

import android.content.ActivityNotFoundException
import androidx.activity.result.ActivityResultCaller
import androidx.activity.result.ActivityResultLauncher
import de.tillhub.paymentengine.contract.PaymentRefundContract
import de.tillhub.paymentengine.contract.RefundRequest
import de.tillhub.paymentengine.data.ISOAlphaCurrency
import de.tillhub.paymentengine.data.ResultCodeSets
import de.tillhub.paymentengine.data.Terminal
import de.tillhub.paymentengine.data.TerminalOperationStatus
import kotlinx.coroutines.flow.MutableStateFlow
import java.math.BigDecimal
import java.time.Instant

/**
* This is called to start of a partial card payment refund,
Expand Down Expand Up @@ -73,13 +76,26 @@ internal class RefundManagerImpl(
config: Terminal
) {
terminalState.tryEmit(TerminalOperationStatus.Pending.Refund(amount, currency))
refundContract.launch(
RefundRequest(
config = config,
transactionId = transactionId,
amount = amount,
currency = currency
try {
refundContract.launch(
RefundRequest(
config = config,
transactionId = transactionId,
amount = amount,
currency = currency
)
)
)
} catch (_: ActivityNotFoundException) {
terminalState.tryEmit(
TerminalOperationStatus.Error.SPOS(
date = Instant.now(),
customerReceipt = "",
merchantReceipt = "",
rawData = "",
data = null,
resultCode = ResultCodeSets.APP_NOT_FOUND_ERROR
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package de.tillhub.paymentengine

import android.content.ActivityNotFoundException
import androidx.activity.result.ActivityResultCaller
import androidx.activity.result.ActivityResultLauncher
import de.tillhub.paymentengine.contract.PaymentReversalContract
import de.tillhub.paymentengine.contract.ReversalRequest
import de.tillhub.paymentengine.data.ISOAlphaCurrency
import de.tillhub.paymentengine.data.ResultCodeSets
import de.tillhub.paymentengine.data.Terminal
import de.tillhub.paymentengine.data.TerminalOperationStatus
import kotlinx.coroutines.flow.MutableStateFlow
import java.math.BigDecimal
import java.time.Instant

/**
* This is called to start of a card payment reversal,
Expand All @@ -23,6 +26,7 @@ interface ReversalManager : CardManager {
receiptNo: String
)

@Suppress("LongParameterList")
fun startReversalTransaction(
transactionId: String,
amount: BigDecimal,
Expand All @@ -32,6 +36,7 @@ interface ReversalManager : CardManager {
receiptNo: String,
)

@Suppress("LongParameterList")
fun startReversalTransaction(
transactionId: String,
amount: BigDecimal,
Expand Down Expand Up @@ -98,15 +103,28 @@ internal class ReversalManagerImpl(
receiptNo: String
) {
terminalState.tryEmit(TerminalOperationStatus.Pending.Reversal(receiptNo))
reversalContract.launch(
ReversalRequest(
transactionId = transactionId,
amount = amount,
tip = tip,
currency = currency,
config = config,
receiptNo = receiptNo
try {
reversalContract.launch(
ReversalRequest(
transactionId = transactionId,
amount = amount,
tip = tip,
currency = currency,
config = config,
receiptNo = receiptNo
)
)
)
} catch (_: ActivityNotFoundException) {
terminalState.tryEmit(
TerminalOperationStatus.Error.SPOS(
date = Instant.now(),
customerReceipt = "",
merchantReceipt = "",
rawData = "",
data = null,
resultCode = ResultCodeSets.APP_NOT_FOUND_ERROR
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ internal sealed class ResultCodeSets<T>(val mapping: Map<T, TransactionResultCod

companion object {
private const val UNKNOWN_RESULT_CODE = -1
val APP_NOT_FOUND_ERROR = TransactionResultCode.Known(R.string.spos_error_app_not_found)

fun getZVTCode(resultCode: Int?): TransactionResultCode {
return LavegoResultCodes.mapping.getOrDefault(
Expand Down
1 change: 1 addition & 0 deletions payment-engine/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,5 @@
<string name="spos_error_terminal_already_activated">Terminal already activated</string>
<string name="spos_error_validation_error">Validation error</string>
<string name="spos_error_unknown">Unknown terminal error</string>
<string name="spos_error_app_not_found">Terminal application not found on device</string>
</resources>

0 comments on commit 4566199

Please sign in to comment.