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
-
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.
-
Order Creation:
create_order()
: Creates a new order in the system.
-
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.
-
Payment Processing:
process_order_to_paid(order_id)
: Marks an order as paid and captures a snapshot of the cart's details.
Example Workflow
-
Create a Payment Attempt:
-
Update Payment Attempt Status:
-
Retrieve an Unpaid Order:
-
Mark Order as Paid:
-
Retrieve Orders for a User:
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.