add test mode to checkout

This commit is contained in:
2026-01-20 10:41:32 -03:00
parent fde5c31ffc
commit 49e0c3333b
13 changed files with 847 additions and 493 deletions

View File

@@ -8,6 +8,7 @@ from layercake.dateutils import now
from layercake.dynamodb import (
DynamoDBPersistenceLayer,
KeyPair,
SortKey,
)
from layercake.extra_types import CreditCard
@@ -17,13 +18,6 @@ from iugu import Credentials, Iugu
logger = Logger(__name__)
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
iugu = Iugu(
Credentials(
IUGU_ACCOUNT_ID,
IUGU_API_TOKEN,
test_mode=IUGU_TEST_MODE,
)
)
@event_source(data_class=EventBridgeEvent)
@@ -36,6 +30,26 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
credit_card = CreditCard(**new_image['credit_card'])
now_ = now()
api_token = dyn.collection.get_item(
KeyPair(
pk=order_id,
sk=SortKey(
'METADATA#TEST_MODE',
path_spec='iugu_api_token',
),
),
default=None,
raise_on_error=False,
)
test_mode = (api_token is not None) or IUGU_TEST_MODE
credentials = Credentials(
IUGU_ACCOUNT_ID,
# Note: `api_token` can be set from the database
api_token or IUGU_API_TOKEN,
test_mode=test_mode,
)
iugu = Iugu(credentials)
token = iugu.payment_token(credit_card)
charge = iugu.charge(
invoice_id=invoice_id,