BOB Docs
APIApplicationStore

OrderService

Key Features

  • Order Management: Handles the creation and retrieval of orders for users and anonymous users.
  • Payment Tracking: Manages payment attempts and tracks their statuses.
  • Payment Integration: Processes orders for payment and integrates with external payment providers.
  • Ownership Validation: Ensures that orders can only be accessed by their rightful owners.
  • Detailed Order Summaries: Captures a snapshot of cart details during the payment process, ensuring accurate tracking of purchased items.

Methods

  1. Order Retrieval:

    • get_order_to_pay(order_id): Fetches an unpaid order with all required details for payment processing.
    • get_user_order(user_or_anonymous_user_id, order_id): Retrieves an order while validating ownership.
    • get_anonymous_user_orders(user_id, page, page_size): Retrieves all orders for an anonymous user.
    • get_user_orders(user_id, page, page_size): Retrieves all orders for a logged-in user.
  2. Order Creation:

    • create_order(): Creates a new order in the system.
  3. Payment Attempts:

    • attempt_to_pay_for_order(order_id): Creates a payment attempt for an order and returns the external payment session ID.
    • update_attempt_to_pay(attempt_external_id, status, total_amount, currency): Updates the status of a payment attempt and processes the order if payment is successful.
  4. Payment Processing:

    • process_order_to_paid(order_id): Marks an order as paid and captures a snapshot of the cart's details.

Example Workflow

  1. Create a Payment Attempt:

    external_id = await order_service.attempt_to_pay_for_order(order_id=123)
  2. Update Payment Attempt Status:

    success, processed_order = await order_service.update_attempt_to_pay(
        attempt_external_id="ext123",
        status=PaymentAttemptStatus.PAID,
        total_amount=1000,
        currency="USD"
    )
  3. Retrieve an Unpaid Order:

    order = await order_service.get_order_to_pay(order_id=123)
  4. Mark Order as Paid:

    paid_order = await order_service.process_order_to_paid(order_id=123)
  5. Retrieve Orders for a User:

    user_orders = await order_service.get_user_orders(user_id="user123", page=1, page_size=10)

Dependencies

  • Repositories Used:
    • OrderRepository: Manages database operations for orders.
    • OrderPaymentAttemptRepository: Handles database operations for payment attempts.

Notes

The OrderService ensures secure and efficient order processing by enforcing ownership validation and providing clear APIs for payment and retrieval. It integrates tightly with payment systems, capturing detailed order summaries and enabling robust tracking of transactions.

Benefits

  • Secure Processing: Enforces ownership validation to prevent unauthorized access.
  • Seamless Integration: Tightly integrates with payment systems for real-time order management.
  • Robust Tracking: Captures and maintains detailed order and payment records.

On this page