pendingTransactions
This commit is contained in:
parent
7c41fd4340
commit
8ae270b625
@ -1,6 +1,9 @@
|
|||||||
package com.example.mypos.data
|
package com.example.mypos.data
|
||||||
|
|
||||||
object AditumError {
|
object AditumError {
|
||||||
|
const val INVALID_AMOUNT_MESSAGE = "Adjusted amount must be greater than zero"
|
||||||
|
const val INVALID_AMOUNT = "INVALID_AMOUNT"
|
||||||
|
|
||||||
const val SERVICE_NOT_AVAILABLE = "SERVICE_NOT_AVAILABLE"
|
const val SERVICE_NOT_AVAILABLE = "SERVICE_NOT_AVAILABLE"
|
||||||
const val SERVICE_NOT_AVAILABLE_MESSAGE = "Failed to connect to Aditum SDK service"
|
const val SERVICE_NOT_AVAILABLE_MESSAGE = "Failed to connect to Aditum SDK service"
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import android.util.Log
|
|||||||
import br.com.aditum.data.v2.enums.InstallmentType
|
import br.com.aditum.data.v2.enums.InstallmentType
|
||||||
import br.com.aditum.data.v2.enums.PayOperationType
|
import br.com.aditum.data.v2.enums.PayOperationType
|
||||||
import br.com.aditum.data.v2.enums.PaymentType
|
import br.com.aditum.data.v2.enums.PaymentType
|
||||||
|
import br.com.aditum.data.v2.model.Charge
|
||||||
import br.com.aditum.data.v2.model.MerchantData
|
import br.com.aditum.data.v2.model.MerchantData
|
||||||
import br.com.aditum.data.v2.model.PinpadMessages
|
import br.com.aditum.data.v2.model.PinpadMessages
|
||||||
import br.com.aditum.data.v2.model.cancelation.CancelationRequest
|
import br.com.aditum.data.v2.model.cancelation.CancelationRequest
|
||||||
@ -17,13 +18,14 @@ import br.com.aditum.data.v2.model.payment.PaymentRequest
|
|||||||
import br.com.aditum.data.v2.model.payment.PaymentResponse
|
import br.com.aditum.data.v2.model.payment.PaymentResponse
|
||||||
import br.com.aditum.data.v2.model.payment.PaymentResponseCallback
|
import br.com.aditum.data.v2.model.payment.PaymentResponseCallback
|
||||||
import br.com.aditum.data.v2.model.transactions.ConfirmTransactionCallback
|
import br.com.aditum.data.v2.model.transactions.ConfirmTransactionCallback
|
||||||
|
import br.com.aditum.data.v2.model.transactions.PendingTransactionsCallback
|
||||||
import com.example.mypos.BuildConfig
|
import com.example.mypos.BuildConfig
|
||||||
import com.example.mypos.data.AditumError
|
import com.example.mypos.data.AditumError
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.util.UUID
|
|
||||||
class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "AditumSdkModule"
|
private const val TAG = "AditumSdkModule"
|
||||||
@ -104,6 +106,7 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
|||||||
installments: Int = 0,
|
installments: Int = 0,
|
||||||
paymentType: PaymentType,
|
paymentType: PaymentType,
|
||||||
allowContactless: Boolean = true,
|
allowContactless: Boolean = true,
|
||||||
|
amountSeasoning: ((Long) -> Long)? = null,
|
||||||
resolve: (PaymentResponse) -> Unit = {},
|
resolve: (PaymentResponse) -> Unit = {},
|
||||||
reject: (String, String?) -> Unit = { _, _ -> }
|
reject: (String, String?) -> Unit = { _, _ -> }
|
||||||
) {
|
) {
|
||||||
@ -114,6 +117,12 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val adjustedAmount = amountSeasoning?.invoke(amount) ?: amount
|
||||||
|
if (adjustedAmount <= 0) {
|
||||||
|
reject(AditumError.INVALID_AMOUNT, AditumError.INVALID_AMOUNT_MESSAGE)
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
val paymentRequest = PaymentRequest().apply {
|
val paymentRequest = PaymentRequest().apply {
|
||||||
currency = 986
|
currency = 986
|
||||||
operationType = PayOperationType.Authorization
|
operationType = PayOperationType.Authorization
|
||||||
@ -146,7 +155,7 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun confirm(nsu: String?, resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) {
|
fun confirm(nsu: String, resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
if (!paymentApplication.ensureServiceConnected()) {
|
if (!paymentApplication.ensureServiceConnected()) {
|
||||||
@ -154,11 +163,6 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsu == null) {
|
|
||||||
reject(AditumError.INVALID_NSU, AditumError.INVALID_NSU_MESSAGE)
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
val callback = object : ConfirmTransactionCallback.Stub() {
|
val callback = object : ConfirmTransactionCallback.Stub() {
|
||||||
override fun onResponse(confirmed: Boolean) {
|
override fun onResponse(confirmed: Boolean) {
|
||||||
resolve(confirmed)
|
resolve(confirmed)
|
||||||
@ -173,7 +177,7 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancel(nsu: String?, isReversal: Boolean, resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) {
|
fun cancel(nsu: String, isReversal: Boolean, resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
if (!paymentApplication.ensureServiceConnected()) {
|
if (!paymentApplication.ensureServiceConnected()) {
|
||||||
@ -181,11 +185,6 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsu == null) {
|
|
||||||
reject(AditumError.INVALID_NSU, AditumError.INVALID_NSU_MESSAGE)
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
val cancelationRequest = CancelationRequest(nsu, isReversal)
|
val cancelationRequest = CancelationRequest(nsu, isReversal)
|
||||||
|
|
||||||
val callback = object : CancelationResponseCallback.Stub() {
|
val callback = object : CancelationResponseCallback.Stub() {
|
||||||
@ -219,6 +218,30 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun pendingTransactions(resolve: (List<Charge?>?) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ ->}) {
|
||||||
|
coroutineScope.launch {
|
||||||
|
try {
|
||||||
|
if (!paymentApplication.ensureServiceConnected()) {
|
||||||
|
reject(AditumError.SERVICE_NOT_AVAILABLE, AditumError.SERVICE_NOT_AVAILABLE_MESSAGE)
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
val callback = object : PendingTransactionsCallback.Stub() {
|
||||||
|
override fun onResponse(results: List<Charge?>?) {
|
||||||
|
val json = gson.toJson(results)
|
||||||
|
Log.e(TAG, "onResponse - $json")
|
||||||
|
resolve(results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paymentApplication.communicationService?.pendingTransactions(callback)
|
||||||
|
?: reject(AditumError.SERVICE_NULL, AditumError.SERVICE_NULL_MESSAGE)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
reject(AditumError.CONFIRM_ERROR, "${AditumError.CONFIRM_ERROR_MESSAGE}: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun deactivate(resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) {
|
fun deactivate(resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user