in src/backend/payment/src/collect-payment/collect.py [0:0]
def lambda_handler(event, context):
"""AWS Lambda Function entrypoint to collect payment
Parameters
----------
event: dict, required
Step Functions State Machine event
chargeId: string
pre-authorization charge ID
context: object, required
Lambda Context runtime methods and attributes
Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
Returns
-------
dict
receiptUrl: string
receipt URL of charge collected
price: int
amount collected
Raises
------
BookingConfirmationException
Booking Confirmation Exception including error message upon failure
"""
pre_authorization_token = event.get("chargeId")
customer_id = event.get("customerId")
if not pre_authorization_token:
metrics.add_metric(name="InvalidPaymentRequest", unit=MetricUnit.Count, value=1)
logger.error({"operation": "input_validation", "details": event})
raise ValueError("Invalid Charge ID")
try:
logger.debug(
f"Collecting payment from customer {customer_id} using {pre_authorization_token} token"
)
ret = collect_payment(pre_authorization_token)
metrics.add_metric(name="SuccessfulPayment", unit=MetricUnit.Count, value=1)
tracer.put_annotation("PaymentStatus", "SUCCESS")
return ret # Step Functions can append multiple values if you return a single dict
except PaymentException as err:
metrics.add_metric(name="FailedPayment", unit=MetricUnit.Count, value=1)
tracer.put_annotation("PaymentStatus", "FAILED")
logger.exception({"operation": "payment_collection"})
raise