fix billing

This commit is contained in:
2025-08-27 22:17:33 -03:00
parent b3a4b48fe5
commit 83c97f409b
12 changed files with 129 additions and 45 deletions

View File

@@ -31,6 +31,8 @@ def postback():
progress = round(Decimal(json_body['ANDAMENTO']), 2)
enrollment_id = dyn.collection.get_item(
KeyPair(
# Post-migration: uncomment the following line
# pk='KONVIVA',
pk='konviva',
sk=SortKey(json_body['ID_MATRICULA'], path_spec='enrollment_id'),
),
@@ -41,7 +43,7 @@ def postback():
update_progress(enrollment_id, progress, dynamodb_persistence_layer=dyn)
if status == 'COMPLETED':
set_score(enrollment_id, score, dynamodb_persistence_layer=dyn)
set_score(enrollment_id, score, progress, dynamodb_persistence_layer=dyn)
return Response(status_code=HTTPStatus.NO_CONTENT)

View File

@@ -86,21 +86,27 @@ def update_progress(
}
)
# Remove reminders and policies that no longer apply
transact.delete(
key=KeyPair(
pk=id,
sk='CANCEL_POLICY',
),
)
transact.delete(
key=KeyPair(
pk=id,
sk='SCHEDULE#REMINDER_NO_ACCESS_AFTER_3_DAYS',
)
)
transact.delete(
key=KeyPair(pk=id, sk='CANCEL_POLICY'),
)
return True
def set_score(
id: str,
/,
score: Decimal,
progress: Decimal,
*,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
):
@@ -138,6 +144,7 @@ def set_score(
return _set_status_as_completed(
id,
score,
progress=progress,
user_id=user_id,
course_id=course_id,
cert_exp_interval=int(
@@ -161,6 +168,7 @@ def set_score(
return _set_status_as_failed(
id,
score,
progress=progress,
user_id=user_id,
course_id=course_id,
dynamodb_persistence_layer=dynamodb_persistence_layer,
@@ -174,6 +182,7 @@ def _set_status_as_completed(
id: str,
/,
score: Decimal,
progress: Decimal,
*,
user_id: str,
course_id: str,
@@ -199,8 +208,8 @@ def _set_status_as_completed(
with dynamodb_persistence_layer.transact_writer() as transact:
transact.update(
key=KeyPair(pk=id, sk='0'),
update_expr='SET #status = :completed, score = :score, \
updated_at = :updated_at',
update_expr='SET #status = :completed, progress = :progress, \
score = :score, updated_at = :updated_at',
cond_expr='#status = :in_progress',
expr_attr_names={'#status': 'status'},
expr_attr_values={
@@ -208,6 +217,7 @@ def _set_status_as_completed(
':in_progress': 'IN_PROGRESS',
':score': score,
':updated_at': now_,
':progress': progress,
},
exc_cls=EnrollmentConflictError,
)
@@ -242,6 +252,7 @@ def _set_status_as_completed(
'id': id,
'sk': 'LOCK',
'ttl': deduplication_lock_ttl,
'hash': lock_hash,
'created_at': now_,
}
)
@@ -256,6 +267,12 @@ def _set_status_as_completed(
)
# Remove reminders and policies that no longer apply
transact.delete(
key=KeyPair(
pk=id,
sk='CANCEL_POLICY',
)
)
transact.delete(
key=KeyPair(
pk=id,
@@ -282,6 +299,7 @@ def _set_status_as_failed(
id: str,
/,
score: Decimal,
progress: Decimal,
user_id: str,
course_id: str,
*,
@@ -293,14 +311,15 @@ def _set_status_as_failed(
with dynamodb_persistence_layer.transact_writer() as transact:
transact.update(
key=KeyPair(pk=id, sk='0'),
update_expr='SET #status = :failed, score = :score, \
updated_at = :updated_at',
update_expr='SET #status = :failed, progress = :progress, \
score = :score, updated_at = :updated_at',
cond_expr='#status = :in_progress',
expr_attr_names={'#status': 'status'},
expr_attr_values={
':failed': 'FAILED',
':in_progress': 'IN_PROGRESS',
':score': score,
':progress': progress,
':updated_at': now_,
},
exc_cls=EnrollmentConflictError,
@@ -314,6 +333,12 @@ def _set_status_as_failed(
cond_expr='attribute_not_exists(sk)',
)
# Remove reminders and events that no longer apply
transact.delete(
key=KeyPair(
pk=id,
sk='CANCEL_POLICY',
)
)
transact.delete(
key=KeyPair(
pk=id,
@@ -413,6 +438,12 @@ def _set_status_as_expired(
cond_expr='attribute_not_exists(sk)',
)
# Remove events and policies that no longer apply
transact.delete(
key=KeyPair(
pk=id,
sk='CANCEL_POLICY',
),
)
transact.delete(
key=KeyPair(
pk=id,