Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
feat: Remove course refund email and update_course_enrollment from ec…
Browse files Browse the repository at this point in the history
…ommerce-worker (#124)

As part of the sailthru to braze transition
AA-715
  • Loading branch information
MatthewPiatetsky authored Mar 30, 2021
1 parent b3083e5 commit eaab282
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 555 deletions.
1 change: 0 additions & 1 deletion ecommerce_worker/configuration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@

# Transactional email template name map
'templates': {
'course_refund': 'Course Refund',
'assignment_email': 'Offer Assignment Email',
'enterprise_portal_email': 'Enterprise Portal Email',
}
Expand Down
142 changes: 0 additions & 142 deletions ecommerce_worker/sailthru/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,148 +221,6 @@ def _update_unenrolled_list(sailthru_client, email, course_url, unenroll):
return False


@shared_task(bind=True, ignore_result=True)
def update_course_enrollment(self, email, course_url, purchase_incomplete, mode, unit_cost=None, course_id=None,
currency=None, message_id=None, site_code=None, sku=None):
"""Adds/updates Sailthru when a user adds to cart/purchases/upgrades a course
Args:
email(str): The user's email address
course_url(str): Course home page url
purchase_incomplete(boolean): True if adding to cart
mode(string): enroll mode (audit, verification, ...)
unit_cost(decimal): cost if purchase event
course_id(CourseKey): course id
currency(str): currency if purchase event - currently ignored since Sailthru only supports USD
message_id(str): value from Sailthru marketing campaign cookie
site_code(str): site code
Returns:
None
"""
# Celery converts decimals to strings, so convert back
unit_cost = Decimal(unit_cost)

# Get configuration
config = get_sailthru_configuration(site_code)

try:
sailthru_client = get_sailthru_client(site_code)
except SailthruError:
# NOTE: We rely on the function to log the error for us
return

# Use event type to figure out processing required
new_enroll = False
send_template = None

if not purchase_incomplete:
if mode == 'verified':
# upgrade complete
send_template = config.get('SAILTHRU_UPGRADE_TEMPLATE')
elif mode in ('audit', 'honor'):
# free enroll
new_enroll = True
send_template = config.get('SAILTHRU_ENROLL_TEMPLATE')
else:
# paid course purchase complete
new_enroll = True
send_template = config.get('SAILTHRU_PURCHASE_TEMPLATE')

# calc price in pennies for Sailthru
# https://getstarted.sailthru.com/new-for-developers-overview/advanced-features/purchase/
cost_in_cents = int(unit_cost * 100)

# update the "unenrolled" course array in the user record on Sailthru if new enroll or unenroll
if new_enroll:
if not _update_unenrolled_list(sailthru_client, email, course_url, False):
schedule_retry(self, config)

# Get course data from Sailthru content library or cache
course_data = _get_course_content(course_id, course_url, sailthru_client, site_code, config)

# build item description
item = _build_purchase_item(course_id, course_url, cost_in_cents, mode, course_data, sku)

# build purchase api options list
options = {}
if purchase_incomplete and config.get('SAILTHRU_ABANDONED_CART_TEMPLATE'):
options['reminder_template'] = config.get('SAILTHRU_ABANDONED_CART_TEMPLATE')
# Sailthru reminder time format is '+n time unit'
options['reminder_time'] = "+{} minutes".format(config.get('SAILTHRU_ABANDONED_CART_DELAY'))

# add appropriate send template
if send_template:
options['send_template'] = send_template

if not _record_purchase(sailthru_client, email, item, purchase_incomplete, message_id, options):
schedule_retry(self, config)


@shared_task(bind=True, ignore_result=True)
def send_course_refund_email(self, email, refund_id, amount, course_name, order_number, order_url, site_code=None):
""" Sends the course refund email.
Args:
self: Ignore.
email (str): Recipient's email address.
refund_id (int): ID of the refund that initiated this task.
amount (str): Formatted amount of the refund.
course_name (str): Name of the course for which payment was refunded.
order_number (str): Order number of the order that was refunded.
order_url (str): Receipt URL of the refunded order.
site_code (str): Identifier of the site sending the email.
"""
config = get_sailthru_configuration(site_code)

try:
sailthru_client = get_sailthru_client(site_code)
except SailthruError:
# NOTE: We rely on the function to log the error for us
return

email_vars = {
'amount': amount,
'course_name': course_name,
'order_number': order_number,
'order_url': order_url,
}

try:
response = sailthru_client.send(
template=config['templates']['course_refund'],
email=email,
_vars=email_vars
)
except SailthruClientError:
logger.exception(
'A client error occurred while attempting to send a course refund notification for refund [%d].',
refund_id
)
return

if response.is_ok():
logger.info('Course refund notification sent for refund %d.', refund_id)
else:
error = response.get_error()
logger.error(
'An error occurred while attempting to send a course refund notification for refund [%d]: %d - %s',
refund_id, error.get_error_code(), error.get_message()
)

if can_retry_sailthru_request(error):
logger.info(
'An attempt will be made again to send a course refund notification for refund [%d].',
refund_id
)
schedule_retry(self, config)
else:
logger.warning(
'No further attempts will be made to send a course refund notification for refund [%d].',
refund_id
)


def _send_offer_assignment_email_via_braze(self, user_email, offer_assignment_id, subject, email_body, sender_alias,
site_code=None, base_enterprise_url=''):
"""
Expand Down
Loading

0 comments on commit eaab282

Please sign in to comment.