Order Management module
Learn more about the Order Management module.
The OrderManagement
module keeps the Digital River orders and WooCommerce orders in sync by managing the state of the orders.
Specifications
This module is responsible for handling different order lifecycle states. It will also enable users to download and view order invoices for their purchases.
Order Management methods
Order Manager class
This class is the module's entry point.
Method
Args, Returns, and Descriptions
__construct
Arg: ApiInstance
$api_instanceOrderContainer
$container
Return: string
Description: Constructs the object by passing its dependencies
name
Arg: -
Return: string
Description: Returns the name of the module
init
Arg: -
Return: void
Description: Initializes the module, register necessary hooks, and initialize StateManager
create
Arg: int $order_id
Return: void
Description: Syncs the WC_Order
with id $order_id
to digitalriver
, and stores the digitalriver
order details in the WC_Order
metadata
get
Arg: String $order_id
Return: Order
/null
Description: Gets a digitalriver Order
whose ID is $order_id
, return null
if no match found
is_dr_order
Arg: WC_Order
$order/int $order_id
Return: bool
Description: Checks if a WooCommerce order has a digitalriver
order associated with it
checkout_id
Arg: int $order_id
Return: string
Description: Returns the ID of the checkout corresponding to the order which has its ID $order_id
Order Container class
This class acts as a Dependency Injection container for providing dependencies to classes present in the OrderManagement
module.
Method
Args, Returns, and Descriptions
__construct
Arg: PimpleContainer
Return: void
Description: Accepts a Dependency Injection container as an argument and assigns it to a container attribute
define_services
Arg: -
Return: void
Description: Defines all the classes present within the module
get
Arg: String $service_name
Return: object
Description: Retrieves a service from the container
State Manager class
This class updates the WC_Order
status to reflect the corresponding Digital River order status.
Method
Args, Returns, and Descriptions
__construct
Arg: OrderManager
$order_manager
Return: void
Description: Stores the OrderManager
object as a property
init
Arg: -
Return: void
Description: Initializes the object and register necessary hooks
statuses
Arg: array $order_statuses
Return: array
Description: Add statuses to the WC_Order
register_statuses
Arg: array $statuses
Return: array
Description: Add statuses to the WC_Order
transit
Arg: String $event, array $event_data
Return: void
Description: Usesstatuses()
as a method to register custom WooCommerce order statuses
handle_status_transition
Arg: int $order_id, string $status_from, string $status_to, \WC_Order $order
Return: void
Description: Handles status change for an order and is useful for a cancellation and refund
Fulfiller class
This class handles automatic order fulfillment.
Method
Args, Returns, and Descriptions
__construct
Arg: OrderManager
$order_manager
Return: void
Description: Constructs the object by passing its dependencies
init
Arg: -
Return: void
Description: Registers necessary hooks if Automatic fulfillment
is enabled
order
Arg: WC_Product
Return: void
Description: Updates the $order
attribute
fulfill
Arg: int $order_id, string $status_from, String $status_to, WC_Order
$order
Return: void
Description: Fulfills the order by calling the Digital River fulfillment API
prepare_items
Arg: array $items
Return: array
Description: Prepares items before passing them to the Digital River fulfillment API
Invoice Manager class
This class manages order invoices.
Method
Args, Returns, and Descriptions
__construct
Arg: OrderManager
$order_manager
Return: void
Description: Constructs the object by passing its dependencies
init
Arg: -
Return: void
Description: Initializes the object and registers necessary hooks
associate_invoice
Arg: Order
$order
Return: void
Description: Associates invoice file ID to WooCommerce Order
invoice_event
Arg: string $event_name, array $event_data
Return: void
Description: Handles an invoice created from digitalriver
download_invoice_action
Arg: array $actions, WC_Orde
r $order
Return: array
Description: Adds a Download Invoice
call to action under My Account > Orders
download_invoice
Arg: -
Return: void
Description: Gets the invoice file link and redirects to it
State Transition Handler Classes
These three Handler classes are responsible for the order state transition.
Class
Description
Fulfiller
This Handler is responsible for fulfilling orders. It calls Digital River API for fulfillment so that the order can be fulfilled and eventually be completed.
Canceller
This Handler is responsible for order cancellation. An order can only be cancelled if it is in Ready for fulfilment
state in WooCommerce.
Note: The order can only be cancelled as a whole, no partial cancellation is available.
RequestRefund
This Handler is responsible for order reversal. The refund can be generated only by the store admin by selecting Request refund
status in WooCommerce.
Note: Only completed orders can be refunded. The refund will be performed on order-level, line-item or partial refunds are not available.
State transition classes must implement the StateTransition
interface. Optionally, they can also extend theBaseTransition
class.
State Transition Interface
Method
Args, Returns, and Descriptions
valid
Arg: string $status_to, string $status_from, \WC_Order $order
Return: bool
Description: Checks if the current transition is valid or not
transit
Arg: WC_Order $order
Return: void
Description: Performs any in-transition activity such as calling Digital River API
Last updated