#ubbyrob13

1 messages · Page 1 of 1 (latest)

elfin duneBOT
gray iron
#

I don't fully understand your question - are you just asking what onSuccess and onFailure do?

cinder basin
#

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

gray iron
#

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?

cinder basin
#

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

gray iron
#

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

cinder basin
#

pi_3NiLbWIcwltjZIut2sK3OSc5

#

this is the most recent test

gray iron
#

Thanks! Let me take a look

cinder basin
#

Thanks!

gray iron
#

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?

cinder basin
#

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

gray iron
#

Hmm...let me pull in some other folks to take a look here as well

cinder basin
#

Thanks

elfin duneBOT
thick epoch
#

👋 can you print out Terminal.getInstance() before you call .cancelPaymentIntent?

cinder basin
#

let me try one sec

thick epoch
cinder basin
#

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)
        }
thick epoch
#

Ah you just call cancelable.cancel() when you want to cancecl the ongoing operation (in this case collectPaymentMethod)

cinder basin
#

the cancel needs a param would it just be the PaymentIntentCallback?

thick epoch
cinder basin
#

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

thick epoch
#

oh with basic callback I meant something like

    override fun onSuccess() {
      ...
    }
    override fun onFailure(exception: TerminalException) {
      ...
    }
}```
cinder basin
#

so then if i use the cancelable.cancel do i also need to cancel the payment intent? or no?

thick epoch
#

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

cinder basin
#

Okay let me try

thick epoch
#

You can call it from onSuccess() for the cancel(..)

cinder basin
#

it looks like im getting this error message with this ?

E/StripeTerminal: class=TerminalSession
    com.stripe.stripeterminal.external.models.TerminalException: Payment was canceled
thick epoch
#

Oh interesting.. Can you share the PaymentIntent ID? also the code you wrote?

cinder basin
#

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

thick epoch
#

Hmm if you take out the Terminal.getInstance().cancelPaymentIntent, does the error go away?

cinder basin
#

oh no , the error is still there

thick epoch
#

So most likely is coming from somewhere else in your code

cinder basin
#

i think its coming from the onFailure from the collectPaymentMethod

thick epoch
#

yeah could be... Are you seeing any logs for

Terminal.getInstance().cancelPaymentIntent```
cinder basin
#

i get the logs for "Payment Cancelled" from the cancelable.cancel() . Im not getting any logs from getInstance.cancelPayment

thick epoch
#

Nothing like ?
D/StripeTerminal: class=Terminal message=cancelPaymentIntent

#

what if you uncomment cancelTerminalPayment(paymentIntent) and move that to onSuccess for cancel(...)?

cinder basin
#

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
thick epoch
#

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

elfin duneBOT
thick epoch
#

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)

https://support.stripe.com/?contact=true