add iugu postback
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from http import HTTPStatus
|
||||
from typing import Any
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
from aws_lambda_powertools import Logger, Tracer
|
||||
from aws_lambda_powertools.event_handler.api_gateway import (
|
||||
@@ -8,7 +9,8 @@ from aws_lambda_powertools.event_handler.api_gateway import (
|
||||
)
|
||||
from aws_lambda_powertools.logging import correlation_paths
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ORDER_TABLE
|
||||
@@ -19,10 +21,35 @@ app = APIGatewayHttpResolver(enable_validation=True)
|
||||
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@app.post('/postback/<order_id>')
|
||||
@app.post('/<order_id>/postback')
|
||||
@tracer.capture_method
|
||||
def postback(order_id: str):
|
||||
return Response(status_code=HTTPStatus.NO_CONTENT)
|
||||
decoded_body = dict(parse_qsl(app.current_event.decoded_body))
|
||||
logger.info('IUGU Postback', decoded_body=decoded_body)
|
||||
event = decoded_body['event']
|
||||
status = decoded_body['data[status]'].upper()
|
||||
|
||||
if event != 'invoice.status_changed':
|
||||
return Response(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
try:
|
||||
dyn.update_item(
|
||||
key=KeyPair(order_id, '0'),
|
||||
update_expr='SET #status = :status, \
|
||||
updated_at = :now',
|
||||
cond_expr='attribute_exists(sk)',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
},
|
||||
expr_attr_values={
|
||||
':status': status,
|
||||
':now': now(),
|
||||
},
|
||||
)
|
||||
except Exception:
|
||||
return Response(status_code=HTTPStatus.NOT_FOUND)
|
||||
else:
|
||||
return Response(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP)
|
||||
|
||||
Reference in New Issue
Block a user