def send_code_assignment_nudge_email(self, email, subject, email_body, site_code=None): """ Sends the code assignment nudge email. Args: self: Ignore. email (str): Recipient's email address. subject (str): Email subject. email_body (str): The body of the email. site_code (str): Identifier of the site sending the email. """ config = get_sailthru_configuration(site_code) notification = Notification(config=config, emails=email, email_vars={ 'subject': subject, 'email_body': email_body }, logger_prefix='Code Assignment Nudge Email', site_code=site_code, template='enterprise_portal_email') _, is_eligible_for_retry = notification.send() if is_eligible_for_retry: schedule_retry(self, config)
def send_offer_assignment_email(self, user_email, offer_assignment_id, subject, email_body, site_code=None): """ Sends the offer assignment email. Args: self: Ignore. user_email (str): Recipient's email address. offer_assignment_id (str): Key of the entry in the offer_assignment model. subject (str): Email subject. email_body (str): The body of the email. site_code (str): Identifier of the site sending the email. """ # TODO: Notification class should be used for sending the notification. config = get_sailthru_configuration(site_code) response = _send_offer_assignment_notification_email( config, user_email, subject, email_body, site_code, self) if response and response.is_ok(): send_id = response.get_body().get('send_id') # pylint: disable=no-member if _update_assignment_email_status(offer_assignment_id, send_id, 'success'): logger.info( '[Offer Assignment] Offer assignment notification sent with message --- {message}' .format(message=email_body)) else: logger.exception( '[Offer Assignment] An error occurred while updating email status data for ' 'offer {token_offer} and email {token_email} via the ecommerce API.' .format( token_offer=offer_assignment_id, token_email=user_email, ))
def send_offer_update_email(self, user_email, subject, email_body, site_code=None): """ Sends the offer emails after assignment, either for revoking or reminding. Args: self: Ignore. user_email (str): Recipient's email address. subject (str): Email subject. email_body (str): The body of the email. site_code (str): Identifier of the site sending the email. """ config = get_sailthru_configuration(site_code) notification = Notification(config=config, emails=user_email, email_vars={ 'subject': subject, 'email_body': email_body }, logger_prefix='Offer Assignment', site_code=site_code, template='enterprise_portal_email') _, is_eligible_for_retry = notification.send() if is_eligible_for_retry: schedule_retry(self, config)
def send_offer_assignment_email(self, user_email, offer_assignment_id, subject, email_body, sender_alias, site_code=None, base_enterprise_url=''): """ Sends the offer assignment email. Args: self: Ignore. user_email (str): Recipient's email address. offer_assignment_id (str): Key of the entry in the offer_assignment model. subject (str): Email subject. email_body (str): The body of the email. site_code (str): Identifier of the site sending the email. base_enterprise_url (str): Url for the enterprise learner portal. sender_alias (str): Enterprise Customer sender alias used as From Name. """ config = get_sailthru_configuration(site_code) notification = Notification(config=config, emails=user_email, email_vars={ 'subject': subject, 'email_body': email_body, 'base_enterprise_url': base_enterprise_url, 'sender_alias': sender_alias, }, logger_prefix='Offer Assignment', site_code=site_code, template='enterprise_portal_email') response, is_eligible_for_retry = notification.send() if is_eligible_for_retry: schedule_retry(self, config) if response and response.is_ok(): send_id = response.get_body().get('send_id') # pylint: disable=no-member if _update_assignment_email_status(offer_assignment_id, send_id, 'success'): logger.info( '[Offer Assignment] Offer assignment notification sent with message --- ' '{message}; base enterprise url --- {base_enterprise_url}'. format(message=email_body, base_enterprise_url=base_enterprise_url)) else: logger.exception( '[Offer Assignment] An error occurred while updating email status data for ' 'offer {token_offer} and email {token_email} via the ecommerce API.' .format( token_offer=offer_assignment_id, token_email=user_email, ))
def send_offer_update_email(self, user_email, subject, email_body, site_code=None): """ Sends the offer emails after assignment, either for revoking or reminding. Args: self: Ignore. user_email (str): Recipient's email address. subject (str): Email subject. email_body (str): The body of the email. site_code (str): Identifier of the site sending the email. """ config = get_sailthru_configuration(site_code) _send_offer_assignment_notification_email(config, user_email, subject, email_body, site_code, self)
def send_offer_usage_email(self, emails, subject, email_body, site_code=None): """ Sends the offer usage email. Args: self: Ignore. emails (str): comma separated emails. subject (str): Email subject. email_body (str): The body of the email. site_code (str): Identifier of the site sending the email. """ config = get_sailthru_configuration(site_code) _, is_eligible_for_retry = Notification( config=config, emails=emails, email_vars={ 'subject': subject, 'email_body': email_body, }, logger_prefix="Offer Usage", site_code=site_code, template='usage_email').send(is_multi_send=True) if is_eligible_for_retry: schedule_retry(self, config)
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 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 """ # 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 == 'audit' or mode == '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)