#ubbyrob13
1 messages · Page 1 of 1 (latest)
I don't fully understand your question - are you just asking what onSuccess and onFailure do?
No I am not - neither of these are being called so Im wondering if my code is incorrect
The stripe documents do not have much information about cancelling in person payments
Ahhh gotcha, I see what you're saying now
So you've confirmed you're seeing the ""Cancel Terminal Payment Called"" log, right?
Are you seeing anything else in your device logs while making these calls?
Im not seeing either of the logs from onSuccess or onFailure, but the logs directly above Terminal.getInstance().cancelPayment are both appearing, and the paymentIntent is correct
Hmm... do you have the payment intent ID so I can take a look? Just want to see if those requests are coming through on our end
Thanks! Let me take a look
Thanks!
Hmmm... yeah I don't see anything on our end for it either, so it looks like it's definitely something is up with the code and the call is not being made
I know you said you didn't see anythign in the logs, but do you see any warnings/errors being thrown at all?
None this is everything i get from the logs
D/CartActivity: Cancel Terminal Payment Called
D/CartActivity: PaymentIntent(id=pi_3NiLbWIcwltjZIut2sK3OSc5, amount=1441, amountCapturable=0, amountReceived=0, application=null, applicationFeeAmount=0, canceledAt=0, cancellationReason=null, captureMethod=automatic, charges=null, clientSecret=pi_3NiLbWIcwltjZIut2sK3OSc5_secret_ZjvMNhxBrx57q3AkcWkKSdZXS, confirmationMethod=automatic, created=1692814590, currency=cad, customer=null, description=null, invoice=null, lastPaymentError=null, livemode=true, metadata={}, onBehalfOf=null, paymentMethodUnion=null, receiptEmail=null, review=null, setupFutureUsage=null, statementDescriptor=null, status=REQUIRES_PAYMENT_METHOD, transferGroup=null, amountDetails=AmountDetails(tip=Tip(amount=null)), amountTip=null, statementDescriptorSuffix=null, paymentMethodOptions=null, stripeAccountId=null)
D/StripeTerminal: class=Terminal message=cancelPaymentIntent
the onFailure was called before when my reader wasn't connected earlier, so i know the function is being hit. I am just unsure why nothing is logged when the reader is connected
Hmm...let me pull in some other folks to take a look here as well
Thanks
👋 can you print out Terminal.getInstance() before you call .cancelPaymentIntent?
let me try one sec
Also taking a step back, are you also trying to cancel payment method collection prompt on the reader?
If so, you need to use the cancelable object returned by the collectPaymentMethod
https://stripe.com/docs/terminal/payments/collect-payment?terminal-sdk-platform=android#collect-payment
Cancelling the PaymentIntent directly won't prompt the reader to stop/cancel payment method collection
either or , the documentation has very little on cancelling this is all i can find. I have val cancelable initiated in my code, but its never used because the documentation really doesn't show how it can me used
private fun collectPaymentMethod(paymentIntent: PaymentIntent) {
val cancelable = Terminal.getInstance().collectPaymentMethod(paymentIntent,
object : PaymentIntentCallback {
override fun onSuccess(paymentIntent: PaymentIntent) {
// Payment method collection successful, you can proceed to process the payment
// Access the paymentIntent object with the updated state, if needed.
processTerminalPayment(paymentIntent)
}
override fun onFailure(exception: TerminalException) {
// Placeholder for handling exception during payment method collection
// You might want to display an error to the user or try again.
}
})
runOnUiThread {
showCancelPaymentAlertDialog(paymentIntent)
}
Ah you just call cancelable.cancel() when you want to cancecl the ongoing operation (in this case collectPaymentMethod)
the cancel needs a param would it just be the PaymentIntentCallback?
You can pass the basic Callback (not a PaymentIntentCallback)
https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.callable/-callback/index.html
okay I used it
cancelable.cancel(Callback)
but im still getting errors
Classifier 'Callback' does not have a companion object, and thus must be initialized here
i imported the stripe error call back
oh with basic callback I meant something like
override fun onSuccess() {
...
}
override fun onFailure(exception: TerminalException) {
...
}
}```
so then if i use the cancelable.cancel do i also need to cancel the payment intent? or no?
You will need to call cancelPaymentIntent separately if you want to cancel the PaymentIntent. You can re-use the same PaymentIntent later incase customer wants to resume checkout..
Can you try calling Terminal.getInstance().cancelPaymentIntent(...) after calling .cancel(..)?
Want to make sure that it does cancel the PaymentIntent once you stop PaymentMethod collection
Okay let me try
You can call it from onSuccess() for the cancel(..)
it looks like im getting this error message with this ?
E/StripeTerminal: class=TerminalSession
com.stripe.stripeterminal.external.models.TerminalException: Payment was canceled
Oh interesting.. Can you share the PaymentIntent ID? also the code you wrote?
This is the code
private fun showCancelPaymentAlertDialog(paymentIntent: PaymentIntent, cancelable: Cancelable) {
val alertDialog = AlertDialog.Builder(this)
.setTitle("Cancel Payment")
.setMessage("Are you sure you want to cancel the payment?")
.setPositiveButton("Cancel Payment") { dialog: DialogInterface, which: Int ->
// Handle the scenario where the user chooses to keep the payment
// For example, you can dismiss the dialog or perform other actions
cancelable.cancel(object : Callback {
override fun onSuccess() {
Log.d("Cart Activity", "Payment Cancelled")
Terminal.getInstance().cancelPaymentIntent(paymentIntent, object: PaymentIntentCallback {
override fun onSuccess(paymentIntent: PaymentIntent) {
Log.d("Cart Activity", "Payment Intent Cancelled")
// Placeholder for handling a successful cancellation
}
override fun onFailure(exception: TerminalException) {
// Placeholder for handling a failed cancellation
Log.d("Cart Activtiy", "Payment intent not cancelled?")
}
})
}
override fun onFailure(exception: TerminalException) {
Log.d("Cart Activtiy", "Payment not cancelled?")
}
})
// cancelTerminalPayment(paymentIntent)
}
.setCancelable(false) // Prevent the dialog from being canceled by tapping outside
.create()
alertDialog.show()
}
this is the pi pi_3NiMZuIcwltjZIut2nlF2t3b
Hmm if you take out the Terminal.getInstance().cancelPaymentIntent, does the error go away?
oh no , the error is still there
So most likely is coming from somewhere else in your code
i think its coming from the onFailure from the collectPaymentMethod
yeah could be... Are you seeing any logs for
Terminal.getInstance().cancelPaymentIntent```
i get the logs for "Payment Cancelled" from the cancelable.cancel() . Im not getting any logs from getInstance.cancelPayment
Nothing like ?
D/StripeTerminal: class=Terminal message=cancelPaymentIntent
what if you uncomment cancelTerminalPayment(paymentIntent) and move that to onSuccess for cancel(...)?
let me try
okay i moved it, i still dont have the logs from that function appearing, but i have this
D/StripeTerminal: class=Terminal message=cancelPaymentIntent
yeah not sure why its not cancelling, I can't reproduce it on my end.
One theory I have is if somehow it is losing the initialized instance of Terminal but that should throw an error when you do Terminal.getInstance() call afaik
Since I can't reproduce it, I'd recommend that you write into our support team via below link with as much information as you can provide like SDK version, example code etc (if you can provide a sample app that we can use to reproduce the issue then that'd be most helpful)