Assigning Costs to Payment Groups

When an Order is first created, it has an empty PaymentGroup, which serves as the default PaymentGroup for the Order. The type of default PaymentGroup that is created is determined by the defaultPaymentGroupType property of the OrderTools component. By default, this property is set to CreditCard.

When a CommerceItem is added to the Order, that item is automatically a part of the default PaymentGroup because it is assumed that when there is only one PaymentGroup, all CommerceItem costs – along with all shipping and tax costs -- are a part of that group. However, once a second PaymentGroup is added to the Order, the existing CommerceItem, any new commerce items, and all shipping and tax costs must be explicitly assigned to one of the two payment groups; any items that were in the default PaymentGroup are no longer a part of any PaymentGroup.

Before the Order is checked out, all of the order’s costs must be a part of a PaymentGroup. This requirement is checked during the checkout process by the validateForCheckout pipeline, which is executed by the processOrder pipeline. Each processor in the validateForCheckout pipeline validates a different part of the Order as complete. The payment groups in the Order are considered complete if the following criteria are met:

None of the required fields (name, address, city, state, and postal code) are empty in any PaymentGroup.

All of the costs associated with the Order, which include the commerce item costs, shipping costs, and tax, are accounted for by one or more payment groups.

If the Order has only one payment group, then the assignment of Order costs is automatic. However, if the Order has more than one payment group, you must explicitly assign the Order costs to the payment groups. You can do so using one of following methods:

Assign the total cost of the Order to one or more payment groups. This approach is more frequently used, and it is the most straightforward way to account for an order’s payment because you are dealing with the Order costs as a whole. See Assigning an Order’s Total Cost to Payment Groups.

Assign the component costs of the Order -- the commerce item costs, shipping costs, and tax -- to one or more payment groups. You should use this method if you need more control over where to assign the component costs of an Order. See Assigning an Order’s Component Costs to Payment Groups.

For more information on the processOrder and validateForCheckout pipelines, see the Checking Out an Order section of the Configuring Purchase Process Services chapter. For information on the PaymentGroupCommerceItemRelationship and PaymentGroupShippingGroupRelationship objects that are described in the following subsections, see the Relationship Types section in this chapter.