Visa Acceptance Platform authorization events arrive as nested JSON objects. Write a function that extracts selected fields and returns one flattened record per event, preserving None for optional fields that are absent.
Implement extract_authorization_fields(events), where events is a list of Python dictionaries produced by parsing JSON. Return a list of dictionaries with these keys:
transaction_id from data.authorizationIdstatus from data.statusamount from data.amount.valuecurrency from data.amount.currencymerchant_category from data.merchant.categoryCodecard_last4 from data.paymentMethod.card.last4created_at from data.createdAtEvery event contains data.authorizationId. All other fields are optional. Do not modify the input or include keys outside the specified output schema.
Example 1
Input: [{"data": {"authorizationId": "A100", "status": "APPROVED", "amount": {"value": 2599, "currency": "USD"}, "merchant": {"categoryCode": "5411"}, "paymentMethod": {"card": {"last4": "4242"}}, "createdAt": "2026-04-01T10:00:00Z"}}]
Output: [{"transaction_id": "A100", "status": "APPROVED", "amount": 2599, "currency": "USD", "merchant_category": "5411", "card_last4": "4242", "created_at": "2026-04-01T10:00:00Z"}]
The nested values are copied into a stable flat schema.
Example 2
Input: [{"data": {"authorizationId": "A101", "status": "DECLINED", "amount": {"value": 0, "currency": "EUR"}}}]
Output: [{"transaction_id": "A101", "status": "DECLINED", "amount": 0, "currency": "EUR", "merchant_category": null, "card_last4": null, "created_at": null}]
Missing optional paths become None, while valid zero values are retained.
def extract_authorization_fields(events):