Payment in the fulfillment framework can be handled in two ways. The value of OrderFulfiller.settleOnFirstShipment
determines how payment is handled:
If
settleOnFirstShipment
is true, all of the payment groups are settled after the first shipping group ships.If
settleOnFirstShipment
is false, all of the payment groups are settled after the last shipping group ships.
You can also configure the fulfillment framework to charge each shipping group to a different credit card at the time of shipment. There are two methods in the system that can be overwritten to facilitate this behavior:
OrderFulfillmentTools.isOrderSettleable
This method is called each time the
OrderFulfiller
is notified that a shipping group has been shipped. (This notification occurs through aModifyOrderNotification
message that contains aGenericUpdate
on the state of the shipping group. The new value isPENDING_SHIPMENT
.)After the
OrderFulfiller
receives the notification, it callsOrderFulfillmentTools.isOrderSettleable
. If this method returns true, thenOrderFulfiller.settleOrder
is called. To configure the fulfillment framework to charge each shipping group to a different credit card at the time of shipment, have this method check if there is aPaymentGroup
specific to this shipping group. If there is, return true. It should also return true if allShippingGroups
have shipped.OrderFulfiller.settleOrder
By default, this method settles all
PaymentGroups
in the order. To pay for each shipping group as it ships, this method should settle eachPaymentGroup
that is notSETTLED
and refers to aShippingGroup
that has shipped.This method should also check if all shipping groups have shipped. If they have, than any other
PaymentGroups
that have not settled, should be settled. Settling aPaymentGroup
most likely will involve using thePaymentManager
.
To facilitate payment by shipping group as each shipping group is shipped, your system must create the appropriate PaymentGroupRelationship
objects. To pay for each shipping group separately (and the items that appear in each shipping group), you will probably create each of these PaymentGroupRelationship
objects yourself. When a user creates an order, the default behavior is for the order to include one PaymentGroup
with one PaymentGroupOrderRelationship
that accounts for the cost of the entire order. You might want to create a PaymentGroupCommerceItemRelationship
for each item in the order, and a PaymentGroupShippingGroupRelationship
for each shipping group in the order. It depends on your business rules.
For more information on payment groups, see the Creating Payment Groups section. For more information on the payment manager, see the Processing Payment of Orders section.