def get_fulfillable_entitlement_for_user_course_run( cls, user, course_run_key): """ Retrieves a fulfillable entitlement for the user and the given course run. Arguments: user (User): The user that we are inspecting the entitlements for. course_run_key (CourseKey): The course run Key. Returns: CourseEntitlement: The most recent fulfillable CourseEntitlement, None otherwise. """ # Check if the User has any fulfillable entitlements. # Note: Wait to retrieve the Course UUID until we have confirmed the User has fulfillable entitlements. # This was done to avoid calling the APIs when the User does not have an entitlement. entitlements = cls.get_fulfillable_entitlements(user) if entitlements: course_uuid = get_course_uuid_for_course(course_run_key) if course_uuid: entitlement = entitlements.filter( course_uuid=course_uuid).first() if (is_course_run_entitlement_fulfillable( course_run_key=course_run_key, entitlement=entitlement) and entitlement.is_entitlement_redeemable()): return entitlement return None
def unenroll_entitlement(cls, course_enrollment, skip_refund): """ Un-enroll the user from entitlement and refund if needed. """ course_uuid = get_course_uuid_for_course(course_enrollment.course_id) course_entitlement = cls.get_entitlement_if_active(course_enrollment.user, course_uuid) if course_entitlement and course_entitlement.enrollment_course_run == course_enrollment: course_entitlement.set_enrollment(None) if not skip_refund and course_entitlement.is_entitlement_refundable(): course_entitlement.expire_entitlement() course_entitlement.refund()
def get_fulfillable_entitlement_for_user_course_run(cls, user, course_run_key): """ Retrieves a fulfillable entitlement for the user and the given course run. Arguments: user (User): The user that we are inspecting the entitlements for. course_run_key (CourseKey): The course run Key. Returns: CourseEntitlement: The most recent fulfillable CourseEntitlement, None otherwise. """ # Check if the User has any fulfillable entitlements. # Note: Wait to retrieve the Course UUID until we have confirmed the User has fulfillable entitlements. # This was done to avoid calling the APIs when the User does not have an entitlement. entitlements = cls.get_fulfillable_entitlements(user) if entitlements: course_uuid = get_course_uuid_for_course(course_run_key) if course_uuid: entitlement = entitlements.filter(course_uuid=course_uuid).first() if (is_course_run_entitlement_fulfillable(course_run_key=course_run_key, entitlement=entitlement) and entitlement.is_entitlement_redeemable()): return entitlement return None