Skip to content

Commit

Permalink
Notify checkout 3ds delegate about additional lifecylce events
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-vysotskyi-cko committed Jul 7, 2023
1 parent 80ead96 commit 43fddbd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ final class Checkout3DSService: PO3DSService {
completion(.failure(failure))
return
}
delegate.willHandle(challenge: challenge)
state = .challenging(context)
let parameters = convertToChallengeParameters(data: challenge)
context.transaction.doChallenge(challengeParameters: parameters) { [unowned self, errorMapper] result in
self.setIdleStateUnchecked()
completion(result.map(extractStatus(challengeResult:)).mapError(errorMapper.convert))
let challengeResult = result.map(extractStatus(challengeResult:)).mapError(errorMapper.convert)
completion(challengeResult)
delegate.didHandle3DS2Challenge(result: challengeResult)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import Checkout3DS
/// Checkout 3DS service delegate.
public protocol POCheckout3DSServiceDelegate: AnyObject {

/// Notifies delegate that service is about to fingerprint device. Implementation should create
/// `ThreeDS2ServiceConfiguration` using `configParameters` and return it.
/// Notifies delegate that service is about to fingerprint device.
func willCreateAuthenticationRequest(configuration: PO3DS2Configuration)

/// Asks implementation to create `ThreeDS2ServiceConfiguration` using `configParameters`. This method
/// could be used to customize underlying 3DS SDK appearance and bahaviour.
func configuration(
with parameters: Checkout3DS.ThreeDS2ServiceConfiguration.ConfigParameters
) -> Checkout3DS.ThreeDS2ServiceConfiguration
Expand All @@ -21,19 +24,44 @@ public protocol POCheckout3DSServiceDelegate: AnyObject {
/// ignores warnings and completes with `true`.
func shouldContinue(with warnings: Set<Checkout3DS.Warning>, completion: @escaping (Bool) -> Void)

/// Notifies delegate that service did complete device fingerprinting.
func didCreateAuthenticationRequest(result: Result<PO3DS2AuthenticationRequest, POFailure>)

/// Notifies delegate that implementation is about to handle 3DS2 challenge.
func willHandle(challenge: PO3DS2Challenge)

/// Notifies delegate that service did end handling 3DS2 challenge with given result.
func didHandle3DS2Challenge(result: Result<Bool, POFailure>)

/// Asks delegate to handle 3DS redirect. See documentation of `PO3DSService/handle(redirect:completion:)`
/// for more details.
func handle(redirect: PO3DSRedirect, completion: @escaping (Result<String, POFailure>) -> Void)
}

extension POCheckout3DSServiceDelegate {

public func willCreateAuthenticationRequest(configuration: PO3DS2Configuration) {
// Ignored
}

public func configuration(
with parameters: Checkout3DS.ThreeDS2ServiceConfiguration.ConfigParameters
) -> Checkout3DS.ThreeDS2ServiceConfiguration {
ThreeDS2ServiceConfiguration(configParameters: parameters)
}

public func didCreateAuthenticationRequest(result: Result<PO3DS2AuthenticationRequest, POFailure>) {
// Ignored
}

public func willHandle(challenge: PO3DS2Challenge) {
// Ignored
}

public func didHandle3DS2Challenge(result: Result<Bool, POFailure>) {
// Ignored
}

public func shouldContinue(with warnings: Set<Checkout3DS.Warning>, completion: @escaping (Bool) -> Void) {
completion(true)
}
Expand Down

0 comments on commit 43fddbd

Please sign in to comment.