lms.djangoapps.commerce package#
Subpackages#
Submodules#
lms.djangoapps.commerce.apps module#
Commerce Application Configuration
lms.djangoapps.commerce.constants module#
Constants for this app as well as the external API.
- class lms.djangoapps.commerce.constants.Messages#
Bases:
objectStrings used to populate response messages.
- ENROLLMENT_CLOSED = 'Enrollment is closed for {course_id}.'#
- ENROLLMENT_EXISTS = 'User {username} is already enrolled in {course_id}.'#
- ENROLL_DIRECTLY = 'Enroll {username} in {course_id} directly because no need for E-Commerce baskets and orders.'#
- NO_DEFAULT_ENROLLMENT_MODE = 'Course {course_id} does not have an honor or audit mode.'#
- NO_ECOM_API = 'E-Commerce API not setup. Enrolled {username} in {course_id} directly.'#
- NO_HONOR_MODE = 'Course {course_id} does not have an honor mode.'#
- NO_SKU_ENROLLED = 'The {enrollment_mode} mode for {course_id}, {course_name}, does not have a SKU. Enrolling {username} directly. Course announcement is {announcement}.'#
- ORDER_COMPLETED = 'Order {order_number} was completed.'#
- ORDER_INCOMPLETE_ENROLLED = 'Order {order_number} was created, but is not yet complete. User was enrolled.'#
lms.djangoapps.commerce.exceptions module#
E-Commerce-related exceptions.
- exception lms.djangoapps.commerce.exceptions.InvalidResponseError#
Bases:
ExceptionException raised when an API response is invalid.
lms.djangoapps.commerce.http module#
HTTP-related entities.
- class lms.djangoapps.commerce.http.DetailResponse(message, status=200)#
Bases:
JsonResponseJSON response that simply contains a detail field.
- class lms.djangoapps.commerce.http.InternalRequestErrorResponse(internal_message)#
Bases:
DetailResponseResponse returned when an internal service request fails.
lms.djangoapps.commerce.models module#
Commerce-related models.
- class lms.djangoapps.commerce.models.CommerceConfiguration(*args, **kwargs)#
Bases:
ConfigurationModelCommerce configuration
- API_NAME = 'commerce'#
- CACHE_KEY = 'commerce.api.data'#
- DEFAULT_ORDER_DASHBOARD_URL = '/dashboard/orders/'#
- DEFAULT_RECEIPT_PAGE_URL = '/checkout/receipt/?order_number='#
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- basket_checkout_page#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- cache_ttl#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- checkout_on_ecommerce_service#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enable_automatic_refund_approval#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property is_cache_enabled#
Whether responses from the Ecommerce API will be cached.
- receipt_page#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
lms.djangoapps.commerce.signals module#
Signal handling functions for use with external commerce service.
- lms.djangoapps.commerce.signals.get_request_user()#
Helper to get the authenticated user from the current HTTP request (if applicable).
If the requester of an unenrollment is not the same person as the student being unenrolled, we authenticate to the commerce service as the requester.
- lms.djangoapps.commerce.signals.handle_refund_order(sender, course_enrollment=None, **kwargs)#
Signal receiver for un-enrollments, used to automatically initiate refunds when applicable.
lms.djangoapps.commerce.utils module#
Utilities to assist with commerce tasks.
- class lms.djangoapps.commerce.utils.EcommerceService#
Bases:
objectHelper class for ecommerce service integration.
- property ecommerce_url_root#
Retrieve Ecommerce service public url root.
- get_absolute_ecommerce_url(ecommerce_page_url)#
Return the absolute URL to the ecommerce page.
- Parameters:
ecommerce_page_url (str) – Relative path to the ecommerce page.
- Returns:
Absolute path to the ecommerce page.
- get_checkout_page_url(*skus, **kwargs)#
Construct the URL to the ecommerce checkout page and include products.
- Parameters:
skus (list) – List of SKUs associated with products to be added to basket
program_uuid (string) – The UUID of the program, if applicable
course_run_keys (list) – The course run keys of the products to be added to basket.
- Returns:
Absolute path to the ecommerce checkout page showing basket that contains specified products.
Example
http://localhost:8002/basket/add/?sku=5H3HG5&sku=57FHHD http://localhost:8002/basket/add/?sku=5H3HG5&sku=57FHHD&bundle=3bdf1dd1-49be-4a15-9145-38901f578c5a
- get_order_dashboard_url()#
Return the URL to the ecommerce dashboard orders page.
- Returns:
order dashboard url.
- Return type:
String
- get_receipt_page_url(order_number)#
Gets the URL for the Order Receipt page hosted by the ecommerce service.
- Parameters:
order_number (str) – Order number.
- Returns:
Receipt page for the specified Order.
- is_enabled(user)#
Determines the availability of the EcommerceService based on user activation and service configuration. Note: If the user is anonymous we bypass the user activation gate and only look at the service config.
- Returns:
Boolean
- payment_page_url()#
Return the URL for the checkout page.
Example
- upgrade_url(user, course_key)#
Returns the URL for the user to upgrade, or None if not applicable.
- lms.djangoapps.commerce.utils.auto_enroll(course_enrollment)#
Helper method to update an enrollment to a default course mode.
- Parameters:
course_enrollment (CourseEnrollment) – The course_enrollment to update.
- Returns:
True if auto-enroll is successful. False if auto-enroll is not applicable.
- Return type:
bool
- lms.djangoapps.commerce.utils.create_zendesk_ticket(requester_name, requester_email, subject, body, tags=None)#
Create a Zendesk ticket via API.
- Returns:
False if we are unable to create the ticket for any reason
- Return type:
bool
- lms.djangoapps.commerce.utils.get_program_price_info(api_user, params)#
Get the program price info from the ecommerce service.
- Parameters:
api_user – The user to use to make the request.
params – The params to use to make the request.
- Returns:
- {
‘total_incl_tax_excl_discounts’: basket.total_incl_tax_excl_discounts, ‘total_incl_tax’: basket.total_incl_tax, ‘currency’: basket.currency
}
- Return type:
JSON
- lms.djangoapps.commerce.utils.is_account_activation_requirement_disabled()#
Checks to see if the django-waffle switch for disabling the account activation requirement is active
- Returns:
Boolean value representing switch status
- lms.djangoapps.commerce.utils.refund_entitlement(course_entitlement)#
Attempt a refund of a course entitlement. Verify the User before calling this refund method
- Returns:
True if the Refund is successfully processed.
- Return type:
bool
- lms.djangoapps.commerce.utils.refund_seat(course_enrollment, change_mode=False)#
Attempt to initiate a refund for any orders associated with the seat being unenrolled, using the commerce service.
- Parameters:
course_enrollment (CourseEnrollment) – a student enrollment
change_mode (Boolean) – change the course mode to free mode or not
- Returns:
- A list of the external service’s IDs for any refunds that were initiated
(may be empty).
- Raises:
requests.exceptions.RequestException – for any unhandled HTTP error during communication with the E-Commerce Service.
requests.exceptions.Timeout – if the attempt to reach the commerce service timed out.