Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
known_third_party = aws,boto3,botocore,constants,controller,external_gateway,fastapi,fastapi_cloudauth,lambda_decorators,lambdawarmer,mangum,model,pydantic,pynamodb,pytz,repository,requests,starlette,ulid,usecase,utils
known_third_party = aws,boto3,botocore,constants,controller,dotenv,external_gateway,fastapi,fastapi_cloudauth,lambda_decorators,lambdawarmer,mangum,model,pydantic,pynamodb,pytz,repository,requests,starlette,typing_extensions,ulid,usecase,utils
1 change: 1 addition & 0 deletions backend/resources/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ paymentHandler:
- "dynamodb:UpdateItem"
Resource:
- "arn:aws:dynamodb:${self:provider.region}:${aws:accountId}:table/${self:custom.registrations}"
- "arn:aws:dynamodb:${self:provider.region}:${aws:accountId}:table/${self:custom.registrations}/index/*"
- "arn:aws:dynamodb:${self:provider.region}:${aws:accountId}:table/${self:custom.entities}"
- "arn:aws:dynamodb:${self:provider.region}:${aws:accountId}:table/${self:custom.events}"
- "arn:aws:dynamodb:${self:provider.region}:${aws:accountId}:table/${self:custom.events}/index/*"
Expand Down
81 changes: 81 additions & 0 deletions backend/scripts/change_discount_code_uses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import argparse
import os
from copy import deepcopy

from dotenv import load_dotenv
from typing_extensions import Literal

script_dir = os.path.dirname(os.path.abspath(__file__))
args = argparse.ArgumentParser()
args.add_argument('--env-file', type=str, default=os.path.join(script_dir, '..', '.env'), help='Path to the .env file')
load_dotenv(dotenv_path=args.parse_args().env_file)

from model.discount.discount import DiscountDBIn
from repository.discount_repository import DiscountsRepository
from utils.logger import logger


def change_discount_code_uses(
event_id: str, discount_id: str, uses_change: int, operation: Literal['add', 'deduct']
) -> None:
"""
Adjusts the max usage of a reusable discount code.

Args:
event_id (str): The ID of the event.
discount_id (str): The ID of the discount code.
uses_change (int): The number of uses to add or deduct. Must be a positive integer.
operation (Literal['add', 'deduct']): The type of operation to perform.
"""
discount_repository = DiscountsRepository()
status, discount_entry, message = discount_repository.query_discount_with_discount_id(
event_id=event_id, discount_id=discount_id
)

if not status:
logger.error(f"Error changing uses of discount code '{discount_id}' for event '{event_id}'. {message}")
return

original_discount_entry = deepcopy(discount_entry)

if not discount_entry.isReusable:
logger.warning(f"Discount code '{discount_id}' is not reusable. Cannot change max uses.")
return

if uses_change < 0:
logger.error('`uses_change` must be a non-negative integer.')
return

new_max_uses = 0
if operation == 'add':
new_max_uses = discount_entry.maxDiscountUses + uses_change
elif operation == 'deduct':
new_max_uses = discount_entry.maxDiscountUses - uses_change

if new_max_uses < discount_entry.currentDiscountUses:
logger.error(
f'Cannot deduct {uses_change} uses. The new max uses ({new_max_uses}) would be less than the current uses ({discount_entry.currentDiscountUses}).'
)
return
else:
logger.error(f"Invalid operation '{operation}'. Must be 'add' or 'deduct'.")
return

discount_entry.maxDiscountUses = new_max_uses
discount_entry.remainingUses = new_max_uses - discount_entry.currentDiscountUses

logger.info(
f"Changed max uses for discount code '{discount_id}' for event '{event_id}' from {original_discount_entry.maxDiscountUses} to {discount_entry.maxDiscountUses}."
)

if discount_entry:
discount_repository.update_discount(
discount_entry=original_discount_entry, discount_in=DiscountDBIn(**discount_entry.attribute_values)
)


if __name__ == '__main__':
event_id = 'test-event-id'
entry_id = 'test-entry-id'
uses = 50
change_discount_code_uses(event_id=event_id, discount_id=entry_id, uses_change=uses, operation='deduct')
29 changes: 29 additions & 0 deletions backend/scripts/resend_confirmation_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import argparse
import os
from http import HTTPStatus

from dotenv import load_dotenv

script_dir = os.path.dirname(os.path.abspath(__file__))
parser = argparse.ArgumentParser()
parser.add_argument(
'--env-file', type=str, default=os.path.join(script_dir, '..', '.env'), help='Path to the .env file'
)
parser.add_argument('--email', type=str, required=True, help='Registrant email address')
parser.add_argument('--event-id', type=str, required=True, help='Event ID')
args = parser.parse_args()
load_dotenv(dotenv_path=args.env_file)


from usecase.pycon_registration_email_notification import (
PyConRegistrationEmailNotification,
)
from utils.logger import logger

if __name__ == '__main__':
usecase = PyConRegistrationEmailNotification()
response = usecase.resend_confirmation_email(event_id=args.event_id, email=args.email)
if response.status_code == HTTPStatus.OK:
logger.info(f'Successfully resent confirmation email to {args.email} for event {args.event_id}')
else:
logger.error(f'Failed to resend confirmation email: {response.content}')
21 changes: 21 additions & 0 deletions backend/usecase/payment_tracking_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self):
self.email_usecase = EmailUsecase()
self.event_repository = EventsRepository()
self.payment_transaction_repository = PaymentTransactionRepository()
self.registration_repository = RegistrationsRepository()

def process_payment_event(self, message_body: dict) -> None:
"""
Expand Down Expand Up @@ -59,13 +60,33 @@ def process_payment_event(self, message_body: dict) -> None:

logger.info(f'Payment transaction status updated to {transaction_status} for entryId {entry_id}')

status, registration_details, _ = self.registration_repository.query_registrations_with_email(
event_id=event_id, email=registration_data.email
)

if status == HTTPStatus.OK and registration_details:
logger.info(
f'Skipping duplicate email for {registration_data.email} - user already has existing registration'
)
return

if transaction_status == TransactionStatus.SUCCESS:
recorded_registration_data = self._create_and_save_registration(
payment_tracking_body=payment_tracking_body
)
if not recorded_registration_data:
logger.error(f'Failed to save registration for entryId {entry_id}')

elif transaction_status == TransactionStatus.FAILED:
status, registrations, msg = self.registration_repository.query_registrations_with_email(
event_id=event_id, email=registration_data.email
)
if status == HTTPStatus.OK and registrations:
logger.info(
f'Skipping failed payment email for {registration_data.email} - user already has existing registration'
)
return

self._send_email_notification(
first_name=registration_data.firstName,
email=registration_data.email,
Expand Down
Loading