def _update_assignment_email_status(offer_assignment_id, send_id, status, site_code=None): """ Update the offer_assignment and offer_assignment_email model using the Ecommerce assignmentemail api. Arguments: offer_assignment_id (str): Key of the entry in the offer_assignment model. send_id (str): Unique message id from Sailthru status (str): status to be sent to the api site_code (str): site code Returns: True or False based on model update status from Ecommerce api """ api = get_ecommerce_client(url_postfix='assignment-email/', site_code=site_code) post_data = { 'offer_assignment_id': offer_assignment_id, 'send_id': send_id, 'status': status, } try: api_response = api.status().post(post_data) except RequestException: logger.exception( '[Offer Assignment] An error occurred while updating offer assignment email status for ' 'offer id {token_offer} and message id {token_send_id} via the Ecommerce API.' .format(token_offer=offer_assignment_id, token_send_id=send_id)) return False return True if api_response.get('status') == 'updated' else False
def fulfill_order(self, order_number, site_code=None, email_opt_in=False): """Fulfills an order. Arguments: order_number (str): Order number indicating which order to fulfill. Returns: None """ max_fulfillment_retries = get_configuration('MAX_FULFILLMENT_RETRIES', site_code=site_code) api = get_ecommerce_client(site_code=site_code) try: logger.info('Requesting fulfillment of order [%s].', order_number) api.orders(order_number).fulfill.put(email_opt_in=email_opt_in) except exceptions.HttpClientError as exc: status_code = exc.response.status_code # pylint: disable=no-member if status_code == 406: # The order is not fulfillable. Therefore, it must be complete. logger.info('Order [%s] has already been fulfilled. Ignoring.', order_number) raise Ignore() # Unknown client error. Let's retry to resolve it. logger.warning( 'Fulfillment of order [%s] failed because of HttpClientError. Retrying', order_number, exc_info=True ) _retry_order(self, exc, max_fulfillment_retries, order_number) except (exceptions.HttpServerError, exceptions.Timeout, SSLError) as exc: # Fulfillment failed, retry _retry_order(self, exc, max_fulfillment_retries, order_number)
def _get_course_content_from_ecommerce(course_id, site_code=None): """ Get course information using the Ecommerce course api. In case of error returns empty response. Arguments: course_id (str): course key of the course site_code (str): site code Returns: course information from Ecommerce """ api = get_ecommerce_client(site_code=site_code) try: api_response = api.courses(course_id).get() except Exception: # pylint: disable=broad-except logger.exception( 'An error occurred while retrieving data for course run [%s] from the Catalog API.', course_id, exc_info=True) return {} return { 'title': api_response.get('name'), 'verification_deadline': api_response.get('verification_deadline') }