runtime
196 / 500
question 196 CSV JSON & JSONL · medium

Fix the captured-payments export

export_captured should write the captured payments to a CSV for finance, but it crashes with ValueError: dict contains fields not in fieldnames. Fix it so it meets the contract. Look at the whole file it writes, not only the crash.

Functionexport_captured(payments, path)
paymentsa list of dictionaries with payment_id, order_id, method, status and amount
Writesa header payment_id,order_id,amount once, then one line per payment whose status is captured
Returnsthe number of payments written
Examples
callexport_captured([{'payment_id': 'PAY0008990', 'order_id': 'O108024', 'method': 'card', 'status': 'failed', 'amount': 57.34}, {'payment_id': 'PAY0008991', 'order_id': 'O108024', 'method': 'card', 'status': 'captured', 'amount': 57.34}], '_x1.csv')returns1

Loading your progress…

Fix the captured-payments export — Python practice · Runtime