feat: an unpaid cart's files are kept 2 days, a paid order's 30
Files are uploaded before payment so the price and the security check use the file itself, but an abandoned cart kept them for 30 days. Now a finished upload is held 2 days, a quote waiting for review 7, an approved quote 2 more to be paid, and the paid order keeps its originals for 30 days from upload. A payment never starts for files that are gone; one under way holds them a day. Files attached to an order take the order's window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -155,6 +155,30 @@ def run():
|
||||
assert queued == 0 and jobs == 1, (queued, jobs)
|
||||
print('PASS: an operator test order reaches the board and the print queue, never Tiny or WhatsApp')
|
||||
|
||||
# Files are uploaded before payment. An unpaid cart keeps them briefly; a
|
||||
# paid order keeps them for its 30 days; a payment never starts for files
|
||||
# that are gone.
|
||||
def files_of(qid):
|
||||
with db.connect() as c:
|
||||
q = c.execute('SELECT approved,draft FROM dtf_local.quotes WHERE id=%s', (qid,)).fetchone()
|
||||
return [u for item in (q['approved'] or q['draft'])['items'] for u in item['uploads']]
|
||||
|
||||
def days(ids, since='now()'):
|
||||
with db.connect() as c:
|
||||
return [float(r['d']) for r in c.execute(
|
||||
f'SELECT extract(epoch FROM expires_at-{since})/86400 AS d FROM dtf_local.uploads WHERE id=ANY(%s)',
|
||||
(ids,)).fetchall()]
|
||||
fresh = upload_bytes(customer, b'UNPAID HOLD TEST')
|
||||
assert all(1.99 < d <= 2.0 for d in days([fresh])), days([fresh])
|
||||
assert all(abs(d - 30) < 0.01 for d in days(files_of(quote_id), 'created_at')), days(files_of(quote_id), 'created_at')
|
||||
late, late_quote, _ = reviewed_quote()
|
||||
assert all(d > 1.99 for d in days(files_of(late_quote))), days(files_of(late_quote))
|
||||
with db.connect() as c:
|
||||
c.execute("UPDATE dtf_local.uploads SET expires_at=now()-interval '1 second' WHERE id=ANY(%s)",
|
||||
(files_of(late_quote),))
|
||||
late.call('/payments/intent', {'quote_id': late_quote, 'method': {'type': 'pix'}}, expected=410)
|
||||
print('PASS: unpaid files are held 2 days, paid ones 30 days, and expired files are never charged for')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
|
||||
Reference in New Issue
Block a user