'Extend the program data with data about learner\'s eligibility for one click purchase,
discount data of the program and SKUs of seats that should be added to basket.'

def _collect_one_click_purchase_eligibility_data(self):

    applicable_seat_types = self.data['applicable_seat_types']
    is_learner_eligible_for_one_click_purchase = self.data['is_program_eligible_for_one_click_purchase']
    skus = []
    if is_learner_eligible_for_one_click_purchase:
        for course in self.data['courses']:
            is_learner_eligible_for_one_click_purchase = (not any((course_run['is_enrolled'] for course_run in course['course_runs'])))
            if is_learner_eligible_for_one_click_purchase:
                published_course_runs = filter((lambda run: (run['status'] == 'published')), course['course_runs'])
                if (len(published_course_runs) == 1):
                    for seat in published_course_runs[0]['seats']:
                        if ((seat['type'] in applicable_seat_types) and seat['sku']):
                            skus.append(seat['sku'])
                else:
                    is_learner_eligible_for_one_click_purchase = False
                    skus = []
                    break
            else:
                skus = []
                break
    if skus:
        try:
            User = get_user_model()
            service_user = User.objects.get(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME)
            api = ecommerce_api_client(service_user)
            discount_data = api.baskets.calculate.get(sku=skus)
            program_discounted_price = discount_data['total_incl_tax']
            program_full_price = discount_data['total_incl_tax_excl_discounts']
            discount_data['is_discounted'] = (program_discounted_price < program_full_price)
            discount_data['discount_value'] = (program_full_price - program_discounted_price)
            self.data.update({'discount_data': discount_data, 'full_program_price': discount_data['total_incl_tax']})
        except (ConnectionError, SlumberBaseException, Timeout):
            log.exception('Failed    to    get    discount    price    for    following    product    SKUs:    %s    ', ',    '.join(skus))
    self.data.update({'is_learner_eligible_for_one_click_purchase': is_learner_eligible_for_one_click_purchase, 'skus': skus})
