-
Notifications
You must be signed in to change notification settings - Fork 135
Connect the stored security code input view to the StoredCardComponent #2476
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
Changes from all commits
459b02d
2222732
d19c71b
ee217c9
cde1d55
3fe5cd9
22689c4
d587680
c4bd100
b8c2bb8
b9b6695
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,66 +7,80 @@ | |||||||
| @_spi(AdyenInternal) import Adyen | ||||||||
| import Foundation | ||||||||
| import UIKit | ||||||||
| #if canImport(AdyenUI) | ||||||||
| @_spi(AdyenInternal) import AdyenUI | ||||||||
| #endif | ||||||||
|
|
||||||||
| /// A component that provides a form for stored card payments. | ||||||||
| @MainActor | ||||||||
| package final class StoredCardComponent: StoredPaymentComponent, Localizable { | ||||||||
|
|
||||||||
| /// The context object for this component. | ||||||||
| package let context: AdyenContext | ||||||||
|
|
||||||||
| /// The card payment method. | ||||||||
| package var paymentMethod: PaymentMethod { | ||||||||
| storedCardPaymentMethod | ||||||||
| } | ||||||||
|
|
||||||||
| /// The delegate of the component. | ||||||||
| package weak var delegate: PaymentComponentDelegate? | ||||||||
|
|
||||||||
| package var localizationParameters: LocalizationParameters? | ||||||||
|
|
||||||||
| private let storedCardPaymentMethod: StoredCardPaymentMethod | ||||||||
|
|
||||||||
| private let theme: CheckoutTheme | ||||||||
|
|
||||||||
| package init( | ||||||||
| storedCardPaymentMethod: StoredCardPaymentMethod, | ||||||||
| context: AdyenContext | ||||||||
| context: AdyenContext, | ||||||||
| theme: CheckoutTheme | ||||||||
| ) { | ||||||||
| self.storedCardPaymentMethod = storedCardPaymentMethod | ||||||||
| self.context = context | ||||||||
| self.theme = theme | ||||||||
| } | ||||||||
|
|
||||||||
| package var viewController: UIViewController { | ||||||||
| storedCardAlertManager.alertController | ||||||||
| } | ||||||||
|
|
||||||||
| internal lazy var storedCardAlertManager: StoredCardAlertManager = { | ||||||||
| sendInitialAnalytics() | ||||||||
| sendDidLoadEvent() | ||||||||
|
|
||||||||
| let manager = StoredCardAlertManager( | ||||||||
| paymentMethod: storedCardPaymentMethod, | ||||||||
| context: context, | ||||||||
| amount: context.amount | ||||||||
|
|
||||||||
| package lazy var viewController: UIViewController = { | ||||||||
| let viewModel = StoredCardInputViewModel( | ||||||||
| theme: theme, | ||||||||
| storedCardPaymentMethod: storedCardPaymentMethod, | ||||||||
| apiContext: context.apiContext, | ||||||||
| publicKey: context.publicKey, | ||||||||
| amount: context.amount, | ||||||||
| analyticsProvider: context.analyticsProvider, | ||||||||
| localizationParameters: localizationParameters | ||||||||
| ) | ||||||||
|
|
||||||||
| manager.localizationParameters = localizationParameters | ||||||||
| manager.completionHandler = { [weak self] result in | ||||||||
| guard let self else { return } | ||||||||
|
|
||||||||
| switch result { | ||||||||
| case let .success(details): | ||||||||
| self.submit(data: PaymentComponentData( | ||||||||
| paymentMethodDetails: details, | ||||||||
| amount: self.context.amount, | ||||||||
| order: self.order | ||||||||
| )) | ||||||||
| case let .failure(error): | ||||||||
| self.delegate?.didFail(with: error, from: self) | ||||||||
| } | ||||||||
|
|
||||||||
| viewModel.cardDetailsCompletionHandler = { [weak self] in | ||||||||
| self?.receivedCardDetailsResultToProcessPayment(result: $0) | ||||||||
| } | ||||||||
|
|
||||||||
| return manager | ||||||||
|
|
||||||||
| viewModel.closeHandler = { [weak self] in | ||||||||
| self?.viewController.dismiss(animated: true) | ||||||||
| } | ||||||||
|
|
||||||||
| // TODO: Robert: This doesn't seem to a right place to trigger initialAnalytics(). As this is a lazy var. Maybe this could be moved elsewhere? - I don't know where as of yet. | ||||||||
| self.sendInitialAnalytics() | ||||||||
|
|
||||||||
| let storedCardInputController = StoredCardInputViewController(viewModel: viewModel) | ||||||||
|
|
||||||||
| // TODO: Robert: StoredView: I assume here is the right place to wrap it in a navigation. As StoredCardComponent can be used separately by the merchant. If this is not, where else should this be? | ||||||||
| return UINavigationController(rootViewController: storedCardInputController) | ||||||||
|
Comment on lines
+68
to
+69
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. Wrapping the component's view controller in a
Suggested change
|
||||||||
| }() | ||||||||
|
|
||||||||
| private func receivedCardDetailsResultToProcessPayment(result: Result<CardDetails, Error>) { | ||||||||
| switch result { | ||||||||
| case let .success(details): | ||||||||
| submit(data: PaymentComponentData( | ||||||||
| paymentMethodDetails: details, | ||||||||
| amount: context.amount, | ||||||||
| order: order | ||||||||
| )) | ||||||||
| case let .failure(error): | ||||||||
| delegate?.didFail(with: error, from: self) | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /// :nodoc: | ||||||||
|
|
||||||||
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.
Triggering
sendInitialAnalytics()inside a lazy property initializer makes the analytics reporting dependent on when theviewControlleris first accessed. To ensure consistent tracking, consider moving this call to the initializer or a more deterministic lifecycle event.