Skip to content

Commit

Permalink
Merge branch 'feature/SP-80-Stöd-för-att-återställa-till-Menu-mode' i…
Browse files Browse the repository at this point in the history
…nto 'feature/native-payments'

SP-80 Stöd för att återställa till Menu mode

See merge request swedbank-pay/swedbank-pay-sdk-ios!8
  • Loading branch information
mbalsiger committed Oct 15, 2024
2 parents c792773 + e68e1c8 commit fcc7706
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 53 deletions.
15 changes: 11 additions & 4 deletions SwedbankPaySDK/Classes/Api/SwedbankPayAPIEnpointRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum EnpointRouter {
case acknowledgeFailedAttempt
case abortPayment
case applePay(paymentPayload: String)
case customizePayment(instrument: SwedbankPaySDK.PaymentAttemptInstrument)
case customizePayment(instrument: SwedbankPaySDK.PaymentAttemptInstrument?)
}

protocol EndpointRouterProtocol {
Expand Down Expand Up @@ -122,13 +122,20 @@ struct SwedbankPayAPIEnpointRouter: EndpointRouterProtocol {
return ["instrument": "ApplePay",
"paymentPayload": paymentPayload]
case .customizePayment(let instrument):
if case .newCreditCard(let enabledPaymentDetailsConsentCheckbox) = instrument {
guard let instrument = instrument else {
return ["paymentMethod": nil]
}

switch instrument {
case .newCreditCard(let enabledPaymentDetailsConsentCheckbox):
return ["paymentMethod": "CreditCard",
"hideStoredPaymentOptions": true,
"showConsentAffirmation" : enabledPaymentDetailsConsentCheckbox,
]
} else {
return nil
case .swish,
.creditCard,
.applePay:
return ["paymentMethod": instrument.identifier]
}
default:
return nil
Expand Down
81 changes: 32 additions & 49 deletions SwedbankPaySDK/Classes/SwedbankPayPaymentSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,73 +157,29 @@ public extension SwedbankPaySDK {
break
}

var succeeded = false

if case .newCreditCard = instrument {
if ongoingModel.paymentSession.instrumentModePaymentMethod == nil || ongoingModel.paymentSession.instrumentModePaymentMethod != "CreditCard",
let operation = ongoingModel.operations?.first(where: { $0.rel == .customizePayment }) {
sessionStartTimestamp = Date()

makeRequest(router: .customizePayment(instrument: instrument), operation: operation)

succeeded = true
} else {
DispatchQueue.main.async {
self.createSwedbankPaySDKController()
}
}
} else if let operation = ongoingModel.paymentSession.methods?
.first(where: { $0.name == instrument.identifier })?.operations?
.first(where: { $0.rel == .expandMethod || $0.rel == .startPaymentAttempt || $0.rel == .getPayment }) {

sessionStartTimestamp = Date()

switch operation.rel {
case .expandMethod:
makeRequest(router: .expandMethod(instrument: instrument), operation: operation)
case .startPaymentAttempt:
makeRequest(router: .startPaymentAttempt(instrument: instrument, culture: ongoingModel.paymentSession.culture), operation: operation)
self.instrument = nil
case .getPayment:
makeRequest(router: .getPayment, operation: operation)
default:
fatalError("Operantion rel is not supported for makeNativePaymentAttempt: \(String(describing: operation.rel))")
}

succeeded = true
} else {
DispatchQueue.main.async {
self.delegate?.sdkProblemOccurred(problem: .paymentSessionEndStateReached)

BeaconService.shared.log(type: .sdkCallbackInvoked(name: "sdkProblemOccurred",
succeeded: self.delegate != nil,
values: ["problem": SwedbankPaySDK.PaymentSessionProblem.paymentSessionEndStateReached.rawValue]))
}

return
}
sessionOperationHandling(paymentOutputModel: ongoingModel, culture: ongoingModel.paymentSession.culture)

switch instrument {
case .swish(let msisdn):
BeaconService.shared.log(type: .sdkMethodInvoked(name: "makePaymentAttempt",
succeeded: succeeded,
succeeded: true,
values: ["instrument": instrument.identifier,
"msisdn": msisdn]))
case .creditCard(let prefill):
BeaconService.shared.log(type: .sdkMethodInvoked(name: "makePaymentAttempt",
succeeded: succeeded,
succeeded: true,
values: ["instrument": instrument.identifier,
"paymentToken": prefill.paymentToken,
"cardNumber": prefill.maskedPan,
"cardExpiryMonth": prefill.expiryMonth,
"cardExpiryYear": prefill.expiryYear]))
case .applePay:
BeaconService.shared.log(type: .sdkMethodInvoked(name: "makePaymentAttempt",
succeeded: succeeded,
succeeded: true,
values: ["instrument": instrument.identifier]))
case .newCreditCard(enabledPaymentDetailsConsentCheckbox: let enabledPaymentDetailsConsentCheckbox):
BeaconService.shared.log(type: .sdkMethodInvoked(name: "makePaymentAttempt",
succeeded: succeeded,
succeeded: true,
values: ["instrument": instrument.identifier,
"showConsentAffirmation": enabledPaymentDetailsConsentCheckbox.description]))
}
Expand Down Expand Up @@ -473,6 +429,15 @@ public extension SwedbankPaySDK {
} else if let attemptPayload = operations.first(where: { $0.rel == .attemptPayload }),
let walletSdk = attemptPayload.firstTask(with: .walletSdk) {
makeApplePayAuthorization(operation: attemptPayload, task: walletSdk)
} else if let instrument = self.instrument,
ongoingModel?.paymentSession.instrumentModePaymentMethod != nil && ongoingModel?.paymentSession.instrumentModePaymentMethod != instrument.identifier,
let customizePayment = ongoingModel?.operations?.first(where: { $0.rel == .customizePayment }) {
makeRequest(router: .customizePayment(instrument: nil), operation: customizePayment)
} else if let instrument = self.instrument,
case .newCreditCard = instrument,
ongoingModel?.paymentSession.instrumentModePaymentMethod == nil || ongoingModel?.paymentSession.instrumentModePaymentMethod != instrument.identifier,
let customizePayment = ongoingModel?.operations?.first(where: { $0.rel == .customizePayment }) {
makeRequest(router: .customizePayment(instrument: instrument), operation: customizePayment)
} else if case .newCreditCard = self.instrument,
ongoingModel?.paymentSession.instrumentModePaymentMethod == "CreditCard" {
DispatchQueue.main.async {
Expand Down Expand Up @@ -591,6 +556,24 @@ public extension SwedbankPaySDK {
succeeded: self.delegate != nil,
values: ["instruments": availableInstruments.compactMap({ $0.identifier }).joined(separator: ";")]))
}
} else if let instrument = self.instrument,
let operation = ongoingModel?.paymentSession.methods?
.first(where: { $0.name == instrument.identifier })?.operations?
.first(where: { $0.rel == .expandMethod || $0.rel == .startPaymentAttempt || $0.rel == .getPayment }) {

sessionStartTimestamp = Date()

switch operation.rel {
case .expandMethod:
makeRequest(router: .expandMethod(instrument: instrument), operation: operation)
case .startPaymentAttempt:
makeRequest(router: .startPaymentAttempt(instrument: instrument, culture: culture), operation: operation)
self.instrument = nil
case .getPayment:
makeRequest(router: .getPayment, operation: operation)
default:
fatalError("Operantion rel is not supported for makeNativePaymentAttempt: \(String(describing: operation.rel))")
}
} else if let getPayment = operations.first(where: { $0.rel == .getPayment }) {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.sessionStartTimestamp = Date()
Expand Down

0 comments on commit fcc7706

Please sign in to comment.