Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(GiniHealthSDK): Payment providers added to payment component IPC-97 #451

Merged
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4564032
feat(GiniHealthSDK): Payment component linked with payment providers …
razvancapra Feb 1, 2024
16877f4
Merge branch 'payment-component-pay-invoice-button' into IPC-110_paym…
razvancapra Feb 2, 2024
e38b216
fix(GiniHealthSDK): Fix small issues, prepare for review and clean co…
razvancapra Feb 2, 2024
0052d7b
fix(GiniHealthSDK): protocol structure included for end client IPC-97
razvancapra Feb 5, 2024
49a70e1
fix(GiniHealthSDK): Fix more information button tap + passing actions…
razvancapra Feb 5, 2024
1989589
fix(GiniHealthSDK): Clean payment view constraints + Adding constants…
razvancapra Feb 5, 2024
455c4a7
fix(GiniHealthSDK): Fix suggestions from review + fetch payment provi…
razvancapra Feb 7, 2024
1718dee
fix(GiniHealthSDK): Fix wrong replacement IPC-97
razvancapra Feb 7, 2024
6b218f9
Merge branch 'payment-component-pay-invoice-button' into IPC-110_paym…
razvancapra Feb 8, 2024
73eb1dc
Merge branch 'payment-component-pay-invoice-button' into IPC-110_paym…
razvancapra Feb 9, 2024
e8ea055
fix(GiniHealthSDK): Fix isPayable protocol after merge
razvancapra Feb 9, 2024
b56d254
fix(GiniHealthSDK): Fix payment provider label name width
razvancapra Feb 9, 2024
edde48c
fix(GiniHealthSDK): Fix chevron icon color on dark mode
razvancapra Feb 9, 2024
155d5b2
Merge branch 'main' into IPC-110_payment-component-bank-available
razvancapra Feb 13, 2024
51ea7be
Merge branch 'payment-component-pay-invoice-button' into IPC-110_paym…
razvancapra Feb 19, 2024
f822c59
fix(GiniHealthSDK): Fix merge changes
razvancapra Feb 19, 2024
a89cbad
fix(GiniHealthSDK): Fix obtain payment providers on a different function
razvancapra Feb 19, 2024
0f148ee
fix(GiniHealthSDK): Fix sending the installed payment providers
razvancapra Feb 20, 2024
2dba0ef
fix(GiniHealthSDK): Fix indenation
razvancapra Feb 20, 2024
3c4be24
fix(GiniHealthSDK): Use button configurations for primary + secondary…
razvancapra Feb 22, 2024
ea9c732
Merge branch 'ipc-health-sdk-update' into IPC-110_payment-component-b…
razvancapra Feb 22, 2024
54a4f63
fix(GiniHealthSDK): Fixes info icon colour and more info label text c…
zladzeyka Feb 22, 2024
6589893
fix(GiniHealthSDK): Fix renaming, cleaning unused variables
razvancapra Feb 23, 2024
c2b9d45
fix(GiniHealthSDK): Fix layout issue to bank icon when payment provid…
razvancapra Feb 23, 2024
9aca000
fix(GiniHealthSDK): Fix colors on not installed payment provider
razvancapra Feb 23, 2024
5d6addb
fix(GiniHealthSDKexmaple): Adds Queried URL Schemes
zladzeyka Feb 23, 2024
5cadf2d
fix(GiniHealthSDK): Remove stored paymentProvider in invoice object
razvancapra Feb 26, 2024
4eea771
fix(GiniHealthSDK): Store selected payment provider in payment contro…
razvancapra Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import os

enum LogEvent {
public enum LogEvent {
case error
case success
case warning
Expand All @@ -29,7 +29,7 @@ public enum LogLevel {
case debug
}

func Log(_ message: String,
public func Log(_ message: String,
event: LogEvent) {
guard case .debug = GiniHealthAPI.logLevel else { return }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// String.swift
//
// Copyright © 2024 Gini GmbH. All rights reserved.
//


import UIKit

extension String {
func toColor() -> UIColor? {
return UIColor(hex: String.rgbaHexFrom(rgbHex: self))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// UIFont.swift
//
// Copyright © 2024 Gini GmbH. All rights reserved.
//


import UIKit

extension UIFont.TextStyle {
static let linkBold: UIFont.TextStyle = .init(rawValue: "kLinkBold")
static let subtitle2: UIFont.TextStyle = .init(rawValue: "kSubtitle2")
static let input: UIFont.TextStyle = .init(rawValue: "kInput")
static let button: UIFont.TextStyle = .init(rawValue: "kButton")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// UITapGestureRecognizer.swift
//
// Copyright © 2024 Gini GmbH. All rights reserved.
//


import UIKit

extension UITapGestureRecognizer {
func didTapAttributedTextInLabel(label: UILabel, targetText: String) -> Bool {
guard let attributedString = label.attributedText, let lblText = label.text else { return false }
let targetRange = (lblText as NSString).range(of: targetText)
//IMPORTANT label correct font for NSTextStorage needed
let mutableAttribString = NSMutableAttributedString(attributedString: attributedString)
mutableAttribString.addAttributes(
[NSAttributedString.Key.font: label.font ?? UIFont.smallSystemFontSize],
range: NSRange(location: 0, length: attributedString.length)
)
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: CGSize.zero)
let textStorage = NSTextStorage(attributedString: mutableAttribString)

// Configure layoutManager and textStorage
layoutManager.addTextContainer(textContainer)
textStorage.addLayoutManager(layoutManager)

// Configure textContainer
textContainer.lineFragmentPadding = 0.0
textContainer.lineBreakMode = label.lineBreakMode
textContainer.maximumNumberOfLines = label.numberOfLines
let labelSize = label.bounds.size
textContainer.size = labelSize

// Find the tapped character location and compare it to the specified range
let locationOfTouchInLabel = self.location(in: label)
let textBoundingBox = layoutManager.usedRect(for: textContainer)
let textContainerOffset = CGPoint(x: (labelSize.width - textBoundingBox.size.width) * 0.5 - textBoundingBox.origin.x,
y: (labelSize.height - textBoundingBox.size.height) * 0.5 - textBoundingBox.origin.y)
let locationOfTouchInTextContainer = CGPoint(x: locationOfTouchInLabel.x - textContainerOffset.x,
y: locationOfTouchInLabel.y - textContainerOffset.y)
let indexOfCharacter = layoutManager.characterIndex(for: locationOfTouchInTextContainer,
in: textContainer,
fractionOfDistanceBetweenInsertionPoints: nil)
return NSLocationInRange(indexOfCharacter, targetRange)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import UIKit
/**
The `GiniColor` class allows to customize color for the light and the dark modes.
*/

@objc public class GiniColor : NSObject {
var lightModeColor: UIColor
var darkModeColor: UIColor

/**
Creates a GiniColor with the colors for the light and dark modes

Expand All @@ -24,4 +25,21 @@ import UIKit
self.lightModeColor = lightModeColor
self.darkModeColor = darkModeColor
}

func uiColor() -> UIColor {
if #available(iOS 13, *) {
return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
if UITraitCollection.userInterfaceStyle == .dark {
/// Return the color for Dark Mode
return self.darkModeColor
} else {
/// Return the color for Light Mode
return self.lightModeColor
}
}
} else {
/// Return a fallback color for iOS 12 and lower.
return self.lightModeColor
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public final class GiniHealthConfiguration: NSObject {
*/
static var shared = GiniHealthConfiguration()

/**
Should be set if the main app's bundle is not used.
*/
var customResourceBundle: Bundle?

/**
Returns a `GiniHealthConfiguration` instance which allows to set individual configurations
to change the look and feel of the Gini Health SDK.
Expand Down Expand Up @@ -217,7 +222,6 @@ public final class GiniHealthConfiguration: NSObject {
*/
@objc public var infoBarCornerRadius: CGFloat = 12.0


// MARK: - Shared properties

/**
Expand All @@ -231,7 +235,9 @@ public final class GiniHealthConfiguration: NSObject {
light: UIFont.systemFont(ofSize: 14,
weight: .light),
thin: UIFont.systemFont(ofSize: 14,
weight: .thin),
weight: .thin),
medium: UIFont.systemFont(ofSize: 14,
weight: .medium),
isEnabled: false)
/**
Sets the color of the loading indicator to the specified color.
Expand All @@ -248,4 +254,13 @@ public final class GiniHealthConfiguration: NSObject {
*/
@objc public var loadingIndicatorScale: CGFloat = 1.0

var textStyleFonts: [UIFont.TextStyle: UIFont] = [
.caption1: UIFontMetrics(forTextStyle: .caption1).scaledFont(for: UIFont.systemFont(ofSize: 13, weight: .regular)),
.caption2: UIFontMetrics(forTextStyle: .caption2).scaledFont(for: UIFont.systemFont(ofSize: 12, weight: .regular)),
.linkBold: UIFontMetrics(forTextStyle: .linkBold).scaledFont(for: UIFont.systemFont(ofSize: 14, weight: .bold)),
.subtitle2: UIFontMetrics(forTextStyle: .subtitle2).scaledFont(for: UIFont.systemFont(ofSize: 14, weight: .medium)),
.input: UIFontMetrics(forTextStyle: .input).scaledFont(for: UIFont.systemFont(ofSize: 16, weight: .medium)),
.button: UIFontMetrics(forTextStyle: .button).scaledFont(for: UIFont.systemFont(ofSize: 16, weight: .bold))
]

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public class GiniFont: NSObject {
public var bold: UIFont
public var light: UIFont
public var thin: UIFont
public var medium: UIFont
public private(set) var isEnabled: Bool

public init(regular: UIFont, bold: UIFont, light: UIFont, thin: UIFont, isEnabled: Bool = true) {
public init(regular: UIFont, bold: UIFont, light: UIFont, thin: UIFont, medium: UIFont, isEnabled: Bool = true) {
self.regular = regular
self.bold = bold
self.light = light
self.thin = thin
self.medium = medium
self.isEnabled = isEnabled
}

Expand All @@ -50,6 +52,8 @@ public class GiniFont: NSObject {
return light
case .thin:
return thin
case .medium:
return medium
default:
assertionFailure("\(weight.rawValue) font weight is not supported")
return regular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func decimal(from inputFieldString: String) -> Decimal? {
A help price structure with decimal value and currency code, used in amout inpur field.
*/

struct Price {
public struct Price {
// Decimal value
var value: Decimal
// Currency code
Expand All @@ -103,7 +103,7 @@ struct Price {
- parameter extractionString: extracted string
*/

init?(extractionString: String) {
public init?(extractionString: String) {

let components = extractionString.components(separatedBy: ":")

Expand All @@ -130,7 +130,7 @@ struct Price {
}

// Formatted string with currency symbol
var string: String? {
public var string: String? {

let result = (Price.stringWithoutSymbol(from: value) ?? "") + " " + (currencySymbol ?? "")

Expand All @@ -152,3 +152,67 @@ struct Price {
return trimmedFormattedStringWithoutCurrency
}
}

/**
Returns an optional `UIColor` instance with the given `name` preferably from the client's bundle.

- parameter name: The name of the UIColor from `GiniColors` asset catalog.

- returns: color if found with name.
*/
func UIColorPreferred(named name: String) -> UIColor {
if let mainBundleColor = UIColor(named: name,
in: Bundle.main,
compatibleWith: nil) {
return mainBundleColor
}

if let customBundle = GiniHealthConfiguration.shared.customResourceBundle,
let customBundleColor = UIColor(named: name,
in: customBundle,
compatibleWith: nil) {
return customBundleColor
}

if let color = UIColor(named: name,
in: giniHealthBundleResource(),
compatibleWith: nil) {
return color
} else {
fatalError("The color named '\(name)' does not exist.")
}
}

func giniHealthBundleResource() -> Bundle {
Bundle.resource
}

extension Foundation.Bundle {
/**
The resource bundle associated with the current module.
- important: When `GiniHealthSDK` is distributed via Swift Package Manager, it will be synthesized automatically in the name of `Bundle.module`.
*/
static var resource: Bundle = {
let moduleName = "GiniHealthSDK"
let bundleName = "\(moduleName)_\(moduleName)"
let candidates = [
// Bundle should be present here when the package is linked into an App.
Bundle.main.resourceURL,

// Bundle should be present here when the package is linked into a framework.
Bundle(for: HealthSDKBundleFinder.self).resourceURL,

// For command-line tools.
Bundle.main.bundleURL]

for candidate in candidates {
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
return bundle
}
}
return Bundle(for: GiniHealth.self)
}()
}

private class HealthSDKBundleFinder {}
Loading
Loading