Skip to content

Commit

Permalink
SP-64 Sluta använda hårdkodad NotificationURL till CreditCard authent…
Browse files Browse the repository at this point in the history
…ication request
  • Loading branch information
mbalsiger committed Sep 6, 2024
1 parent 9d92103 commit 2bcf6a7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct OperationOutputModel: Codable, Hashable {
let method: String?
let next: Bool?
let tasks: [IntegrationTask]?
let expects: [ExpectationModel]?
}

extension OperationOutputModel {
Expand Down
1 change: 1 addition & 0 deletions SwedbankPaySDK/Classes/Api/Models/ProblemDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public extension SwedbankPaySDK {
public let title: String?
public let status: Int32?
public let detail: String?
public let originalDetail: String?

let operation: OperationOutputModel?
}
Expand Down
2 changes: 0 additions & 2 deletions SwedbankPaySDK/Classes/Api/SwedbankPayAPIConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ struct SwedbankPayAPIConstants {
static var requestTimeoutInterval = 10.0
static var sessionTimeoutInterval = 20.0
static var creditCardTimoutInterval = 30.0

static var notificationUrl = "https://fake.payex.com/notification"
}

private enum HTTPHeaderField: String {
Expand Down
10 changes: 5 additions & 5 deletions SwedbankPaySDK/Classes/Api/SwedbankPayAPIEnpointRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Endpoint {
enum EnpointRouter {
case expandMethod(instrument: SwedbankPaySDK.PaymentAttemptInstrument)
case startPaymentAttempt(instrument: SwedbankPaySDK.PaymentAttemptInstrument, culture: String?)
case createAuthentication(methodCompletionIndicator: String)
case createAuthentication(methodCompletionIndicator: String, notificationUrl: String)
case completeAuthentication(cRes: String)
case getPayment
case preparePayment
Expand Down Expand Up @@ -80,23 +80,23 @@ struct SwedbankPayAPIEnpointRouter: EndpointRouterProtocol {
"screenWidth": String(Int32(UIScreen.main.nativeBounds.width)),
"screenColorDepth": String(24)],
"browser": ["acceptHeader": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"languageHeader": Locale.current.identifier,
"languageHeader": Locale.current.identifier.replacingOccurrences(of: "_", with: "-"),
"timeZoneOffset": TimeZone.current.offsetFromGMT(),
"javascriptEnabled": true],
"service": ["name": "SwedbankPaySDK-iOS",
"version": SwedbankPaySDK.VersionReporter.currentVersion]
]
case .createAuthentication(let methodCompletionIndicator):
case .createAuthentication(let methodCompletionIndicator, let notificationUrl):
return ["methodCompletionIndicator": methodCompletionIndicator,
"notificationUrl": SwedbankPayAPIConstants.notificationUrl,
"notificationUrl": notificationUrl,
"requestWindowSize": "FULLSCREEN",
"client": ["userAgent": SwedbankPaySDK.VersionReporter.userAgent,
"ipAddress": NetworkStatusProvider.getAddress(for: .wifi) ?? NetworkStatusProvider.getAddress(for: .cellular) ?? "",
"screenHeight": String(Int32(UIScreen.main.nativeBounds.height)),
"screenWidth": String(Int32(UIScreen.main.nativeBounds.width)),
"screenColorDepth": String(24)],
"browser": ["acceptHeader": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"languageHeader": Locale.current.identifier,
"languageHeader": Locale.current.identifier.replacingOccurrences(of: "_", with: "-"),
"timeZoneOffset": TimeZone.current.offsetFromGMT(),
"javascriptEnabled": true]
]
Expand Down
26 changes: 22 additions & 4 deletions SwedbankPaySDK/Classes/SwedbankPayPaymentSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public extension SwedbankPaySDK {
private var hasShownProblemDetails: [ProblemDetails] = []
private var scaMethodRequestDataPerformed: [(name: String, value: String)] = []
private var scaRedirectDataPerformed: [(name: String, value: String)] = []
private var notificationUrl: String? = nil

private var sessionStartTimestamp = Date()

Expand Down Expand Up @@ -107,6 +108,7 @@ public extension SwedbankPaySDK {
hasShownProblemDetails = []
scaMethodRequestDataPerformed = []
scaRedirectDataPerformed = []
notificationUrl = nil
hasShownAvailableInstruments = false

if automaticConfiguration {
Expand All @@ -117,7 +119,8 @@ public extension SwedbankPaySDK {
href: sessionURL.absoluteString,
method: "GET",
next: nil,
tasks: nil)
tasks: nil,
expects: nil)

sessionStartTimestamp = Date()
makeRequest(router: nil, operation: model)
Expand Down Expand Up @@ -425,13 +428,27 @@ public extension SwedbankPaySDK {
}
}
} else if let createAuthentication = operations.first(where: { $0.rel == .createAuthentication }),
let task = createAuthentication.firstTask(with: .scaMethodRequest),
let scaMethod = scaMethodRequestDataPerformed.first(where: { $0.name == task.expects?.first(where: { $0.name == "threeDSMethodData" })?.value ?? "" }) {
makeRequest(router: .createAuthentication(methodCompletionIndicator: scaMethod.value), operation: createAuthentication)
let notificationUrl = createAuthentication.expects?.first(where: { $0.name == "NotificationUrl" })?.value {
self.notificationUrl = notificationUrl

if let task = createAuthentication.firstTask(with: .scaMethodRequest),
let scaMethod = scaMethodRequestDataPerformed.first(where: { $0.name == task.expects?.first(where: { $0.name == "threeDSMethodData" })?.value ?? "" }) {
makeRequest(router: .createAuthentication(methodCompletionIndicator: scaMethod.value, notificationUrl: notificationUrl), operation: createAuthentication)
} else if let methodCompletionIndicator = createAuthentication.expects?.first(where: { $0.name == "methodCompletionIndicator" })?.value {
makeRequest(router: .createAuthentication(methodCompletionIndicator: methodCompletionIndicator, notificationUrl: notificationUrl), operation: createAuthentication)
} else {
self.delegate?.sdkProblemOccurred(problem: .internalInconsistencyError)

BeaconService.shared.log(type: .sdkCallbackInvoked(name: "sdkProblemOccurred",
succeeded: self.delegate != nil,
values: ["problem": SwedbankPaySDK.PaymentSessionProblem.internalInconsistencyError.rawValue]))
}
} else if let operation = operations.first(where: { $0.firstTask(with: .scaRedirect) != nil }),
let task = operation.firstTask(with: .scaRedirect),
!scaRedirectDataPerformed.contains(where: { $0.name == task.expects?.first(where: { $0.name == "creq" })?.value }) {
DispatchQueue.main.async {
self.webViewController.notificationUrl = notificationUrl

self.delegate?.show3DSecureViewController(viewController: self.webViewController)

BeaconService.shared.log(type: .sdkCallbackInvoked(name: "show3DSecureViewController",
Expand Down Expand Up @@ -471,6 +488,7 @@ public extension SwedbankPaySDK {
hasShownProblemDetails = []
scaMethodRequestDataPerformed = []
scaRedirectDataPerformed = []
notificationUrl = nil
hasShownAvailableInstruments = false
} else if (operations.contains(where: { $0.rel == .expandMethod }) || operations.contains(where: { $0.rel == .startPaymentAttempt })) &&
hasShownAvailableInstruments == false {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class SwedbankPaySCAWebViewController: UIViewController {

let activityView = UIActivityIndicatorView()

var notificationUrl: String?

init() {
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
Expand Down Expand Up @@ -148,7 +150,7 @@ extension SwedbankPaySCAWebViewController: WKNavigationDelegate {
) {
let request = navigationAction.request

if request.url?.absoluteString == SwedbankPayAPIConstants.notificationUrl,
if request.url?.absoluteString == self.notificationUrl,
let httpBody = request.httpBody,
let bodyString = String(data: httpBody, encoding: .utf8),
let urlComponents = URLComponents(string: "https://www.apple.com?\(bodyString)"),
Expand Down

0 comments on commit 2bcf6a7

Please sign in to comment.