From f593b21a73fa318612bacb3487b06913f7b5c6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Rafael=20Siqueira?= Date: Fri, 16 Jan 2026 18:08:07 -0300 Subject: [PATCH] check status to payment retries --- .../app/routes/orders/payment_retries.py | 8 +- api.saladeaula.digital/tests/seeds.jsonl | 2 +- .../routes/_.$orgid.enrollments.add/route.tsx | 3 +- .../_.$orgid.payments.$id._index/route.tsx | 163 ++++++++++-------- 4 files changed, 98 insertions(+), 78 deletions(-) diff --git a/api.saladeaula.digital/app/routes/orders/payment_retries.py b/api.saladeaula.digital/app/routes/orders/payment_retries.py index c280b18..375b947 100644 --- a/api.saladeaula.digital/app/routes/orders/payment_retries.py +++ b/api.saladeaula.digital/app/routes/orders/payment_retries.py @@ -36,8 +36,14 @@ def payment_retries( with dyn.transact_writer() as transact: transact.condition( key=KeyPair(order_id, '0'), - cond_expr='attribute_exists(sk) AND installments = :installments', + cond_expr='attribute_exists(sk) \ + AND installments = :installments \ + AND #status = :pending', + expr_attr_names={ + '#status': 'status', + }, expr_attr_values={ + ':pending': 'PENDING', ':installments': installments, }, exc_cls=OrderConflictError, diff --git a/api.saladeaula.digital/tests/seeds.jsonl b/api.saladeaula.digital/tests/seeds.jsonl index 5f6e5de..de7745c 100644 --- a/api.saladeaula.digital/tests/seeds.jsonl +++ b/api.saladeaula.digital/tests/seeds.jsonl @@ -28,7 +28,7 @@ // Seeds for Order // file: tests/routes/orders/test_payment_retries.py -{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "0", "installments": 3} +{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "0", "installments": 3, "status": "PENDING"} {"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "INVOICE", "invoice_id": "123"} {"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "TRANSACTION#STATS", "last_attempt_succeeded": false} diff --git a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx index e2cfa76..dd12476 100644 --- a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx +++ b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx @@ -490,10 +490,11 @@ function ActionMenu() { }} > - +
Envios recentes diff --git a/apps/admin.saladeaula.digital/app/routes/_.$orgid.payments.$id._index/route.tsx b/apps/admin.saladeaula.digital/app/routes/_.$orgid.payments.$id._index/route.tsx index 6d410ca..7a119ce 100644 --- a/apps/admin.saladeaula.digital/app/routes/_.$orgid.payments.$id._index/route.tsx +++ b/apps/admin.saladeaula.digital/app/routes/_.$orgid.payments.$id._index/route.tsx @@ -2,7 +2,7 @@ import type { Route } from './+types/route' import { formatCEP } from '@brazilian-utils/brazilian-utils' import { zodResolver } from '@hookform/resolvers/zod' -import { useRequest } from 'ahooks' +import { useRequest, useToggle } from 'ahooks' import { AlertCircleIcon, ArrowLeftRightIcon, @@ -13,7 +13,7 @@ import { } from 'lucide-react' import { useEffect } from 'react' import { useForm } from 'react-hook-form' -import { Link } from 'react-router' +import { Link, useRevalidator } from 'react-router' import { z } from 'zod' import { Currency } from '@repo/ui/components/currency' @@ -31,13 +31,6 @@ import { CardHeader, CardTitle } from '@repo/ui/components/ui/card' -import { - Command, - CommandEmpty, - CommandGroup, - CommandItem, - CommandList -} from '@repo/ui/components/ui/command' import { Item, ItemActions, @@ -121,6 +114,13 @@ type User = { type Invoice = { invoice_id: string secure_url: string + bank_slip?: { + bank_slip_pdf_url: string + } + pix?: { + qrcode: string + qrcode_text: string + } } type Attempts = { @@ -180,6 +180,8 @@ export default function Route({ loaderData: { order } }: Route.ComponentProps) { reset() }, []) + console.log(order) + return (
@@ -203,7 +205,8 @@ export default function Route({ loaderData: { order } }: Route.ComponentProps) { - + + {/* Billing address */} Endereço de cobrança
    @@ -218,14 +221,12 @@ export default function Route({ loaderData: { order } }: Route.ComponentProps) {
- + {/* Payment method */} Forma de pagamento
- {Component && ( - - )} + {Component && }
@@ -315,8 +316,6 @@ export default function Route({ loaderData: { order } }: Route.ComponentProps) {
- - {/*
{JSON.stringify(order, null, 2)}
*/}
) } @@ -326,7 +325,7 @@ function Status({ status: s }: { status: string }) { const { icon: Icon, color } = statuses?.[s] ?? { icon: HelpCircleIcon } return ( - + {status} @@ -337,7 +336,7 @@ type PaymentMethodProps = { id: string status: string total: number - invoice_id: string + invoice: Invoice installments: number } @@ -345,7 +344,7 @@ type BankSlipPaymentMethodProps = PaymentMethodProps & {} function BankSlipPaymentMethod({ status }: BankSlipPaymentMethodProps) { return ( -
    +
    • Boleto bancário
    • @@ -356,8 +355,27 @@ function BankSlipPaymentMethod({ status }: BankSlipPaymentMethodProps) { type PixPaymentMethodrops = PaymentMethodProps & {} -function PixPaymentMethod({}: PixPaymentMethodrops) { - return <>Pix +function PixPaymentMethod({ invoice, status }: PixPaymentMethodrops) { + return ( +
      +
        +
      • Pix
      • +
      • + +
      • +
      + + {invoice?.pix ? ( +
      + {invoice.pix.qrcode_text} +
      + ) : null} +
      + ) } function UnknownPaymentMethod() { @@ -365,7 +383,7 @@ function UnknownPaymentMethod() { } type CreditCardPaymentMethodProps = PaymentMethodProps & { - stats: { last_attempt_succeeded: boolean } + stats?: { last_attempt_succeeded: boolean } credit_card: { last4: string; brand: string } } @@ -375,22 +393,20 @@ function CreditCardPaymentMethod({ total, credit_card, installments, - invoice_id, + invoice, stats }: CreditCardPaymentMethodProps) { return ( <> -
        +
        • - {credit_card.brand} (Crédito) **** {credit_card.last4} + {credit_card.brand}
        • +
        • (Crédito) **** {credit_card.last4}
        • - {stats.last_attempt_succeeded === false ? ( - - Pagamento não aprovado + {stats?.last_attempt_succeeded === false ? ( + + Negado ) : ( @@ -402,13 +418,13 @@ function CreditCardPaymentMethod({ {installments}x {total / Number(installments)}

          - {stats.last_attempt_succeeded === false ? ( -
          + {stats?.last_attempt_succeeded === false && invoice?.invoice_id ? ( +
          - {/*
          - Transações -
          */}
          - {payment_attempts.map( - ({ sk, brand, last4, status, ...props }, index) => { - const [, , created_at] = sk.split('#') + {payment_attempts.map(({ sk, brand, last4, status }, index) => { + const [, , created_at] = sk.split('#') - return ( -
            -
          • - - - {created_at} - - -
          • -
          • - {brand} -
          • -
          • **** {last4}
          • -
          • - {status === 'FAILED' ? ( - - ) : ( - - )} -
          • -
          - ) - } - )} + return ( +
            +
          • + + + {created_at} + + +
          • +
          • + {brand} +
          • +
          • **** {last4}
          • +
          • + {status === 'FAILED' ? ( + + ) : ( + + )} +
          • +
          + ) + })}