Skip to content

Commit

Permalink
feat(GiniBankSDK): recalculate max price value for Skonto RA items
Browse files Browse the repository at this point in the history
PP-906
  • Loading branch information
mrkulik committed Oct 30, 2024
1 parent 8f1357b commit a4b63ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class DigitalInvoiceViewModel {
weak var delegate: DigitalInvoiceViewModelDelagate?
var invoice: DigitalInvoice? {
didSet {
skontoViewModel?.setMaximumAmountToPayValue(invoice?.maximumAvailablePrice)
skontoViewModel?.setAmountToPayPrice(invoice?.total?.stringWithoutSymbol ?? "")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public struct DigitalInvoice {
return amountToPay
}
}

var maximumAvailablePrice: Decimal {
let maxPricePerItem = 99999.99
let totalMaxValue = maxPricePerItem * Double(lineItems.count)
let roundedValue = (totalMaxValue * 100).rounded(.up) / 100
return Decimal(roundedValue)
}
}

extension DigitalInvoice {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ class SkontoViewModel {
}
}

func setMaximumAmountToPayValue(_ value: Decimal?) {
guard let value else { return }
maximumAmountToPayValue = value
}

private func setPrice(_ price: String, maxValue: Decimal, errorMessage: String, completion: (Price) -> Void) {
let validationMessage = validatePrice(price, maxValue: maxValue, errorMessage: errorMessage)
if let validationMessage {
Expand Down

0 comments on commit a4b63ea

Please sign in to comment.