feat: the cart offers Correios PAC and SEDEX next to Jadlog
All checks were successful
Build and deploy / Validate source (push) Successful in 1m48s
Build and deploy / Integration suite on a real stack (push) Successful in 4m25s
Build and deploy / Secret scan and release gate (push) Successful in 15s
Build and deploy / Publish images (push) Successful in 1m54s
All checks were successful
Build and deploy / Validate source (push) Successful in 1m48s
Build and deploy / Integration suite on a real stack (push) Successful in 4m25s
Build and deploy / Secret scan and release gate (push) Successful in 15s
Build and deploy / Publish images (push) Successful in 1m54s
Dropstar sent its Correios contract. The cart now asks every carrier at once for the CEP and lists each option with its delivery time, cheapest first and chosen by default: Jadlog .PACKAGE, Correios PAC and Correios SEDEX, plus pickup. A carrier that does not answer is left out instead of blocking the others, and the server quotes the customer's choice again at approval. The order summary, the Kanban and Minha conta name the carrier chosen. app/correios.py follows the CWS manuals: a token from the posting card (kept until shortly before it expires, renewed once if refused), the contract's own prices by its DR, and the delivery time. Each box is one object priced by its sides; Correios work out the cubic weight. All carriers price the same package, now in app/package.py. Only CORREIOS_CODIGO_ACESSO goes in the stack; the user, card and contract are its defaults. python -m app.correios_probe checks the contract and its service codes on the account. Tested: tests/test_correios (token, contract parameters, prices in Brazilian format, boxes, a code override, a failing carrier), the full suite in a CI-style stack, and the cart in Brave on desktop and phone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ from fastapi import HTTPException
|
||||
from psycopg.types.json import Jsonb
|
||||
|
||||
from .adapters import FakeFreight, FakePayment, LocalS3Storage, require_runtime
|
||||
from .freight import FreightOptions
|
||||
from .core.secrets import load as load_secret_files
|
||||
|
||||
# Secret files must resolve before any configuration below is read.
|
||||
@@ -25,11 +26,15 @@ if os.environ.get('PAYMENT_ADAPTER') == 'mercadopago':
|
||||
payment = MercadoPagoPayment()
|
||||
else:
|
||||
payment = FakePayment()
|
||||
# Every carrier configured; the simulated one only where there is none.
|
||||
_carriers = []
|
||||
if os.environ.get('FREIGHT_ADAPTER') == 'jadlog':
|
||||
from .jadlog import JadlogFreight
|
||||
freight = JadlogFreight()
|
||||
else:
|
||||
freight = FakeFreight()
|
||||
_carriers.append(JadlogFreight())
|
||||
from . import correios as _correios
|
||||
if _correios.configured():
|
||||
_carriers.append(_correios.CorreiosFreight())
|
||||
freight = FreightOptions(_carriers or [FakeFreight()])
|
||||
ENVIRONMENT = os.environ.get('APP_ENV', 'local')
|
||||
PUBLIC_ORIGIN = os.environ.get('PUBLIC_ORIGIN', 'http://localhost')
|
||||
ALLOWED_HOSTS = [host for host in os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',') if host]
|
||||
@@ -55,10 +60,23 @@ TRANSITIONS = {'rec': ['tra','cor'], 'tra': ['fil','cor'], 'fil': ['imp','cor'],
|
||||
BACK = {'tra': 'rec', 'fil': 'tra', 'imp': 'fil', 'fin': 'imp'}
|
||||
|
||||
|
||||
def real_delivery():
|
||||
"""Whether a real carrier is configured; a simulated price is local only."""
|
||||
return any(carrier.name != 'fake' for carrier in freight.carriers)
|
||||
|
||||
|
||||
def delivery_services():
|
||||
"""The delivery options the cart may offer: none outside the local stack
|
||||
without a real carrier, so a customer sees only pickup."""
|
||||
if ENVIRONMENT != 'local' and not real_delivery():
|
||||
return []
|
||||
return [{'service': service, 'description': label} for service, label in freight.services.items()]
|
||||
|
||||
|
||||
def require_delivery_available(service):
|
||||
"""Outside the local stack, a simulated freight price must never reach a
|
||||
customer: until a real freight provider exists, only pickup is offered."""
|
||||
if service != 'pickup' and ENVIRONMENT != 'local' and getattr(freight, 'name', '') == 'fake':
|
||||
if service != 'pickup' and ENVIRONMENT != 'local' and not real_delivery():
|
||||
raise HTTPException(503, 'A entrega ainda não está disponível. Escolha a retirada em Franca.')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user