-
Notifications
You must be signed in to change notification settings - Fork 135
[v6] (1/2) BACS Direct Debit: Remove confirmation screen #2597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/COSDK-1284_Remove_confirmation_screen_BACS
Are you sure you want to change the base?
Changes from all commits
37758ef
d63a699
c090a46
e2648a4
b75183f
b03b02a
c47aa67
3daa169
0c8358e
001de8c
73e0e26
098f05d
d682f55
b4bc0c8
2e69f78
0161acd
76d0723
735df2c
8f01ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,11 +13,6 @@ import Adyen | |
| #endif | ||
| import UIKit | ||
|
|
||
| internal protocol BACSDirectDebitRouterProtocol: AnyObject { | ||
| func presentConfirmation(with data: BACSDirectDebitData) | ||
| func confirmPayment(with data: BACSDirectDebitData) | ||
| } | ||
|
|
||
| /// A component that provides a form for BACS Direct Debit payments. | ||
| @MainActor | ||
| package final class BACSDirectDebitComponent: PaymentComponent, PresentableComponent { | ||
|
|
@@ -27,7 +22,10 @@ package final class BACSDirectDebitComponent: PaymentComponent, PresentableCompo | |
|
|
||
| // MARK: - PresentableComponent | ||
|
|
||
| package let viewController: UIViewController | ||
| package lazy var viewController: UIViewController = { | ||
| let bacsViewController = createViewController() | ||
| return SecuredViewController(child: bacsViewController, style: configuration.style) | ||
| }() | ||
|
|
||
| /// The object that acts as the delegate of the component. | ||
| package weak var delegate: PaymentComponentDelegate? | ||
|
|
@@ -40,23 +38,21 @@ package final class BACSDirectDebitComponent: PaymentComponent, PresentableCompo | |
| /// The context object for this component. | ||
| package let context: AdyenContext | ||
|
|
||
| /// The object that acts as the presentation delegate of the component. | ||
| package weak var presentationDelegate: PresentationDelegate? | ||
|
|
||
| /// Component's configuration | ||
| package var configuration: Configuration | ||
|
|
||
| // MARK: - PaymentComponent | ||
|
|
||
| package func performSubmit() { | ||
| bacsViewModel?.performSubmit() | ||
| } | ||
|
nauaros marked this conversation as resolved.
|
||
|
|
||
| // MARK: - Properties | ||
|
|
||
| internal let bacsPaymentMethod: BACSDirectDebitPaymentMethod | ||
|
|
||
| internal var confirmationPresenter: BACSConfirmationPresenterProtocol? | ||
| private var confirmationViewPresented = false | ||
|
|
||
| internal let inputFormViewController: BACSInputFormViewController | ||
|
|
||
| internal private(set) var inputPresenter: BACSInputPresenterProtocol? | ||
|
|
||
|
|
||
| internal private(set) var bacsViewModel: BACSViewModel? | ||
|
|
||
| // MARK: - Initializers | ||
|
|
||
| /// Creates and returns a BACS Direct Debit component. | ||
|
|
@@ -72,16 +68,11 @@ package final class BACSDirectDebitComponent: PaymentComponent, PresentableCompo | |
| self.bacsPaymentMethod = paymentMethod | ||
| self.context = context | ||
| self.configuration = configuration | ||
| self.inputFormViewController = BACSInputFormViewController( | ||
| title: paymentMethod.name, | ||
| scrollEnabled: configuration.showsSubmitButton, | ||
| styleProvider: configuration.style | ||
| ) | ||
| self.viewController = SecuredViewController( | ||
| child: inputFormViewController, | ||
| style: configuration.style | ||
| ) | ||
|
|
||
| } | ||
|
|
||
| // MARK: - Private | ||
|
|
||
| private func createViewController() -> UIViewController { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we think of extracting assembly code from the payment business logic to another assembly/provider/factory? |
||
| let tracker = BACSDirectDebitComponentTracker( | ||
| paymentMethod: bacsPaymentMethod, | ||
| context: context, | ||
|
|
@@ -92,74 +83,27 @@ package final class BACSDirectDebitComponent: PaymentComponent, PresentableCompo | |
| localizationParameters: configuration.localizationParameters, | ||
| scope: String(describing: self) | ||
| ) | ||
| self.inputPresenter = BACSInputPresenter( | ||
| view: inputFormViewController, | ||
| router: self, | ||
| tracker: tracker, | ||
| itemsFactory: itemsFactory | ||
| ) | ||
| inputPresenter?.amount = context.amount | ||
| inputFormViewController.presenter = inputPresenter | ||
|
|
||
| } | ||
|
|
||
| package func performSubmit() { | ||
| // TODO: - COSDK-1284: The confirmation screen will be removed. | ||
| } | ||
| } | ||
|
|
||
| // MARK: - BACSDirectDebitRouterProtocol | ||
|
|
||
| /// :nodoc: | ||
| extension BACSDirectDebitComponent: BACSDirectDebitRouterProtocol { | ||
|
|
||
| internal func presentConfirmation(with data: BACSDirectDebitData) { | ||
| confirmationViewPresented = true | ||
| let confirmationView = assembleConfirmationView(with: data) | ||
|
|
||
| let wrappedComponent = PresentableComponentWrapper( | ||
| component: self, | ||
| viewController: confirmationView | ||
| ) | ||
| presentationDelegate?.present(component: wrappedComponent) | ||
| } | ||
|
|
||
| internal func confirmPayment(with data: BACSDirectDebitData) { | ||
| guard let bacsDirectDebitPaymentMethod = paymentMethod as? BACSDirectDebitPaymentMethod else { | ||
| return | ||
| } | ||
| let details = BACSDirectDebitDetails( | ||
| paymentMethod: bacsDirectDebitPaymentMethod, | ||
| holderName: data.holderName, | ||
| bankAccountNumber: data.bankAccountNumber, | ||
| bankLocationId: data.bankLocationId | ||
| let viewModel = BACSViewModel( | ||
| paymentMethod: bacsPaymentMethod, | ||
| amount: context.amount, | ||
| configuration: configuration, | ||
| tracker: tracker, | ||
| itemsFactory: itemsFactory, | ||
| onSubmit: { [weak self] details in | ||
| let data = PaymentComponentData( | ||
| paymentMethodDetails: details, | ||
| order: self?.order | ||
| ) | ||
| self?.submit(data: data) | ||
| } | ||
| ) | ||
| confirmationPresenter?.startLoading() | ||
| submit(data: PaymentComponentData(paymentMethodDetails: details, order: order)) | ||
| } | ||
| self.bacsViewModel = viewModel | ||
|
|
||
| // MARK: - Private | ||
|
|
||
| private func assembleConfirmationView(with data: BACSDirectDebitData) -> UIViewController { | ||
| let confirmationViewController = BACSConfirmationViewController( | ||
| return BACSViewController( | ||
| title: paymentMethod.name, | ||
| scrollEnabled: configuration.showsSubmitButton, | ||
| styleProvider: configuration.style, | ||
| localizationParameters: configuration.localizationParameters | ||
| viewModel: viewModel | ||
| ) | ||
| let itemsFactory = BACSItemsFactory( | ||
| styleProvider: configuration.style, | ||
| localizationParameters: configuration.localizationParameters, | ||
| scope: String(describing: self) | ||
| ) | ||
| confirmationPresenter = BACSConfirmationPresenter( | ||
| data: data, | ||
| view: confirmationViewController, | ||
| router: self, | ||
| itemsFactory: itemsFactory | ||
| ) | ||
| confirmationViewController.presenter = confirmationPresenter | ||
| return SecuredViewController(child: confirmationViewController, style: configuration.style) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -170,21 +114,6 @@ extension BACSDirectDebitComponent: LoadingComponent { | |
|
|
||
| /// Stops any processing animation that the component is running. | ||
| package func stopLoading() { | ||
| confirmationPresenter?.stopLoading() | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Cancellable | ||
|
|
||
| /// :nodoc: | ||
| extension BACSDirectDebitComponent: Cancellable { | ||
|
|
||
| /// Called when the user cancels the component. | ||
| package func didCancel() { | ||
| if confirmationViewPresented == false { | ||
| inputPresenter?.resetForm() | ||
| } else { | ||
| confirmationViewPresented = false | ||
| } | ||
| bacsViewModel?.stopLoading() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // | ||
| // Copyright (c) 2021 Adyen N.V. | ||
| // | ||
| // This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
| // | ||
|
|
||
| import Adyen | ||
| #if canImport(AdyenUI) | ||
| import AdyenUI | ||
| @_spi(AdyenInternal) import class AdyenUI.FormViewController | ||
| #endif | ||
| import Combine | ||
| import UIKit | ||
|
|
||
| internal final class BACSViewController: FormViewController { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed |
||
|
|
||
| // MARK: - Properties | ||
|
|
||
| private let viewModel: BACSViewModel | ||
| private var cancellables = Set<AnyCancellable>() | ||
|
|
||
| // MARK: - Initializers | ||
|
|
||
| internal init( | ||
| title: String, | ||
| viewModel: BACSViewModel | ||
| ) { | ||
| self.viewModel = viewModel | ||
| super.init( | ||
| scrollEnabled: viewModel.configuration.showsSubmitButton, | ||
| style: viewModel.configuration.style, | ||
| localizationParameters: viewModel.configuration.localizationParameters | ||
| ) | ||
| self.title = title | ||
| } | ||
|
|
||
| // MARK: - View life cycle | ||
|
|
||
| override internal func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| viewModel.viewDidLoad() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought; |
||
| bindValidation() | ||
| viewModel.items.forEach { append($0) } | ||
| } | ||
|
|
||
| // MARK: - Private | ||
|
|
||
| private func bindValidation() { | ||
| viewModel.$shouldShowValidation.sink { [weak self] shouldShowValidation in | ||
| if shouldShowValidation { self?.showValidation() } | ||
| }.store(in: &cancellables) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this approach limit our testing capabilities? Passing a mock view controller could help us cover the lifecycle events if needed.