question 173 Exceptions & Validation · easy
Payments that can't be booked
Runtime Market's payment export has an amount column typed as text. Before booking, finance wants every payment that can't be booked, with the reason.
Function
invalid_amounts(payments)paymentsdictionaries with
payment_id and a text amountReturns
{payment_id: reason} for each bad payment, in order: "not a number" when float can't read the amount, "not positive" when it is 0 or lessRulesgood payments don't appear; refunds are a separate export, so a negative amount here is a mistake
Examples
callinvalid_amounts([{'payment_id': 'PAY0000045', 'amount': '12.93'}, {'payment_id': 'PAY0000416', 'amount': 'ninety'}, {'payment_id': 'PAY0001357', 'amount': '-71.14'}, {'payment_id': 'PAY0001503', 'amount': '1,234.00'}])returns{'PAY0000416': 'not a number', 'PAY0001357': 'not positive', 'PAY0001503': 'not a number'}
callinvalid_amounts([{'payment_id': 'P1', 'amount': '5'}])returns{}
callinvalid_amounts([{'payment_id': 'P2', 'amount': ''}])returns{'P2': 'not a number'}