Skip to content

Commit

Permalink
Merge pull request #473 from commonknowledge/handle-mailchimp-api-error
Browse files Browse the repository at this point in the history
Prevent MailChimp API error from crashing application at checkout
  • Loading branch information
Moggach authored Jul 17, 2024
2 parents 5d4a4b5 + 21ed633 commit f53be55
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/utils/mailchimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ def mailchimp_contact_for_user(user: User, list_id=settings.MAILCHIMP_LIST_ID):
member = apply_gdpr_consent(member)
return member
except MailchimpApiClientError:
member = mailchimp.lists.add_list_member(
list_id,
{
"email_address": user.primary_email,
"merge_fields": {"FNAME": user.first_name, "LNAME": user.last_name},
"status": "subscribed" if user.gdpr_email_consent else "unsubscribed",
},
)
member = apply_gdpr_consent(member)
return member
try:
member = mailchimp.lists.add_list_member(
list_id,
{
"email_address": user.primary_email,
"merge_fields": {"FNAME": user.first_name, "LNAME": user.last_name},
"status": "subscribed" if user.gdpr_email_consent else "unsubscribed",
},
)
member = apply_gdpr_consent(member)
return member
except MailchimpApiClientError as e:
print(f"Failed to add list member: {e}")
return None


def tag_user_in_mailchimp(user: User, tags_to_enable=list(), tags_to_disable=list()):
Expand Down

0 comments on commit f53be55

Please sign in to comment.