billing: Add transaction.atomic() for Customer creation and logging.

This commit is contained in:
Rishi Gupta 2018-08-22 18:40:38 -07:00
parent 3cf9cd00d6
commit d081cf7b78
1 changed files with 11 additions and 10 deletions

View File

@ -146,16 +146,17 @@ def do_create_customer_with_payment_source(user: UserProfile, stripe_token: str)
if PRINT_STRIPE_FIXTURE_DATA:
print(''.join(['"create_customer": ', str(stripe_customer), ','])) # nocoverage
event_time = timestamp_to_datetime(stripe_customer.created)
RealmAuditLog.objects.create(
realm=user.realm, acting_user=user, event_type=RealmAuditLog.STRIPE_CUSTOMER_CREATED,
event_time=event_time)
RealmAuditLog.objects.create(
realm=user.realm, acting_user=user, event_type=RealmAuditLog.STRIPE_CARD_ADDED,
event_time=event_time)
Customer.objects.create(
realm=realm,
stripe_customer_id=stripe_customer.id,
billing_user=user)
with transaction.atomic():
RealmAuditLog.objects.create(
realm=user.realm, acting_user=user, event_type=RealmAuditLog.STRIPE_CUSTOMER_CREATED,
event_time=event_time)
RealmAuditLog.objects.create(
realm=user.realm, acting_user=user, event_type=RealmAuditLog.STRIPE_CARD_ADDED,
event_time=event_time)
Customer.objects.create(
realm=realm,
stripe_customer_id=stripe_customer.id,
billing_user=user)
return stripe_customer
@catch_stripe_errors