def refund_seat(course_enrollment, request_user):
 course_key_str = unicode(course_enrollment.course_id)
 unenrolled_user = course_enrollment.user
 try:
  refund_ids = ecommerce_api_client((request_user or unenrolled_user)).refunds.post({u'course_id': course_key_str, u'username': unenrolled_user.username})
 except HttpClientError as exc:
  if ((exc.response.status_code == 403) and (request_user != unenrolled_user)):
   log.warning(u'User [%s] was not authorized to initiate a refund for user [%s] upon unenrollment from course [%s]', request_user.id, unenrolled_user.id, course_key_str)
   return []
  else:
   raise exc
 if refund_ids:
  log.info(u'Refund successfully opened for user [%s], course [%s]: %r', unenrolled_user.id, course_key_str, refund_ids)
  if (course_enrollment.mode != u'verified'):
   log.info(u'Skipping refund email notification for non-verified mode for user [%s], course [%s], mode: [%s]', course_enrollment.user.id, course_enrollment.course_id, course_enrollment.mode)
  else:
   try:
    send_refund_notification(course_enrollment, refund_ids)
   except:
    log.warning(u'Could not send email notification for refund.', exc_info=True)
 else:
  log.debug(u'No refund opened for user [%s], course [%s]', unenrolled_user.id, course_key_str)
 return refund_ids

def refund_seat ( course_enrollment , request_user ) : course_key_str = unicode ( course_enrollment . course_id ) unenrolled_user = course_enrollment . user try : refund_ids = ecommerce_api_client ( ( request_user or unenrolled_user ) ) . refunds . post ( { u'course_id' : course_key_str , u'username' : unenrolled_user . username } ) except HttpClientError as exc : if ( ( exc . response . status_code == 403 ) and ( request_user != unenrolled_user ) ) : log . warning ( u'User [%s] was not authorized to initiate a refund for user [%s] upon unenrollment from course [%s]' , request_user . id , unenrolled_user . id , course_key_str ) return [ ] else : raise exc if refund_ids : log . info ( u'Refund successfully opened for user [%s], course [%s]: %r' , unenrolled_user . id , course_key_str , refund_ids ) if ( course_enrollment . mode != u'verified' ) : log . info ( u'Skipping refund email notification for non-verified mode for user [%s], course [%s], mode: [%s]' , course_enrollment . user . id , course_enrollment . course_id , course_enrollment . mode ) else : try : send_refund_notification ( course_enrollment , refund_ids ) except : log . warning ( u'Could not send email notification for refund.' , exc_info = True ) else : log . debug ( u'No refund opened for user [%s], course [%s]' , unenrolled_user . id , course_key_str ) return refund_ids
attempt to initiate a refund for any orders associated with the seat being unenrolled .