fix: a payment started in time is the order when approved late, a second payment is listed for a refund, a coupon's limit is checked at payment
All checks were successful
Build and deploy / Validate source (push) Successful in 13s
Build and deploy / Integration suite on a real stack (push) Successful in 8m10s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m17s
All checks were successful
Build and deploy / Validate source (push) Successful in 13s
Build and deploy / Integration suite on a real stack (push) Successful in 8m10s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m17s
- A PIX paid in its last minutes after the quote's 24 h, or a card approved
after Mercado Pago's review, was refused ("quote expired before payment"):
money in, no order. A payment whose attempt began while the quote was
valid is now honoured; a card in review keeps its quote, files and the
reconciliation for 72 h.
- A second approved payment of the same cart (a PIX and a card) was taken
for a re-sent approval and logged only. It is now listed on the Kanban as
attention, with the order, for a refund.
- A coupon's uses were counted only when the cart was made, so carts made
before it ran out, or before it was paused or ended, still paid with the
discount. The intent checks it again and asks for a new cart without it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,7 @@ def run():
|
||||
quote, payment_id = uuid4(), str(900_000_000 + uuid4().int % 99_999_999)
|
||||
approved = {'customer': {'mail': 'reconcile@example.test'}, 'items': [], 'total_cents': 1490}
|
||||
order_id = None
|
||||
extra = []
|
||||
try:
|
||||
with db.connect() as c:
|
||||
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
|
||||
@@ -55,7 +56,36 @@ def run():
|
||||
asked = paid.asked
|
||||
assert payments.reconcile(db.connect, paid, quote_id=quote) == [] and paid.asked == asked
|
||||
print('PASS: an approved payment is found by asking the provider; a short one is refused; each applies once')
|
||||
|
||||
# Approved after the quote's 24 h: a payment started in time (a PIX paid
|
||||
# in its last minutes, a card approved after review) is the order; one
|
||||
# started after the deadline is refused.
|
||||
for started, expected in (("now()-interval '3 hours'", 'order '), ("now()-interval '1 hour'", 'refused: quote expired')):
|
||||
late, late_payment = uuid4(), str(800_000_000 + uuid4().int % 99_999_999)
|
||||
extra.append((late, late_payment))
|
||||
with db.connect() as c:
|
||||
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
|
||||
VALUES(%s,%s,%s,'reconcile-fixture',%s,%s,now()-interval '26 hours')''',
|
||||
(late, uuid4(), uuid4(), Jsonb({'customer': approved['customer'], 'items': []}), Jsonb(approved)))
|
||||
c.execute(f'''INSERT INTO dtf_local.payment_intents(id,quote_id,provider,provider_payment_id,method,status,
|
||||
amount_cents,response,created_at) VALUES(%s,%s,'mercadopago',%s,'card','pending',1490,'{{}}',{started})''',
|
||||
(uuid4(), late, late_payment))
|
||||
provider = Provider({'id': late_payment, 'status': 'approved', 'currency_id': 'BRL',
|
||||
'transaction_amount': 14.9, 'external_reference': str(late)})
|
||||
outcomes = payments.reconcile(db.connect, provider, quote_id=late)
|
||||
assert len(outcomes) == 1 and outcomes[0].startswith(expected), (started, outcomes)
|
||||
print('PASS: a payment started within the 24 h is the order whenever approved; one started later is refused')
|
||||
finally:
|
||||
for late, late_payment in extra:
|
||||
with db.connect() as c:
|
||||
for row in c.execute('SELECT id FROM dtf_local.orders WHERE quote_id=%s', (late,)).fetchall():
|
||||
c.execute("DELETE FROM dtf_local.outbox WHERE event_key LIKE %s", (f"{row['id']}:%",))
|
||||
c.execute('DELETE FROM dtf_local.print_files WHERE order_id=%s', (row['id'],))
|
||||
c.execute('DELETE FROM dtf_local.orders WHERE id=%s', (row['id'],))
|
||||
c.execute("DELETE FROM dtf_local.payment_events WHERE provider='mercadopago' AND event_id LIKE %s",
|
||||
(f'{late_payment}:%',))
|
||||
c.execute('DELETE FROM dtf_local.payment_intents WHERE quote_id=%s', (late,))
|
||||
c.execute('DELETE FROM dtf_local.quotes WHERE id=%s', (late,))
|
||||
with db.connect() as c:
|
||||
if order_id:
|
||||
c.execute("DELETE FROM dtf_local.outbox WHERE event_key LIKE %s", (f'{order_id}:%',))
|
||||
|
||||
Reference in New Issue
Block a user