-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Co-Badged Cards/SwiftUI/Co-Badged Cards Example/Models/PrimerCardDataErrorsModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// PrimerCardDataErrorsModel.swift | ||
// Co-Badged Cards Example | ||
// | ||
// Created by Jack Newcombe on 26/01/2024. | ||
// | ||
|
||
import Foundation | ||
import PrimerSDK | ||
|
||
class PrimerCardDataErrorsModel: PrimerBaseCardDataModel { | ||
|
||
override init() { | ||
super.init() | ||
logger.info("[PrimerCardDataErrorsModel.init]") | ||
} | ||
|
||
fileprivate func clearErrors() { | ||
self.cardNumber = "" | ||
self.expiryDate = "" | ||
self.cvvNumber = "" | ||
self.cardholderName = "" | ||
self.selectedCardNetwork = .unknown | ||
} | ||
} | ||
|
||
extension PrimerCardDataErrorsModel: PrimerDataServiceErrorsDelegate { | ||
func didReceiveErrors(errors: [Error]) { | ||
logger.info("[PrimerCardDataModel.didReceiveErrors]") | ||
DispatchQueue.main.async { | ||
self.clearErrors() | ||
|
||
let validationErrors = errors.reversed().compactMap { $0 as? PrimerValidationError } | ||
|
||
validationErrors.forEach { error in | ||
logger.info("[PrimerCardDataModel.didReceiveErrors] error => \(error.errorId)") | ||
switch error { | ||
case .invalidCardnumber(let message, _, _): | ||
self.cardNumber = message | ||
case .invalidCardType(let message, _, _): | ||
self.cardNumber = message // Overrides above | ||
case .invalidExpiryDate(let message, _, _): | ||
self.expiryDate = message | ||
case .invalidCvv(let message, _, _): | ||
self.cvvNumber = message | ||
case .invalidCardholderName(let message, _, _): | ||
self.cardholderName = message | ||
default: break | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters