Skip to content

Commit

Permalink
card approve analytics changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KunJeongPark committed Dec 13, 2024
1 parent 8c99fde commit a6e9468
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions Sources/CardPayments/CardClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,19 @@ public class CardClient: NSObject {
guard getQueryStringParameter(url: url, param: "flow") == "3ds",
url.contains("helios"),
let url = URL(string: url) else {
self.notifyCheckoutFailure(with: CardError.threeDSecureURLError, completion: completion)
self.notify3dsCheckoutFailure(with: CardError.threeDSecureURLError, completion: completion)
return
}

analyticsService?.sendEvent("card-payments:confirm-payment-source:challenge-required")
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge-required")
startThreeDSecureChallenge(url: url, orderId: result.id, completion: completion)
} else {
analyticsService?.sendEvent("card-payments:confirm-payment-source:succeeded")

let cardResult = CardResult(orderID: result.id, status: result.status, didAttemptThreeDSecureAuthentication: false)
notifyCheckoutSuccess(for: cardResult, completion: completion)
}
} catch let error as CoreSDKError {
analyticsService?.sendEvent("card-payments:confirm-payment-source:failed")
notifyCheckoutFailure(with: error, completion: completion)
} catch {
analyticsService?.sendEvent("card-payments:confirm-payment-source:failed")
notifyCheckoutFailure(with: CardError.unknownError, completion: completion)
}
}
Expand Down Expand Up @@ -161,25 +157,25 @@ public class CardClient: NSObject {
context: self,
sessionDidDisplay: { [weak self] didDisplay in
if didDisplay {
self?.analyticsService?.sendEvent("card-payments:3ds:challenge-presentation:succeeded")
self?.analyticsService?.sendEvent("card-payments:approve-order:challenge-presentation:succeeded")
} else {
self?.analyticsService?.sendEvent("card-payments:3ds:challenge-presentation:failed")
self?.analyticsService?.sendEvent("card-payments:approve-order:challenge-presentation:failed")
}
},
sessionDidComplete: { _, error in
if let error = error {
switch error {
case ASWebAuthenticationSessionError.canceledLogin:
self.notifyCheckoutCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
self.notify3dsCheckoutCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
return
default:
self.notifyCheckoutFailure(with: CardError.threeDSecureError(error), completion: completion)
self.notify3dsCheckoutFailure(with: CardError.threeDSecureError(error), completion: completion)
return
}
}

let cardResult = CardResult(orderID: orderId, status: nil, didAttemptThreeDSecureAuthentication: true)
self.notifyCheckoutSuccess(for: cardResult, completion: completion)
self.notify3dsCheckoutSuccess(for: cardResult, completion: completion)
}
)
}
Expand Down Expand Up @@ -229,13 +225,23 @@ public class CardClient: NSObject {
completion(result, nil)
}

private func notify3dsCheckoutSuccess(for result: CardResult, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge-succeeded")
completion(result, nil)
}

private func notifyCheckoutFailure(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:approve-order:failed")
completion(nil, error)
}

private func notifyCheckoutCancelWithError(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:approve-order:challenge:user-canceled")
private func notify3dsCheckoutFailure(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge-failed")
completion(nil, error)
}

private func notify3dsCheckoutCancelWithError(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge-canceled")
completion(nil, error)
}

Expand Down

0 comments on commit a6e9468

Please sign in to comment.