add route to payment's details
This commit is contained in:
@@ -11,6 +11,9 @@ class ConflictError(ServiceError):
|
|||||||
super().__init__(HTTPStatus.CONFLICT, msg)
|
super().__init__(HTTPStatus.CONFLICT, msg)
|
||||||
|
|
||||||
|
|
||||||
|
class OrderNotFoundError(NotFoundError): ...
|
||||||
|
|
||||||
|
|
||||||
class UserNotFoundError(NotFoundError): ...
|
class UserNotFoundError(NotFoundError): ...
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||||
from layercake.dynamodb import (
|
from layercake.dynamodb import (
|
||||||
DynamoDBPersistenceLayer,
|
DynamoDBPersistenceLayer,
|
||||||
|
KeyPair,
|
||||||
SortKey,
|
SortKey,
|
||||||
TransactKey,
|
TransactKey,
|
||||||
)
|
)
|
||||||
|
|
||||||
from boto3clients import dynamodb_client
|
from boto3clients import dynamodb_client
|
||||||
from config import ORDER_TABLE
|
from config import ORDER_TABLE
|
||||||
|
from exceptions import OrderNotFoundError
|
||||||
|
|
||||||
from .checkout import router as checkout
|
from .checkout import router as checkout
|
||||||
|
|
||||||
@@ -18,12 +20,25 @@ dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
|||||||
|
|
||||||
@router.get('/<order_id>')
|
@router.get('/<order_id>')
|
||||||
def get_order(order_id: str):
|
def get_order(order_id: str):
|
||||||
return dyn.collection.get_items(
|
order = dyn.collection.get_items(
|
||||||
TransactKey(order_id)
|
TransactKey(order_id)
|
||||||
+ SortKey('0')
|
+ SortKey('0')
|
||||||
+ SortKey('ITEMS')
|
+ SortKey('ITEMS', rename_key='items')
|
||||||
+ SortKey('ADDRESS')
|
+ SortKey('ADDRESS', rename_key='address')
|
||||||
+ SortKey('PIX')
|
+ SortKey('CREDIT_CARD', rename_key='credit_card')
|
||||||
+ SortKey('NFSE')
|
+ SortKey('INVOICE', rename_key='invoice')
|
||||||
+ SortKey('FEE'),
|
+ SortKey('NFSE', rename_key='nfse')
|
||||||
|
+ SortKey('FEE', rename_key='fee')
|
||||||
|
+ SortKey('TRANSACTION#STATS', rename_key='stats'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not order:
|
||||||
|
raise OrderNotFoundError('Order not found')
|
||||||
|
|
||||||
|
attempts = dyn.collection.query(KeyPair(order_id, 'TRANSACTION#ATTEMPT#'))
|
||||||
|
enrollments = dyn.collection.query(KeyPair(order_id, 'ENROLLMENT#'))
|
||||||
|
|
||||||
|
return order | {
|
||||||
|
'attempts': attempts['items'],
|
||||||
|
'enrollments': enrollments['items'],
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import type { Route } from './+types/route'
|
||||||
|
|
||||||
|
import { Link } from 'react-router'
|
||||||
|
|
||||||
|
import { request as req } from '@repo/util/request'
|
||||||
|
import {
|
||||||
|
Breadcrumb,
|
||||||
|
BreadcrumbItem,
|
||||||
|
BreadcrumbLink,
|
||||||
|
BreadcrumbList,
|
||||||
|
BreadcrumbPage,
|
||||||
|
BreadcrumbSeparator
|
||||||
|
} from '@repo/ui/components/ui/breadcrumb'
|
||||||
|
|
||||||
|
export function meta() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
title: 'Pagamento'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loader({ params, request, context }: Route.LoaderArgs) {
|
||||||
|
const r = await req({
|
||||||
|
url: `/orders/${params.id}`,
|
||||||
|
request,
|
||||||
|
context
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!r.ok) {
|
||||||
|
throw new Response(null, { status: r.status })
|
||||||
|
}
|
||||||
|
|
||||||
|
return { order: await r.json() }
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Route({ loaderData: { order } }: Route.ComponentProps) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-2.5">
|
||||||
|
<Breadcrumb>
|
||||||
|
<BreadcrumbList>
|
||||||
|
<BreadcrumbItem>
|
||||||
|
<BreadcrumbLink asChild>
|
||||||
|
<Link to="../payments">Histórico de pagamentos</Link>
|
||||||
|
</BreadcrumbLink>
|
||||||
|
</BreadcrumbItem>
|
||||||
|
<BreadcrumbSeparator />
|
||||||
|
<BreadcrumbItem>
|
||||||
|
<BreadcrumbPage>Pagamento</BreadcrumbPage>
|
||||||
|
</BreadcrumbItem>
|
||||||
|
</BreadcrumbList>
|
||||||
|
</Breadcrumb>
|
||||||
|
<pre>{JSON.stringify(order, null, 2)}</pre>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -44,8 +44,7 @@ export async function loader({ params, request, context }: Route.LoaderArgs) {
|
|||||||
throw new Response(null, { status: r.status })
|
throw new Response(null, { status: r.status })
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await r.json()
|
return { user: await r.json() } as { user: any }
|
||||||
return { data } as { data: any }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldRevalidate({
|
export function shouldRevalidate({
|
||||||
@@ -55,9 +54,7 @@ export function shouldRevalidate({
|
|||||||
return currentParams.id !== nextParams.id
|
return currentParams.id !== nextParams.id
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Route({
|
export default function Route({ loaderData: { user } }: Route.ComponentProps) {
|
||||||
loaderData: { data: user }
|
|
||||||
}: Route.ComponentProps) {
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2.5">
|
<div className="space-y-2.5">
|
||||||
<Breadcrumb>
|
<Breadcrumb>
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
|||||||
transact.put(
|
transact.put(
|
||||||
item={
|
item={
|
||||||
'id': order_id,
|
'id': order_id,
|
||||||
'sk': f'TRANSACTION#ATTEMPTS#{now_.isoformat()}',
|
'sk': f'TRANSACTION#ATTEMPT#{now_.isoformat()}',
|
||||||
'brand': credit_card.brand,
|
'brand': credit_card.brand,
|
||||||
'last4': credit_card.last4,
|
'last4': credit_card.last4,
|
||||||
'status': 'SUCCEEDED',
|
'status': 'SUCCEEDED',
|
||||||
@@ -88,7 +88,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
|||||||
transact.put(
|
transact.put(
|
||||||
item={
|
item={
|
||||||
'id': order_id,
|
'id': order_id,
|
||||||
'sk': f'TRANSACTION#ATTEMPTS#{now_.isoformat()}',
|
'sk': f'TRANSACTION#ATTEMPT#{now_.isoformat()}',
|
||||||
'brand': credit_card.brand,
|
'brand': credit_card.brand,
|
||||||
'last4': credit_card.last4,
|
'last4': credit_card.last4,
|
||||||
'status': 'FAILED',
|
'status': 'FAILED',
|
||||||
|
|||||||
Reference in New Issue
Block a user