feat: an order paid on the Site says how: "pago com Pix" or "pago com cartão" on its paid line
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 8m35s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m16s

The board carries paid_with, the method of the quote's approved payment
attempt (the one Tiny is told about). Until now a paid Site order only said
"pago em", so a Tiny refusal (DTF-API-C, #196) could not be traced to Pix
or card from the Kanban.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-12-01 10:58:31 -03:00
parent b18f6e1312
commit fc9e6d2681
4 changed files with 25 additions and 1 deletions

View File

@@ -235,6 +235,11 @@ def with_print_files(c, orders):
WHERE parent_id=ANY(%s) AND cancelled_at IS NULL ORDER BY parent_id, created_at DESC''', (ids,)).fetchall()}
parents = {r['id']: r for r in c.execute('SELECT id,number,state FROM dtf_local.orders WHERE id=ANY(%s)',
([o['parent_id'] for o in orders if o.get('parent_id')],)).fetchall()}
# How each Site order was paid, Pix or card: its quote's approved attempt,
# the one Tiny is told about too (app/payments.py).
paid_with = {r['quote_id']: r['method'] for r in c.execute('''SELECT DISTINCT ON (quote_id) quote_id,method
FROM dtf_local.payment_intents WHERE quote_id=ANY(%s) AND status='approved' ORDER BY quote_id,created_at DESC''',
([o['quote_id'] for o in orders if o.get('quote_id')],)).fetchall()}
# Every order's review photos and videos, in one query like the print files.
review_rows = reviews.by_order(c, ids)
# The proof card's go on its order too: an answered card leaves the board,
@@ -244,6 +249,7 @@ def with_print_files(c, orders):
for order in orders:
order['hot'] = hot.get(order['id'])
order['hot_parts'] = hot_parts.get(order['id'], [])
order['paid_with'] = paid_with.get(order.get('quote_id'))
order['reviews'] = review_rows.get(str(order['id']), [])
child = children.get(order['id'])
# Its machine: an order prints where its approved proof did (Dropstar, 2026-11-05).

View File

@@ -142,6 +142,21 @@ def run():
assert [e['provider'] for e in paid] == ['tiny'], paid
print('PASS: exactly one Tiny notification for the order')
# The order's paid line says how it was paid: nothing while no attempt is
# approved, then the approved one (the card attempt above).
def paid_with():
orders = board.call('/operator/board', operator=True)['orders']
return next(o for o in orders if o['id'] == order['id'])['paid_with']
assert paid_with() is None
with db.connect() as c:
c.execute("UPDATE dtf_local.payment_intents SET status='approved' WHERE quote_id=%s AND method='card'", (quote_id,))
try:
assert paid_with() == 'card'
finally:
with db.connect() as c:
c.execute("UPDATE dtf_local.payment_intents SET status='pending' WHERE quote_id=%s AND method='card'", (quote_id,))
print('PASS: the board says the order was paid with the approved attempt, card')
# A payment that was never reviewed, and one for something that is not a quote.
deliver({'event_id': 'nonsense-' + uuid4().hex, 'reference': 'not-a-uuid',
'status': 'approved', 'amount_cents': 100})

View File

@@ -53,7 +53,8 @@ function renderPanel(order){
// A proof card is no sale (app/proof.py): it says whose proof it is.
if(order.proof_parent)paid.append(node('b','Prova do pedido #'+order.proof_parent.number),', sem custo, criada em '+when(order.created_at));
else paid.append(node('b',money(s.total_cents)),isTest(order)?' sem pagamento, '+when(order.created_at):
paidOutside(order)?' pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado em '+when(order.created_at):' pago em '+when(order.created_at));
paidOutside(order)?' pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado em '+when(order.created_at):
' pago'+(PAID_WITH[order.paid_with]?' com '+PAID_WITH[order.paid_with]:'')+' em '+when(order.created_at));
const code=node('span',undefined,'chip');
code.append(node('span','DTF-'+order.number,'code'),copyButton(fileCode(order),'Copiar “'+fileCode(order)+'”, o começo do nome dos arquivos deste pedido'));
const theirs=node('span','Código do cliente ','tip-l');theirs.append(node('span',orderCode(order.id),'code strong'));theirs.dataset.tip='O código que aparece para o cliente';

View File

@@ -238,6 +238,8 @@ function callout(d,title,text,tone=''){
// Faturado is not one of them: an invoiced sale goes through the montador's
// Venda (front 7a.3), and the API refuses it here (Sentry DTF-WEB-E).
const PAID_OUTSIDE={pix:'Pix',card:'Cartão',cash:'Dinheiro',credit:'Crédito do cliente'};
// How a Site order was paid, on the order's paid line (the board's paid_with).
const PAID_WITH={pix:'Pix',card:'cartão'};
function registerDialog(quote){
const group=(name,label,options)=>{
const g=node('div',undefined,'fgroup2');g.setAttribute('role','radiogroup');g.setAttribute('aria-label',label);