Answer:
Day 1, merchandise purchased on account, credit terms 3/15, n/45
Dr Merchandise inventory 500,000
Cr Accounts payable 500,000
Day 4, defective merchandise is returned
Dr Accounts payable 50,000
Cr Merchandise inventory 50,000
Day 29, invoice is paid
Dr Accounts payable 450,000
Cr Cash 450,000
Since the invoice was paid after the discount period was over, the payment must be for the total amount owed.