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:
@@ -33,6 +33,7 @@ def run():
|
||||
manager = manager.operator_client
|
||||
coupon_id = None
|
||||
quote_id = None
|
||||
early_id = None
|
||||
order_id = None
|
||||
upload_id = None
|
||||
try:
|
||||
@@ -61,6 +62,9 @@ def run():
|
||||
assert [line['total_cents'] for line in approved['items']] == [7990, 8990], approved
|
||||
assert approved['total_cents'] == 16081, approved
|
||||
|
||||
# A second cart with the coupon, made while it still had uses.
|
||||
early_id = quote(client, items, code, mail)['id']
|
||||
|
||||
# One paid order spends a use (a fake payment, no print job).
|
||||
order_id = uuid4()
|
||||
with db.connect() as c:
|
||||
@@ -110,6 +114,10 @@ def run():
|
||||
manager.call('/operator/site/coupons/' + coupon_id, {'max_uses': 1})
|
||||
refused = quote(client, items, code, mail, expected=422)
|
||||
assert refused['detail'] == 'Este cupom já foi usado o máximo de vezes.', refused
|
||||
# The limit is spent at payment: the cart made before it ran out no
|
||||
# longer pays with its discount.
|
||||
refused = client.call('/payments/intent', {'quote_id': early_id, 'method': {'type': 'pix'}}, expected=409)
|
||||
assert 'máximo de vezes' in refused['detail'] and 'sem o cupom' in refused['detail'], refused
|
||||
manager.call('/operator/site/coupons/' + coupon_id,
|
||||
{'max_uses': None, 'max_uses_per_customer': 1})
|
||||
refused = quote(client, items, code, mail, expected=422)
|
||||
@@ -135,13 +143,16 @@ def run():
|
||||
stats = manager.call('/operator/stats?days=30')
|
||||
assert any(entry['id'] == coupon_id for entry in stats['coupons']), stats['coupons']
|
||||
print('PASS: a coupon discounts one product, refuses paused/expired/not-started/'
|
||||
'minimum/product/use states, reaches Tiny data and Números, and soft delete keeps history')
|
||||
'minimum/product/use states, also at payment, reaches Tiny data and Números, and soft delete keeps history')
|
||||
finally:
|
||||
with db.connect() as c:
|
||||
if order_id:
|
||||
c.execute('DELETE FROM dtf_local.orders WHERE id=%s', (order_id,))
|
||||
if quote_id:
|
||||
c.execute('DELETE FROM dtf_local.quotes WHERE id=%s', (quote_id,))
|
||||
if early_id:
|
||||
c.execute('DELETE FROM dtf_local.payment_intents WHERE quote_id=%s', (early_id,))
|
||||
c.execute('DELETE FROM dtf_local.quotes WHERE id=%s', (early_id,))
|
||||
if coupon_id:
|
||||
c.execute('DELETE FROM dtf_local.coupons WHERE id=%s', (coupon_id,))
|
||||
if upload_id:
|
||||
|
||||
Reference in New Issue
Block a user