#aneeb_code

1 messages ยท Page 1 of 1 (latest)

slate cryptBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1433387999886053417

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

twilit spoke
#

hey there ๐Ÿ‘‹ taking a look at your question

twilit spoke
slate cryptBOT
dense loom
#

Not reconnect I try to connect it normally

pseudo plover
#

Can you try cancelling the transaction using the Cancelable object that's returned from Terminal.getInstance().collectPaymentMethod?

dense loom
#

private fun collectPaymentMethod(intent: PaymentIntent) {
paymentCancellable = Terminal.getInstance().collectPaymentMethod(
callback = collectPaymentIntentCallback,
intent = intent,
config = paymentCollectionConfig
)
}

this is the collectPaymentMethod i am using

pseudo plover
#

Can you perhaps outline the flow here to clarify things for me? Are you listening for disconnect callbacks? Are you using autoReconnectOnUnexpectedDisconnect? How do you detect the disconnect, and what code runs at that point?

dense loom
#

sure

slate cryptBOT
dense loom
#

when there is any exception occur I clear the payment by calling below method

private fun cancelCurrentTransaction() {
if (isCancelling) return
isCancelling = true

    paymentCancellable?.let {
        it.cancel(paymentCancellationCallback)
    } ?: run {
        safeResetTerminal()
        _cancellationState.value = true
        isCancelling = false
    }
}

and when I try to initiate another payment, I setCardReaderWithLocation

fun setupCardReaderWithLocation() {
val locationMap = getOrgData()?.organizationTerminalLocations
val subscriberId = orgDetailsRM?.subscriberConnectedAccountId ?: getStripeData()?.stripeId

    if (locationMap.isNullOrEmpty() || subscriberId == null) {
        getLocation()
        return
    }

    val existingLocationId = locationMap[subscriberId]
    if (existingLocationId != null) {
        locationId = existingLocationId
        connectToCardRead()
    } else {
        getLocation()
    }
}

after that I try to initialize the card reader because our category or account gets changed that's why we have to initialize it again

#

private fun initialize() {
//val savedLocationId = PreferencesManager.getString(AppConstants.KEY_LOCATION_ID, "")
//if (savedLocationId == null && savedLocationId != locationId) {
//PreferencesManager.putString(AppConstants.KEY_LOCATION_ID, locationId)
if (canInitializeTerminal.get()) {
paymentManager.init(
connectionType = paymentManager.getSavedConnectionType(),
locationId = locationId,
connectedAccountId = instance?.orgDetailsRM?.subscriberConnectedAccountId
?: getStripeData()?.stripeId.default,
userToken = getUserData()?.jwtToken.default,
organizationId = getUserData()?.organizationId.default
)
} else {
startDonating()
}
//}
}

#

then we call it our web API to create a payment intent and after it's success I call handleDonateApiSuccess

private fun handleDonateApiSuccess(data: DonateRes?) {
try {
if (data != null) {
EventLog.logErrorResponse(
event = "handleDonateApiSuccess",
errorResponse = Gson().toJson(data)
)
sendLog("handleDonateApiSuccess process payment: " + Gson().toJson(data))
donationId = data.donationId
paymentManager.processPayment(data.paymentIntentId)
}

    } catch (e: Exception) {
        e.printStackTrace()
        sendLog("Exception::: handleDonateApiSuccess()::: \n ${e.localizedMessage}")
        EventLog.logException(
            event = "Exception::: handleDonateApiSuccess()",
            exception = e
        )
    }
}
#

override fun processPayment(secret: String) {

    val reader = Terminal.getInstance().connectedReader
    if (reader != null) {
        Terminal
            .getInstance()
            .retrievePaymentIntent(
                clientSecret = secret,
                callback = paymentIntentCallback
            )
    } else {
        updateTerminalState(TerminalState.Exception("No reader connected!"))
    }
}
sullen kettle
#

Hey! Taking over for my colleague. Let me catch up.

dense loom
#

sure

sullen kettle
#

private fun cancelCurrentTransaction() {
if (isCancelling) return
isCancelling = true

    paymentCancellable?.let {
        it.cancel(paymentCancellationCallback)
    } ?: run {
        safeResetTerminal()
        _cancellationState.value = true
        isCancelling = false
    }
}

Have you had a chance to debug this and when the unexpected disconnect happens, this function is called ? Can you add a log there

dense loom
#

yes it is being call, I call it explicitly

sullen kettle
#

No in your code there is a check paymentCancellable?

#

Also you should cann the paymentCancellable.cancel() after you are re-connected again to the reader

dense loom
#

okay let me check

sullen kettle
#

For example, you listen to the event onDisconnect, you set a boolean property for example to try (cancelCurrenttransaction). And when the listener onReaderReconnectSucceeded is called you check that attribut, if it's true, you cancel the transaction

dense loom
#

ok sure

#

also can we check from code that there is no transaction stuck in the card reader and we have too clear that before initializing a new transaction??

sullen kettle
#

This needs to happens after re-connecting to the reader of course

dense loom
#

okay let me check