def _notify_purchaser(self): """ Notify the purchaser that the refund has been processed. """ site_configuration = self.order.site.siteconfiguration site_code = site_configuration.partner.short_code if not site_configuration.send_refund_notifications: logger.info( 'Refund notifications are disabled for Partner [%s]. No notification will be sent for Refund [%d]', site_code, self.id ) return # NOTE (CCB): The initial version of the refund email only supports refunding a single course. product = self.lines.first().order_line.product product_class = product.get_product_class().name if product_class != SEAT_PRODUCT_CLASS_NAME: logger.warning( ('No refund notification will be sent for Refund [%d]. The notification supports product lines ' 'of type Course, not [%s].'), self.id, product_class ) return course_name = self.lines.first().order_line.product.course.name order_number = self.order.number order_url = get_receipt_page_url(site_configuration, order_number) amount = format_currency(self.currency, self.total_credit_excl_tax) send_course_refund_email.delay(self.user.email, self.id, amount, course_name, order_number, order_url, site_code=site_code) logger.info('Course refund notification scheduled for Refund [%d].', self.id)
def test_notify_purchaser(self, mock_task): """ Verify the notification is scheduled if the site has notifications enabled and the refund is for a course seat. """ site_configuration = self.site.siteconfiguration site_configuration.send_refund_notifications = True user = UserFactory() course = CourseFactory() price = Decimal(100.00) product = course.create_or_update_seat('verified', True, price, self.partner) basket = create_basket(empty=True) basket.site = self.site basket.add_product(product) order = create_order(basket=basket, user=user) order_url = get_receipt_page_url(site_configuration, order.number) refund = Refund.create_with_lines(order, order.lines.all()) with LogCapture(REFUND_MODEL_LOGGER_NAME) as l: refund._notify_purchaser() # pylint: disable=protected-access msg = 'Course refund notification scheduled for Refund [{}].'.format(refund.id) l.check( (REFUND_MODEL_LOGGER_NAME, 'INFO', msg) ) amount = format_currency(order.currency, price) mock_task.assert_called_once_with( user.email, refund.id, amount, course.name, order.number, order_url, site_code=self.partner.short_code )
def test_notify_purchaser(self, mock_task): """ Verify the notification is scheduled if the site has notifications enabled and the refund is for a course seat. """ site_configuration = self.site.siteconfiguration site_configuration.send_refund_notifications = True user = UserFactory() course = CourseFactory() price = Decimal(100.00) product = course.create_or_update_seat('verified', True, price, self.partner) basket = create_basket(empty=True) basket.site = self.site basket.add_product(product) order = create_order(basket=basket, user=user) order_url = get_receipt_page_url(site_configuration, order.number) refund = Refund.create_with_lines(order, order.lines.all()) with LogCapture(REFUND_MODEL_LOGGER_NAME) as l: refund._notify_purchaser() # pylint: disable=protected-access msg = 'Course refund notification scheduled for Refund [{}].'.format( refund.id) l.check((REFUND_MODEL_LOGGER_NAME, 'INFO', msg)) amount = format_currency(order.currency, price) mock_task.assert_called_once_with(user.email, refund.id, amount, course.name, order.number, order_url, site_code=self.partner.short_code)