From 7c41fd4340d0649bac291d57ac855d139f071bec Mon Sep 17 00:00:00 2001 From: Ighor Moura Date: Mon, 21 Jul 2025 18:06:10 -0400 Subject: [PATCH] melhorando pay --- .idea/.name | 1 + .../mypos/services/AditumSdkService.kt | 35 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 .idea/.name diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..3fe0597 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +POS \ No newline at end of file diff --git a/app/src/main/java/com/example/mypos/services/AditumSdkService.kt b/app/src/main/java/com/example/mypos/services/AditumSdkService.kt index 21e319b..648ec99 100644 --- a/app/src/main/java/com/example/mypos/services/AditumSdkService.kt +++ b/app/src/main/java/com/example/mypos/services/AditumSdkService.kt @@ -100,10 +100,11 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) { } fun pay( - amount: Int, - installments: Int, - merchantChargeId: String?, - resolve: (Any) -> Unit = {}, + amount: Long, + installments: Int = 0, + paymentType: PaymentType, + allowContactless: Boolean = true, + resolve: (PaymentResponse) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> } ) { coroutineScope.launch { @@ -114,14 +115,13 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) { } val paymentRequest = PaymentRequest().apply { - operationType = PayOperationType.Authorization - paymentType = PaymentType.Credit - this.amount = amount.toLong() - this.merchantChargeId = merchantChargeId ?: UUID.randomUUID().toString() currency = 986 - allowContactless = true + operationType = PayOperationType.Authorization + this.paymentType = paymentType + this.amount = amount + this.allowContactless = allowContactless manualEntry = false - installmentType = InstallmentType.Merchant + installmentType = if (paymentType == PaymentType.Debit) InstallmentType.None else InstallmentType.Merchant installmentNumber = installments } @@ -129,7 +129,8 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) { override fun onResponse(paymentResponse: PaymentResponse?) { if (paymentResponse != null) { val json = gson.toJson(paymentResponse) - resolve(json) + Log.e(TAG, "onResponse - $json") + resolve(paymentResponse) } else { Log.e(TAG, "onResponse - paymentResponse is null") reject(AditumError.PAYMENT_RESPONSE_NULL, AditumError.PAYMENT_RESPONSE_NULL_MESSAGE) @@ -206,6 +207,18 @@ class AditumSdkService(private val paymentApplication: PaymentApplication) { } } + fun aboutOperation(resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) { + coroutineScope.launch { + if (!paymentApplication.ensureServiceConnected()) { + reject(AditumError.SERVICE_NOT_AVAILABLE, AditumError.SERVICE_NOT_AVAILABLE_MESSAGE) + return@launch + } + + paymentApplication.communicationService?.abortOperation() + + } + } + fun deactivate(resolve: (Boolean) -> Unit = {}, reject: (String, String?) -> Unit = { _, _ -> }) { coroutineScope.launch { try {