Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Release 5.10.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
IngenicoEPayments committed Mar 9, 2023
1 parent 4d14689 commit 300c444
Show file tree
Hide file tree
Showing 214 changed files with 3,577 additions and 1,518 deletions.
11 changes: 11 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project: IngenicoConnectKit.xcodeproj
schemes:
- IngenicoConnectKit
targets:
- IngenicoConnectKit
- IngenicoConnectKitTests
clean_build: true
retain_public: true
build_arguments:
- -destination
- platform="iOS Simulator,name=iPhone 13,OS=15.5"
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
excluded:
- Carthage/*
2 changes: 1 addition & 1 deletion IngenicoConnectKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "IngenicoConnectKit"
s.version = "5.9.0"
s.version = "5.10.0"
s.summary = "Ingenico Connect Swift SDK"
s.description = <<-DESC
This native iOS SDK facilitates handling payments in your apps
Expand Down
233 changes: 165 additions & 68 deletions IngenicoConnectKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

84 changes: 44 additions & 40 deletions IngenicoConnectKit/AssetManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,133 +24,136 @@ extension UserDefaults {
public class AssetManager {
public let logoFormat = "pp_logo_%@"
public let tooltipFormat = "pp_%@_tooltip_%@"

public var documentsFolderPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
public var fileManager = FileManager() // var for testing
public var sdkBundle = Bundle(path: SDKConstants.kSDKBundlePath ?? "") { // var for testing
didSet {
initImageMapping()
}
}
public var imageMapping: [AnyHashable : Any]?
public var imageMapping: [AnyHashable: Any]?

public init() {
initImageMapping()
}

/*
An initial mapping from image identifiers to paths is stored in the bundle.
This mapping is transferred to the device and kept up to date.
*/
public func initImageMapping() {
guard let sdk = sdkBundle, let imageMappingPath = sdk.path(forResource: "imageMapping", ofType: "plist"),
let mapping = fileManager.dict(atPath: imageMappingPath) as? [AnyHashable : Any] else {
let mapping = fileManager.dict(atPath: imageMappingPath) as? [AnyHashable: Any] else {
return
}
imageMapping = mapping

UserDefaults.standard[SDKConstants.kImageMapping] = imageMapping
UserDefaults.standard[SDKConstants.kImageMappingInitialized] = true
UserDefaults.standard.synchronize()
}

public func logoIdentifier(with paymentItem: BasicPaymentItem) -> String {
guard let url = URL(string: paymentItem.displayHints.logoPath) else {
Macros.DLog(message: "Logo path not found.")
return "Logo path not found."
}
var fileName = url.lastPathComponent
fileName = fileName.replacingOccurrences(of: ".png", with: "")

if let range = fileName.range(of: "_", options: .backwards) {
fileName = String(fileName[..<range.lowerBound])
}

return fileName
}

public func initializeImages(for paymentItems: [BasicPaymentItem]) {
for paymentItem in paymentItems {
paymentItem.displayHints.logoImage = logoImage(forItem: paymentItem.identifier)
}
}

public func initializeImages(for paymentItem: BasicPaymentItem) {
paymentItem.displayHints.logoImage = logoImage(forItem: paymentItem.identifier)

if let item = paymentItem as? PaymentItem {
for field in item.fields.paymentProductFields where field.displayHints.tooltip?.imagePath != nil {
field.displayHints.tooltip?.image = tooltipImage(forItem: item.identifier, field: field.identifier)
}
}
}

public func updateImagesAsync(for paymentItems: [BasicPaymentItem], baseURL: String) {
updateImagesAsync(for: paymentItems, baseURL: baseURL, nil)
}

public func updateImagesAsync(for paymentItem: BasicPaymentItem, baseURL: String) {
updateImagesAsync(for: paymentItem, baseURL: baseURL, nil)
}

public func updateImagesAsync(for paymentItems: [BasicPaymentItem], baseURL: String, _ callback: (() -> Void)?) {
DispatchQueue.global().async {
self.updateImages(for: paymentItems, baseURL: baseURL)

if let callback = callback {
DispatchQueue.main.async {
callback()
}
}
}
}

public func updateImagesAsync(for paymentItem: BasicPaymentItem, baseURL: String, _ callback: (() -> Void)?) {
DispatchQueue.global().async {
self.updateImages(for: paymentItem, baseURL: baseURL)

if let callback = callback {
DispatchQueue.main.async {
callback()
}
}
}
}

public func updateImages(for paymentItems: [BasicPaymentItem], baseURL: String) {
for object in paymentItems {
let paymentItem = object
let logoPath = paymentItem.displayHints.logoPath
let identifier = String(format: self.logoFormat, paymentItem.identifier)
updateImage(withIdentifier: identifier, newPath: logoPath, baseURL: baseURL)
}

UserDefaults.standard[SDKConstants.kImageMapping] = imageMapping
UserDefaults.standard.synchronize()
}

public func updateImages(for paymentItem: BasicPaymentItem, baseURL: String) {
if let item = paymentItem as? PaymentItem {
let fields = item.fields

for field in fields.paymentProductFields where field.displayHints.tooltip?.imagePath != nil {
let identifier = String(format: self.tooltipFormat, paymentItem.identifier, field.identifier)
self.updateImage(withIdentifier: identifier, newPath: field.displayHints.tooltip!.imagePath!, baseURL: baseURL)
self.updateImage(
withIdentifier: identifier,
newPath: field.displayHints.tooltip!.imagePath!,
baseURL: baseURL
)
}
}



UserDefaults.standard[SDKConstants.kImageMapping] = imageMapping
UserDefaults.standard.synchronize()
}

public func updateImage(withIdentifier identifier: String, newPath: String, baseURL: String) {
var currentPath = ""

if let img = imageMapping, let path = img[identifier] as? String {
currentPath = path
}

if currentPath == newPath {
return
}
Expand All @@ -164,19 +167,20 @@ public class AssetManager {
return
}
let newURLString = "\(baseURL)/\(newPathEncoded)"
guard let newURLStringEncoded = newURLString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
guard let newURLStringEncoded =
newURLString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
Macros.DLog(message: "Could not encode url string for: \(newURLString)")
return
}

guard let newURL = URL(string: newURLStringEncoded) else {
Macros.DLog(message: "Unable to create URL for baseURL: \(baseURL) & newPath: \(newPath)")
return

}

let imagePath = URL(fileURLWithPath: "\(documentsFolderPath)/\(identifier)")

do {
let data = try fileManager.data(atURL: newURL)
try fileManager.write(toURL: imagePath, data: data, options: [])
Expand All @@ -187,37 +191,37 @@ public class AssetManager {
Macros.DLog(message: "Unable to save image: \(identifier)")
}
}

public func logoImage(forItem paymentItemId: String) -> UIImage {
let identifier = String(format: logoFormat, paymentItemId)
return image(forIdentifier: identifier)
}

public func tooltipImage(forItem paymentItemId: String, field paymentProductFieldId: String) -> UIImage {
let identifier = String(format: self.tooltipFormat, paymentItemId, paymentProductFieldId)
return image(forIdentifier: identifier)
}

public func image(forIdentifier identifier: String) -> UIImage {
/*
If an image for this identifier is available in the documents folder,
this image is newer than the one in the bundle and should be used.
*/
let imagePath = "\(documentsFolderPath)/\(identifier)"

if let image = fileManager.image(atPath: imagePath) {
return image
}

/*
If there's no updated image available in the documents folder,
use the one in the bundle.
*/
if let sdk = sdkBundle, let imagePath = sdk.path(forResource: identifier , ofType: "png"),
if let sdk = sdkBundle, let imagePath = sdk.path(forResource: identifier, ofType: "png"),
let image = fileManager.image(atPath: imagePath) {
return image
}

// Could not find image so return an empty image
return UIImage()
}
Expand Down
2 changes: 1 addition & 1 deletion IngenicoConnectKit/Base64/Base64+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Data {
.replacingOccurrences(of: "+", with: "-")
.replacingOccurrences(of: "/", with: "_")
}

public func encode() -> String {
return self.base64EncodedString()
}
Expand Down
Loading

0 comments on commit 300c444

Please sign in to comment.