Customizing the business flow for payment processing
If the business flow provided by payment rules does not meet your business needs, you can customize the business flow used for payment processing.
Procedure
Typical customization business scenarios
Many
sites use WebSphere
Commerce as
the order capture system. The order is fulfilled and managed by an
ERP, or order management system. The following list describes a typical
scenario:
- An order is captured by WebSphere Commerce. When the order is submitted, payment is authorized with order total amount. Then order is transferred to the external system.
- After the order is fulfilled by the external order management system, a shipment confirmation message is passed back to WebSphere Commerce to capture payment for the shipped order items in this package.
- At order submission, the ProcessOrderCmdImpl command calls PrimePaymentCmd to process payment since the order total amount needs to be processed. Customize the getInitialAmount() method of the ProcessOrderCmdImpl command to get the total amount of this order.
- When the shipment confirmation is received by WebSphere
Commerce, the
order related information is updated in the WebSphere
Commerce database.
The payment of order items to be shipped needs to be captured at this
phase.
- You should have a command to update order related information in WebSphere Commerce.
- In this command, call ReservePaymentCmd and FinalizePaymentCmd
to capture payment for this order to be shipped.
- Call ReservePaymentCmd to process the ReservePayment payment event
by using the following sample code.
In this sample code, shipmentList is a HashMap containing all order items to ship at this time, where the key is the shipment ID, and the value is the total amount of the shipment. For sites using the ATP inventory system, the shipment ID can be the release ID; for Non-ATP inventory, the shipment ID can be any identifier of this shipment. Also, dShipmentTotal is the total amount of those shipped order items previously of this order adding the total amount of order items to ship this time.ReservePaymentCmd cmd = (ReservePaymentCmd)CommandFactory.createCommand(ReservePaymentCmd.NAME,storeId); cmd.setCommandContext(getCommandContext()); cmd.setOrderId(ordersId); cmd.setReleases(shipmentList); cmd.setReservationAmount(dShipmentTotal); cmd.execute();
- Immediately after, FinalizePaymentCmd is called at the same caller
for each shipment, respectively by using the sample code as follows:
In this sample code, shipmentId corresponds to the identifier of this shipment used in the ReservePaymentCmd command above. Also, shipmentAmount is the total amount of this shipment.FinalizePaymentCmd cmd = (FinalizePaymentCmd) CommandFactory.createCommand(FinalizePaymentCmd.NAME, storeId); cmd.setOrderId(orderId); cmd.setReleaseId(shipmentId); cmd.setFinalizationAmount(shipmentAmount); cmd.setCommandContext(getCommandContext()); cmd.execute();
- Call ReservePaymentCmd to process the ReservePayment payment event
by using the following sample code.
- If you support multiple shipments
and perform payment deposits by shipment, there will be multiple payment
authorizations against one payment method. You can configure WebSphere
Commerce to select the appropriate payment against which to perform
the payment deposit action for the current shipment. This reduces
transactions, and may reduce unnecessary charges for use of the payment
network. To configure WebSphere Commerce to select payments for the
current shipment, register the implementation class of DetermineSortedPaymentsCmd,
which builds a relationship between shipments and payment actions. Register the DetermineSortedPaymentsCmdImpl task command using an SQL statement similar to the following example:
insert into REGCMD (STOREENT_ID,INTERFACENAME,CLASSNAME,TARGET,OPTCOUNTER) values(storeID,'com.ibm.commerce.payment.rules.commands.DetermineSortedPaymentsCmd', 'com.ibm.commerce.payment.rules.commands.DetermineSortedPaymentsCmdImpl', 'Local',0);