5050from flexiblepricing .api import determine_courseware_flexible_price_discount
5151from hubspot_sync .task_helpers import sync_hubspot_deal
5252from main .constants import (
53+ USER_MSG_TYPE_B2B_ERROR_MISSING_ENROLLMENT_CODE ,
54+ USER_MSG_TYPE_B2B_INVALID_BASKET ,
55+ USER_MSG_TYPE_BASKET_EMPTY ,
5356 USER_MSG_TYPE_COURSE_NON_UPGRADABLE ,
5457 USER_MSG_TYPE_DISCOUNT_INVALID ,
5558 USER_MSG_TYPE_ENROLL_BLOCKED ,
@@ -74,6 +77,7 @@ def generate_checkout_payload(request): # noqa: PLR0911
7477 if basket .has_user_blocked_products (request .user ):
7578 return {
7679 "country_blocked" : True ,
80+ "error" : USER_MSG_TYPE_ENROLL_BLOCKED ,
7781 "response" : redirect_with_user_message (
7882 reverse ("user-dashboard" ),
7983 {"type" : USER_MSG_TYPE_ENROLL_BLOCKED },
@@ -83,6 +87,7 @@ def generate_checkout_payload(request): # noqa: PLR0911
8387 if basket .has_user_purchased_same_courserun (request .user ):
8488 return {
8589 "purchased_same_courserun" : True ,
90+ "error" : USER_MSG_TYPE_ENROLL_DUPLICATED ,
8691 "response" : redirect_with_user_message (
8792 reverse ("cart" ),
8893 {"type" : USER_MSG_TYPE_ENROLL_DUPLICATED },
@@ -92,6 +97,7 @@ def generate_checkout_payload(request): # noqa: PLR0911
9297 if basket .has_user_purchased_non_upgradable_courserun ():
9398 return {
9499 "purchased_non_upgradeable_courserun" : True ,
100+ "error" : USER_MSG_TYPE_COURSE_NON_UPGRADABLE ,
95101 "response" : redirect_with_user_message (
96102 reverse ("cart" ),
97103 {"type" : USER_MSG_TYPE_COURSE_NON_UPGRADABLE },
@@ -104,6 +110,7 @@ def generate_checkout_payload(request): # noqa: PLR0911
104110 apply_user_discounts (request )
105111 return {
106112 "invalid_discounts" : True ,
113+ "error" : USER_MSG_TYPE_DISCOUNT_INVALID ,
107114 "response" : redirect_with_user_message (
108115 reverse ("cart" ),
109116 {"type" : USER_MSG_TYPE_DISCOUNT_INVALID },
@@ -115,6 +122,7 @@ def generate_checkout_payload(request): # noqa: PLR0911
115122 if not is_discount_supplied_for_b2b_purchase (request , active_contracts ):
116123 return {
117124 "invalid_discounts" : True ,
125+ "error" : USER_MSG_TYPE_B2B_ERROR_MISSING_ENROLLMENT_CODE ,
118126 "response" : redirect_with_user_message (
119127 reverse ("cart" ),
120128 {"type" : USER_MSG_TYPE_REQUIRED_ENROLLMENT_CODE_EMPTY },
@@ -124,12 +132,23 @@ def generate_checkout_payload(request): # noqa: PLR0911
124132 if not validate_basket_for_b2b_purchase (request , active_contracts ):
125133 return {
126134 "invalid_discounts" : True ,
135+ "error" : USER_MSG_TYPE_B2B_INVALID_BASKET ,
127136 "response" : redirect_with_user_message (
128137 reverse ("cart" ),
129138 {"type" : USER_MSG_TYPE_DISCOUNT_INVALID },
130139 ),
131140 }
132141
142+ if not basket .basket_items .count ():
143+ return {
144+ "basket_empty" : True ,
145+ "error" : USER_MSG_TYPE_BASKET_EMPTY ,
146+ "response" : redirect_with_user_message (
147+ reverse ("cart" ),
148+ {"type" : USER_MSG_TYPE_BASKET_EMPTY },
149+ ),
150+ }
151+
133152 order = PendingOrder .create_from_basket (basket )
134153 total_price = 0
135154
0 commit comments