// Calculate a minor-unit discount capped by both an offer maximum and the subtotal. Rates are whole basis points rounded down. pub fn cart_discount(subtotal: i64, rate: i64, cap: i64) -> i64 { if subtotal<0 || rate<0 || rate>10000 || cap<0 { return -1; } let discount = subtotal*rate/10000; if discount>cap { return cap; } discount }