Skip to content

Commit

Permalink
Merge pull request #717 from gini/PP-906-iOS-RA-Skonto-Set-dynamic-fi…
Browse files Browse the repository at this point in the history
…nal-amount-to-pay-from-RA-into-Skonto-screen

feat(GiniBankSDK): recalculate max price value for Skonto RA items
  • Loading branch information
mrkulik authored Nov 8, 2024
2 parents f946bd1 + 7978ec5 commit bb6fe4c
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 @@ -181,6 +181,11 @@ class SkontoViewModel {
}
}

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

private func setPrice(_ price: String,
maxValue: Decimal,
errorMessage: String,
Expand Down

0 comments on commit bb6fe4c

Please sign in to comment.