Skip to content

Commit

Permalink
Merge branch 'feature/client-app-launch-failed-serverside' into 'feat…
Browse files Browse the repository at this point in the history
…ure/native-payments'

Client app launch failed serverside

See merge request swedbank-pay/swedbank-pay-sdk-ios!16
  • Loading branch information
alleus committed Nov 19, 2024
2 parents 3e53193 + 2a6b312 commit d25f198
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 8 additions & 2 deletions SwedbankPaySDK/Classes/Api/SwedbankPayAPIEnpointRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ struct Endpoint {
let method: String?
}

enum FailPaymentAttemptProblemType: String {
case userCancelled = "UserCancelled"
case technicalError = "TechnicalError"
case clientAppLaunchFailed = "ClientAppLaunchFailed"
}

enum EnpointRouter {
case expandMethod(instrument: SwedbankPaySDK.PaymentAttemptInstrument)
case startPaymentAttempt(instrument: SwedbankPaySDK.PaymentAttemptInstrument, culture: String?)
Expand All @@ -34,7 +40,7 @@ enum EnpointRouter {
case abortPayment
case attemptPayload(paymentPayload: String)
case customizePayment(instrument: SwedbankPaySDK.PaymentAttemptInstrument?, paymentMethod: String?, restrictToPaymentMethods: [String]?)
case failPaymentAttempt(problemType: String, errorCode: String?)
case failPaymentAttempt(problemType: FailPaymentAttemptProblemType, errorCode: String?)
}

protocol EndpointRouterProtocol {
Expand Down Expand Up @@ -145,7 +151,7 @@ struct SwedbankPayAPIEnpointRouter: EndpointRouterProtocol {
"restrictToPaymentMethods": nil]
}
case .failPaymentAttempt(let problemType, let errorCode):
return ["problemType": problemType,
return ["problemType": problemType.rawValue,
"errorCode": errorCode]
default:
return nil
Expand Down
18 changes: 8 additions & 10 deletions SwedbankPaySDK/Classes/SwedbankPayPaymentSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public extension SwedbankPaySDK {
}
}

private func launchClientApp(task: IntegrationTask) {
private func launchClientApp(task: IntegrationTask, failPaymentAttemptOperation: OperationOutputModel) {
guard let href = task.href, var components = URLComponents(string: href) else {
self.delegate?.sdkProblemOccurred(problem: .internalInconsistencyError)

Expand All @@ -375,15 +375,12 @@ public extension SwedbankPaySDK {
if let url = components.url {
DispatchQueue.main.async {
UIApplication.shared.open(url) { complete in
self.instrument = nil

if complete {
self.hasLaunchClientAppURLs.append(url)
self.instrument = nil
} else {
self.delegate?.sdkProblemOccurred(problem: .clientAppLaunchFailed)

BeaconService.shared.log(type: .sdkCallbackInvoked(name: "sdkProblemOccurred",
succeeded: self.delegate != nil,
values: ["problem": SwedbankPaySDK.PaymentSessionProblem.clientAppLaunchFailed.rawValue]))
self.makeRequest(router: .failPaymentAttempt(problemType: .clientAppLaunchFailed, errorCode: nil), operation: failPaymentAttemptOperation)
}

BeaconService.shared.log(type: .launchClientApp(values: ["callbackUrl": self.orderInfo?.paymentUrl?.absoluteString ?? "",

Check warning on line 386 in SwedbankPaySDK/Classes/SwedbankPayPaymentSession.swift

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SwedbankPaySDK/Classes/SwedbankPayPaymentSession.swift#L386

Line should be 120 characters or less; currently it has 145 characters
Expand All @@ -410,9 +407,9 @@ public extension SwedbankPaySDK {
case .success(let paymentOutputModel):
self.sessionOperationHandling(paymentOutputModel: paymentOutputModel, culture: paymentOutputModel.paymentSession.culture)
case .failure(ApplePayError.userCancelled):
self.makeRequest(router: .failPaymentAttempt(problemType: "UserCancelled", errorCode: ""), operation: failPaymentAttemptOperation)
self.makeRequest(router: .failPaymentAttempt(problemType: .userCancelled, errorCode: nil), operation: failPaymentAttemptOperation)

Check warning on line 410 in SwedbankPaySDK/Classes/SwedbankPayPaymentSession.swift

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

SwedbankPaySDK/Classes/SwedbankPayPaymentSession.swift#L410

Line should be 120 characters or less; currently it has 150 characters
case .failure(let error):
self.makeRequest(router: .failPaymentAttempt(problemType: "TechnicalError", errorCode: error.localizedDescription), operation: failPaymentAttemptOperation)
self.makeRequest(router: .failPaymentAttempt(problemType: .technicalError, errorCode: error.localizedDescription), operation: failPaymentAttemptOperation)
}
}
}
Expand Down Expand Up @@ -528,10 +525,11 @@ public extension SwedbankPaySDK {
self.instrument = nil
} else if let launchClientApp = operations.first(where: { $0.firstTask(withRel: .launchClientApp) != nil }),
let tasks = launchClientApp.firstTask(withRel: .launchClientApp),
let failPayment = paymentOutputModel.paymentSession.methods?.firstMethod(withName: AvailableInstrument.swish(prefills: nil).paymentMethod)?.operations?.firstOperation(withRel: .failPaymentAttempt),
!hasLaunchClientAppURLs.contains(where: { $0.absoluteString.contains(tasks.href ?? "") }) {
// We have an active launchClientApp task, and the contained URL isn't in the list of already launched Client App URLs, launch the external app on the device

self.launchClientApp(task: launchClientApp.firstTask(withRel: .launchClientApp)!)
self.launchClientApp(task: tasks, failPaymentAttemptOperation: failPayment)
} else if let scaMethodRequest = operations.first(where: { $0.firstTask(withRel: .scaMethodRequest) != nil }),
let task = scaMethodRequest.firstTask(withRel: .scaMethodRequest),
let href = task.href,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public extension SwedbankPaySDK {
case paymentSessionAPIRequestFailed(error: Error, retry: (()->Void)?)
case paymentControllerPaymentFailed(error: Error, retry: (()->Void)?)
case paymentSession3DSecureViewControllerLoadFailed(error: Error, retry: (()->Void)?)
case clientAppLaunchFailed
case internalInconsistencyError
case automaticConfigurationFailed

Expand All @@ -32,7 +31,6 @@ public extension SwedbankPaySDK {
case .paymentSessionAPIRequestFailed: "paymentSessionAPIRequestFailed"
case .paymentControllerPaymentFailed: "paymentControllerPaymentFailed"
case .paymentSession3DSecureViewControllerLoadFailed: "paymentSession3DSecureViewControllerLoadFailed"
case .clientAppLaunchFailed: "clientAppLaunchFailed"
case .internalInconsistencyError: "internalInconsistencyError"
case .automaticConfigurationFailed: "automaticConfigurationFailed"
}
Expand Down

0 comments on commit d25f198

Please sign in to comment.