django_program.registration.services.checkout

Checkout service for converting carts into orders.

Handles the atomic checkout flow, credit application, and order cancellation. All methods are stateless and operate on model instances directly.

Classes

CheckoutService

Stateless service for checkout operations.

class django_program.registration.services.checkout.CheckoutService[source]

Bases: object

Stateless service for checkout operations.

Converts carts into orders, applies credits, and handles cancellations.

static checkout(cart, *, billing_name='', billing_email='', billing_company='')[source]

Convert a cart into an order atomically.

Re-validates stock, pricing, and voucher validity at checkout time to prevent stale-cart issues. Creates an Order with PENDING status, snapshots each CartItem into OrderLineItems, records voucher details, and marks the cart as CHECKED_OUT.

Parameters:
  • cart (Cart) – The open cart to check out.

  • billing_name (str) – Customer billing name.

  • billing_email (str) – Customer billing email.

  • billing_company (str) – Customer billing company.

Return type:

Order

Returns:

The newly created Order with PENDING status.

Raises:

ValidationError – If the cart is empty, expired, not open, or if stock/price validation fails at checkout time.

static apply_credit(order, credit)[source]

Apply a store credit to an order.

Creates a CREDIT payment record and marks the credit as APPLIED. If the credit covers the full remaining balance, transitions the order to PAID and fires the order_paid signal.

Parameters:
  • order (Order) – The order to apply the credit to.

  • credit (Credit) – The available credit to apply.

Return type:

Payment

Returns:

The created Payment record.

Raises:

ValidationError – If the order is not PENDING, the credit is not AVAILABLE, or the credit belongs to a different conference/user.

static cancel_order(order)[source]

Cancel a pending order and release associated resources.

Reverses any succeeded credit payments (restoring the Credit to AVAILABLE), transitions the order to CANCELLED, and decrements the voucher usage counter if a voucher was used.

Parameters:

order (Order) – The order to cancel.

Return type:

Order

Returns:

The updated Order with CANCELLED status.

Raises:

ValidationError – If the order cannot be cancelled (not PENDING).