stripe-terminal-ios
stripe-terminal-ios copied to clipboard
need cancel payment intent example
during collecting payment intent, for the cancel case: we need example for cancel PaymentIntent. do actions like:
- cancell collecting payment intent.
- cancel payment intent
we would like a example with cancelling button during collecting payment
we would like a example with cancelling button during collecting payment
The Example app in the repo has the first part of this that you can play with/review:
https://github.com/stripe/stripe-terminal-ios/blob/master/Example/Example/PaymentViewController.swift#L113
is the collect call where it sets the self.cancelable and then it's a bit buried but that gets used by the VC's subclass which is a EventDisplayingViewController
which implements the CancelableViewController
protocol https://github.com/stripe/stripe-terminal-ios/blob/cc279fa8a31088c1c46ec711971b9d62c4b2bd3c/Example/Example/CancelableViewController.swift#L28
so when collecting the cancel button in the nav bar is wired up to the self.cancelable
which is set during collect and then nil'd after. The completion block of the collectPaymentMethod
though is the source of truth for when the collect has completed still.
the missing piece here though is step 2 "cancel payment intent"
for that the SDK interface is cancelPaymentIntent
which is a thin wrapper around the API's cancel call. So in the collectPaymentMethod completion you can check if the error is cancel and call the cancelPaymentIntent to fully cancel it at the API.
But note after cancelling collectPaymentMethod you may also decide to recollect so canceling isn't strictly required. But if you don't cancel it and don't recollect and then confirm/processPayment it will be left in the "incomplete" state.
Agree we should add more of this to https://stripe.com/docs/terminal/payments/collect-payment?terminal-sdk-platform=ios#collect-payment will work on that.
Thanks a lot for your answer. Yes, after the cancelable.cancel, the payment intent was left in the "incomplete" state. Maybe the "Canceled" state is looking better. Eventually , we make it, by calling cancelPaymentIntent with a 0.5 seconds delay in the call back of cancelable.cancel like
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5)
sorry for the extremely delayed response here. We were reviewing old issues and this one came up.
Maybe the "Canceled" state is looking better.
this is acting as expected. The state is the API's representation intentionally and the canceled state is an explicit state for PaymentIntents that the intent only moves to when the cancel action on the PI is requested: https://docs.stripe.com/payments/paymentintents/lifecycle
the public example app in the repo also now cancels PaymentIntent's in the API (using the cancelPaymentIntent SDK method) when you request cancel after collect, which hopefully helps.
closing this out but re-open if need still have a bug here that I'm missing.