add payment section

This commit is contained in:
2026-01-19 20:16:57 -03:00
parent ed58e26e7e
commit 6732e07dfa
13 changed files with 222 additions and 58 deletions

View File

@@ -1,4 +1,3 @@
from enum import Enum
from http import HTTPStatus
from typing import Annotated
@@ -20,17 +19,11 @@ router = Router()
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
class PaymentMethod(str, Enum):
BANK_SLIP = 'BANK_SLIP'
MANUAL = 'MANUAL'
@router.post('/<org_id>/subscription')
def add(
org_id: str,
name: Annotated[str, Body(embed=True)],
billing_day: Annotated[int, Body(embed=True, ge=1, le=31)],
payment_method: Annotated[PaymentMethod, Body(embed=True)],
subscription_frozen: Annotated[bool, Body(embed=True)] = False,
):
now_ = now()
@@ -55,7 +48,6 @@ def add(
'id': org_id,
'sk': 'METADATA#SUBSCRIPTION',
'billing_day': billing_day,
'payment_method': payment_method.value,
'created_at': now_,
},
cond_expr='attribute_not_exists(sk)',
@@ -88,7 +80,6 @@ def add(
def edit(
org_id: str,
billing_day: Annotated[int, Body(embed=True, ge=1, le=31)],
payment_method: Annotated[PaymentMethod, Body(embed=True)],
subscription_frozen: Annotated[bool, Body(embed=True)] = False,
):
now_ = now()
@@ -102,11 +93,9 @@ def edit(
transact.update(
key=KeyPair(org_id, 'METADATA#SUBSCRIPTION'),
update_expr='SET billing_day = :billing_day, \
payment_method = :payment_method, \
updated_at = :now',
expr_attr_values={
':billing_day': billing_day,
':payment_method': payment_method.value,
':now': now_,
},
cond_expr='attribute_exists(sk)',