Skip to content

Commit

Permalink
Aligned creation of card component between session and advanced flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-SD committed Mar 10, 2025
1 parent 179c49b commit 31f921c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
19 changes: 15 additions & 4 deletions ios/Classes/components/card/BaseCardComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,28 @@ class BaseCardComponent: NSObject, FlutterPlatformView, UIScrollViewDelegate {
}

func buildCardComponent(
paymentMethodString: String,
paymentMethodString: String?,
isStoredPaymentMethod: Bool,
cardComponentConfiguration: CardComponentConfigurationDTO,
adyenContext: AdyenContext
cardComponentConfiguration: CardComponentConfigurationDTO?,
componentDelegate: PaymentComponentDelegate?,
cardDelegate: CardComponentDelegate?
) throws -> CardComponent {
guard let paymentMethodString = paymentMethod else { throw PlatformError(errorDescription: "Payment method not found") }
guard let cardComponentConfiguration else { throw PlatformError(errorDescription: "Card configuration not found") }
let adyenContext = try cardComponentConfiguration.createAdyenContext()
let cardConfiguration = cardComponentConfiguration.cardConfiguration.mapToCardComponentConfiguration(
shopperLocale: cardComponentConfiguration.shopperLocale)
let paymentMethod: AnyCardPaymentMethod = isStoredPaymentMethod
? try JSONDecoder().decode(StoredCardPaymentMethod.self, from: Data(paymentMethodString.utf8))
: try JSONDecoder().decode(CardPaymentMethod.self, from: Data(paymentMethodString.utf8))
return CardComponent(paymentMethod: paymentMethod, context: adyenContext, configuration: cardConfiguration)
let cardComponent = CardComponent(
paymentMethod: paymentMethod,
context: adyenContext,
configuration: cardConfiguration
)
cardComponent.delegate = componentDelegate
cardComponent.cardComponentDelegate = cardDelegate
return cardComponent
}

func showCardComponent(cardComponent: CardComponent) {
Expand Down
25 changes: 11 additions & 14 deletions ios/Classes/components/card/advanced/CardAdvancedComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CardAdvancedComponent: BaseCardComponent {
private var actionComponentDelegate: ActionComponentDelegate?
private var actionComponent: AdyenActionComponent?
private var presentationDelegate: PresentationDelegate?
private var cardDelegate: PaymentComponentDelegate?
private var componentDelegate: PaymentComponentDelegate?

override init(
frame: CGRect,
Expand Down Expand Up @@ -38,6 +38,7 @@ class CardAdvancedComponent: BaseCardComponent {
private func setupCardComponentView() {
do {
let cardComponent = try setupCardComponent()
actionComponent = buildActionComponent(adyenContext: cardComponent.context)
showCardComponent(cardComponent: cardComponent)
componentPlatformApi.onActionCallback = { [weak self] jsonActionResponse in
self?.onAction(actionResponse: jsonActionResponse)
Expand All @@ -51,21 +52,17 @@ class CardAdvancedComponent: BaseCardComponent {
}

private func setupCardComponent() throws -> CardComponent {
guard let cardComponentConfiguration else { throw PlatformError(errorDescription: "Card configuration not found") }
guard let paymentMethodString = paymentMethod else { throw PlatformError(errorDescription: "Payment method not found") }
let adyenContext = try cardComponentConfiguration.createAdyenContext()
let cardComponent = try buildCardComponent(
paymentMethodString: paymentMethodString,
componentDelegate = CardAdvancedFlowDelegate(
componentFlutterApi: componentFlutterApi,
componentId: componentId
)
return try buildCardComponent(
paymentMethodString: paymentMethod,
isStoredPaymentMethod: isStoredPaymentMethod,
cardComponentConfiguration: cardComponentConfiguration,
adyenContext: adyenContext
)

actionComponent = buildActionComponent(adyenContext: adyenContext)
cardDelegate = CardAdvancedFlowDelegate(componentFlutterApi: componentFlutterApi, componentId: componentId)
cardComponent.delegate = cardDelegate
cardComponent.cardComponentDelegate = self
return cardComponent
componentDelegate: componentDelegate,
cardDelegate: self
)
}

private func buildActionComponent(adyenContext: AdyenContext) -> AdyenActionComponent {
Expand Down
13 changes: 4 additions & 9 deletions ios/Classes/components/card/session/CardSessionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@ class CardSessionComponent: BaseCardComponent {
}

private func setupCardComponent() throws -> CardComponent {
guard let cardComponentConfiguration else { throw PlatformError(errorDescription: "Card configuration not found") }
guard let paymentMethodString = paymentMethod else { throw PlatformError(errorDescription: "Payment method not found") }
guard let session = sessionHolder.session else { throw PlatformError(errorDescription: "Session not found") }
let adyenContext = try cardComponentConfiguration.createAdyenContext()
let cardComponent = try buildCardComponent(
paymentMethodString: paymentMethodString,
return try buildCardComponent(
paymentMethodString: paymentMethod,
isStoredPaymentMethod: isStoredPaymentMethod,
cardComponentConfiguration: cardComponentConfiguration,
adyenContext: adyenContext
componentDelegate: session,
cardDelegate: self
)
cardComponent.delegate = session
cardComponent.cardComponentDelegate = self
return cardComponent
}

private func setupSessionFlowDelegate() {
Expand Down

0 comments on commit 31f921c

Please sign in to comment.