#aneeb_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
- aneeb_code, 13 hours ago, 5 messages
hey there ๐ taking a look at your question
First how are you re-connecting to the terminal, are you doing this manually or via the autoReconnectOnUnexpectedDisconnect?
In general, the first option here is to cancel via the Cancelable object returned from Terminal.getInstance().collectPaymentMethod. If this doesn't help, you could disconnect completely, and re-connect again.
Lastly, reboot the reader. (https://docs.stripe.com/terminal/payments/connect-reader?terminal-sdk-platform=android&reader-type=usb#reboot-the-connected-reader)
Not reconnect I try to connect it normally
Can you try cancelling the transaction using the Cancelable object that's returned from Terminal.getInstance().collectPaymentMethod?
private fun collectPaymentMethod(intent: PaymentIntent) {
paymentCancellable = Terminal.getInstance().collectPaymentMethod(
callback = collectPaymentIntentCallback,
intent = intent,
config = paymentCollectionConfig
)
}
this is the collectPaymentMethod i am using
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?
sure
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!"))
}
}
Hey! Taking over for my colleague. Let me catch up.
sure
private fun cancelCurrentTransaction() {
if (isCancelling) return
isCancelling = truepaymentCancellable?.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
yes it is being call, I call it explicitly
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
okay let me check
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
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??
I think you can check the PaymentStatus:
https://stripe.dev/stripe-terminal-android/core/com.stripe.stripeterminal/-terminal/index.html#-1631844340%2FProperties%2F-1814817128
And cancel the PaymentIntent also then:
https://stripe.dev/stripe-terminal-android/core/com.stripe.stripeterminal/-terminal/index.html#52935420%2FFunctions%2F-1814817128
This needs to happens after re-connecting to the reader of course
Between, here are all the available functions and properties that the Terminal SDK provides you:
https://stripe.dev/stripe-terminal-android/core/com.stripe.stripeterminal/-terminal/index.html
okay let me check