diff --git a/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Component/PONativeAlternativePaymentComponent.swift b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Component/PONativeAlternativePaymentComponent.swift index a838ab825..ea2e912ef 100644 --- a/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Component/PONativeAlternativePaymentComponent.swift +++ b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Component/PONativeAlternativePaymentComponent.swift @@ -52,7 +52,7 @@ public final class PONativeAlternativePaymentComponent { /// Cancels the ongoing payment. public func cancel() { - interactor.cancel() + interactor.cancel(reason: .programmatic) } // MARK: - Internal diff --git a/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentCancellationReason.swift b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentCancellationReason.swift new file mode 100644 index 000000000..d82d0c226 --- /dev/null +++ b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentCancellationReason.swift @@ -0,0 +1,25 @@ +// +// NativeAlternativePaymentCancellationReason.swift +// ProcessOut +// +// Created by Andrii Vysotskyi on 10.08.2026. +// + +import Foundation + +/// Describes the reason why the payment flow was cancelled. +enum NativeAlternativePaymentCancellationReason { + + /// The customer explicitly cancelled the payment flow (for example, by tapping a Cancel button). + case customer + + /// The payment flow was cancelled because the associated objects were released as part of the + /// lifecycle. + /// + /// This commonly happens when the screen is dismissed, but it can also occur for other reasons + /// that result in the flow being deallocated. + case lifecycle + + /// The payment flow was explicitly cancelled by the application code. + case programmatic +} diff --git a/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentDefaultInteractor.swift b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentDefaultInteractor.swift index 477dd94ba..50b2d1f12 100644 --- a/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentDefaultInteractor.swift +++ b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentDefaultInteractor.swift @@ -151,7 +151,15 @@ final class NativeAlternativePaymentDefaultInteractor: state = .redirecting(newState) } + func didRequestCancelConfirmation() { + send(event: .didRequestCancelConfirmation) + } + override func cancel() { + cancel(reason: .programmatic) + } + + func cancel(reason: NativeAlternativePaymentCancellationReason) { switch state { case .starting(let currentState): currentState.task.cancel() @@ -168,11 +176,12 @@ final class NativeAlternativePaymentDefaultInteractor: default: break } - setFailureState(error: POFailure(message: "Alternative payment has been canceled.", code: .Mobile.cancelled)) - } - - func didRequestCancelConfirmation() { - send(event: .didRequestCancelConfirmation) + setFailureState( + error: POFailure( + message: "Alternative payment has been canceled. Reason: '\(reason)'.", + code: .Mobile.cancelled + ) + ) } // MARK: - Private Properties diff --git a/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentInteractor.swift b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentInteractor.swift index 23142538e..cef69200b 100644 --- a/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentInteractor.swift +++ b/Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentInteractor.swift @@ -33,4 +33,7 @@ protocol NativeAlternativePaymentInteractor: Interactor