diff --git a/GiniComponents/GiniUtilites/Sources/GiniUtilites/Price.swift b/GiniComponents/GiniUtilites/Sources/GiniUtilites/Price.swift index 8ecaeb011..099c4b49b 100644 --- a/GiniComponents/GiniUtilites/Sources/GiniUtilites/Price.swift +++ b/GiniComponents/GiniUtilites/Sources/GiniUtilites/Price.swift @@ -12,9 +12,18 @@ import Foundation public struct Price { // Decimal value - public var value: Decimal + public var value: Decimal { + didSet { + if value > Price.maxValue { + value = Price.maxValue + } + } + } // Currency code let currencyCode: String + + // Maximum allowed value + private static let maxValue: Decimal = 99999.99 /** Returns a price structure with decimal value and currency code from extraction string diff --git a/HealthSDK/GiniHealthSDK/Sources/GiniHealthSDK/Core/PaymentComponentsController+Helpers.swift b/HealthSDK/GiniHealthSDK/Sources/GiniHealthSDK/Core/PaymentComponentsController+Helpers.swift index 2d7a6192b..996fc18de 100644 --- a/HealthSDK/GiniHealthSDK/Sources/GiniHealthSDK/Core/PaymentComponentsController+Helpers.swift +++ b/HealthSDK/GiniHealthSDK/Sources/GiniHealthSDK/Core/PaymentComponentsController+Helpers.swift @@ -304,7 +304,7 @@ extension PaymentComponentsController { It also increments the onboarding count for the selected payment provider. - Parameter qrCodeData: A qrCode data information for the document associated payment request generated by the payment details. - - Parameter paymentRequestId:The payment request id from generated from the payment info extracted from the invoice + - Parameter paymentRequestId: The payment request id from generated from the payment info extracted from the invoice - Returns: A configured `BottomSheetViewController` for sharing invoices. */ public func shareInvoiceBottomSheet(qrCodeData: Data, paymentRequestId: String) -> BottomSheetViewController { diff --git a/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailView.swift b/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailView.swift index 24144f9f8..79e51f279 100644 --- a/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailView.swift +++ b/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailView.swift @@ -99,7 +99,7 @@ extension OrderDetailView: UITextFieldDelegate { */ func updateAmoutToPayWithCurrencyFormat() { let textField = Self.amountTextField - if textField.hasText, let text = textField.text { + if textField.hasText, let text = textField.text?.replacingOccurrences(of: ".", with: "") { if let priceValue = text.decimal(), var price = order?.price { price.value = priceValue diff --git a/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailViewController.swift b/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailViewController.swift index c2b88b84b..ce607d0f8 100644 --- a/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailViewController.swift +++ b/HealthSDK/GiniHealthSDKExample/GiniHealthSDKExample/OrdersList/OrderDetailViewController.swift @@ -142,15 +142,14 @@ final class OrderDetailViewController: UIViewController { order.recipient = textFields[NSLocalizedString(Fields.recipient.rawValue, comment: "")]?.text ?? "" order.purpose = textFields[NSLocalizedString(Fields.purpose.rawValue, comment: "")]?.text ?? "" - var text = textFields[NSLocalizedString(Fields.amountToPay.rawValue, comment: "")]?.text ?? "" - text = text.replacingOccurrences(of: ",", with: ".") - if let decimalAmount = Decimal(string: text) { - var price = Price(extractionString: order.amountToPay) ?? Price(value: decimalAmount, currencyCode: "€") - price.value = decimalAmount - - order.amountToPay = price.extractionString - } else { - order.amountToPay = Price(value: .zero, currencyCode: "€").extractionString + let text = textFields[NSLocalizedString(Fields.amountToPay.rawValue, comment: "")]?.text ?? "" + if let priceValue = text.decimal() { + let price = Price(value: priceValue, currencyCode: "€") + if priceValue > 0 { + order.amountToPay = price.extractionString + } else { + order.amountToPay = Price(value: .zero, currencyCode: "€").extractionString + } } }