Requesting a Policy in Financial Services Accelerator
A Policy request is created at the end of a checkout process. It gathers all the information provided by a customer and describes a policy range.
Requesting a Policy
Once the customer has completed all of the checkout steps and provided all the information needed to purchase a policy, the Final Review page is displayed and this is the point when the policy request is created.
Requesting an insurance policy is the equivalent of purchasing an item in standard e-commerce process flow. It occurs when the payment is approved and the customer has confirmed a will to purchase the policy. The policy request has been implemented so that it is part of a standard Place an Order phase of the checkout flow. Throughout the checkout process, the details of the insurance quote are stored in a Quote object which itself is an attribute of the Cart component. Once an order is created, the standard PlaceOrder process is initiated. The first step performed is to create an Order object by cloning the Cart object. As part of this cloning, the Quote object is carried over onto the new Order object which means that the details held in the Quote can be used to create the Policy object.
The actual placeOrder() method performs a number of steps and is designed to be extended for flexibility. The CommerceCheckoutService contains a component which implements the CommercePlaceOrderStrategy interface. This contains a placeOrder() method which is the method involved in actually creating an OrderModel from the CartModel. This involves a number of stages and, in order to keep this process extensible, the default implementing class which is DefaultCommercePlaceOrderStrategy contains methods that use a number of CommercePlaceOrderMethodHook components to implement any customizations when placing the order. Both the DefaultCommercePlaceOrderStrategy and the CommercePlaceOrderMethodHook components have the following methods available :
- beforePlaceOrder()
- beforeSubmitOrder()
- afterPlaceOrder()
Each of these methods in the DefaultCommercePlaceOrderStrategy calls the corresponding method in any wired CommercePlaceOrderMethodHook components. The beforePlaceOrder() method is called before any models are created by the service layer. The beforeSubmitOrder() method is called once the order model has been created and populated with the cart information, the payment information, any promotions and any applicable tax. Once this has successfully been processed, the afterPlaceOrder() is called immediately before the results are passed back from the placeOrder() method.
The actual OrderModel is generated by the createOrderFromCart() method in the OrderService. As both the Cart and the Order objects are derived from the AbstractOrder class, the generation of the OrderModel is practically a clone of the cart model so that all of the details that are defined in the cart at abstract order level are copied into the resulting order. As the InsuranceQuote is an attribute of the AbstractOrder object, the new OrderModel is generated with a copy of the InsuranceQuote object that was constructed on the cart during the checkout phase. This means that when it is time to create the InsurancePolicy, all of the Quote details are available.
The creation of the InsurancePolicy is handled in the submitOrder() method of the OrderService which is called from the placeOrder() method in the PlaceOrderStrategy component. The DefaultOrderService class has a list of possible SubmitOrderStrategy components and the submitOrder() method iterates over this list and calls each registered object's submitOrder() method. There is a PolicyCreationSubmitOrderStrategy component which is registered with the OrderSerivce component which is used to create the InsurancePolicy by in turn calling the requestPolicyCreation() method on it's registered PolicyServiceFacade. This method copies the appropriate information across from the quote and is responsible for any other integrations to create the InsurancePolicy object. As part of this process, the URL for the generated PDF document of the policy is generated, so that it can be permanently stored on the InsurancePolicy object. This is handled by a registered PolicyPdfUrlGenerator components wired into the PolicyServiceFacade.
The last step when generating an order is to invoke the clearSessionTaxDocument method on the registered ExternalTaxService to ensure that any tax document held in the current session used to generate tax on an order is removed, so that any subsequent tax calculations are made with a new and more appropriate tax document.
Class diagram
The diagram below describes the relationship between the various classes used when generating a policy. It shows both the interfaces and the implementing classes for the various components. Usually, the implementation class for an interface is Default + {interface name}, but certain implementations are for specific tasks. For instance, the SubmitOrderStrategy has an implementation that is specific for creating insurance policies in the PolicyCreationSubmitOrderStrategy. The diagram does not show all members and methods - just those that are significant for the policy requesting process flow.