@@ -32,6 +32,10 @@ public final class StripeCardReaderService: NSObject {
3232 /// Keeps track of whether a chip card needs to be removed
3333 private var timerCancellable : Cancellable ?
3434 private var isChipCardInserted : Bool = false
35+
36+ /// Stripe don't tell us where a cancellation comes from: if we keep track of when we trigger one,
37+ /// we can infer when it comes from the cancel button on the reader instead
38+ private var cancellationStartedInApp : Bool ?
3539}
3640
3741
@@ -285,6 +289,8 @@ extension StripeCardReaderService: CardReaderService {
285289 return
286290 }
287291
292+ self . cancellationStartedInApp = true
293+
288294 let cancelPaymentIntent = { [ weak self] in
289295 Terminal . shared. cancelPaymentIntent ( activePaymentIntent) { ( intent, error) in
290296 if let error = error {
@@ -296,6 +302,7 @@ extension StripeCardReaderService: CardReaderService {
296302 self ? . activePaymentIntent = nil
297303 promise ( . success( ( ) ) )
298304 }
305+ self ? . cancellationStartedInApp = nil
299306 }
300307 }
301308 guard let paymentCancellable = self . paymentCancellable,
@@ -509,12 +516,11 @@ private extension StripeCardReaderService {
509516 /// https://stripe.dev/stripe-terminal-ios/docs/Classes/SCPTerminal.html#/c:objc(cs)SCPTerminal(im)collectPaymentMethod:delegate:completion:
510517 if case . commandCancelled( let cancellationSource) = underlyingError {
511518 DDLogWarn ( " 💳 Warning: collect payment cancelled \( error) " )
512- /// If we've not used the cancellable in the app, the cancellation must have come from the reader
513519 if case . unknown = cancellationSource {
514- if self ? . paymentCancellable != nil {
515- underlyingError = . commandCancelled( from: . reader)
516- } else {
520+ if self ? . cancellationStartedInApp != nil {
517521 underlyingError = . commandCancelled( from: . app)
522+ } else {
523+ underlyingError = . commandCancelled( from: . reader)
518524 }
519525 }
520526 } else {
0 commit comments