An order’s component costs include its commerce item costs, shipping costs, and tax. You can assign these various costs to payment groups using the following methods:
- CommerceItemManager.addItemAmountToPaymentGroup()
- CommerceItemManager.addRemainingItemAmountToPaymentGroup()
- ShippingGroupManager.addShippingCostAmountToPaymentGroup()
- ShippingGroupManager.addRemainingShippingCostToPaymentGroup()
- OrderManager.addTaxAmountToPaymentGroup()
- OrderManager.addRemainingTaxAmountToPaymentGroup()
For example, suppose an Order has two commerce items, two payment groups, and one shipping group. The cost of the first item is $5.99, and the cost of the second item is $9.99. Both items are in the shipping group, and the shipping cost is $5.00. The tax for the order is $0.80. You might account for the order’s costs by doing the following:
- Call - addItemAmountToPaymentGroup()for the first item and pass 5.99 for the amount parameter to the first payment group.
- Call - addItemAmountToPaymentGroup()for the second item and pass 9.99 for the amount parameter to the second payment group.
- Call - addShippingCostAmountToPaymentGroup()for the shipping group and pass 5.00 for the amount parameter to the first payment group.
- Call - addTaxAmountToPaymentGroup()for the order’s tax and pass 0.80 for the amount parameter to the second payment group.- The order’s costs are now accounted for because the commerce item costs, shipping costs, and tax have all been assigned to a payment group. 
Accounting for Commerce Item Costs
If the CommerceItem costs of an Order are assigned to one or more payment groups, then during checkout the order’s CommerceItem costs are accounted for according to the following rules:
- If there is only one - PaymentGroupin the- Orderand no relationships exist between that- PaymentGroupand the commerce items in the- Order, then the cost of all commerce items in the- Orderimplicitly is accounted for by that- PaymentGroup.
- If there is only one - PaymentGroupin the- Orderand relationships exist between that- PaymentGroupand the commerce items in the- Order, or if there is more than one- PaymentGroupin the- Order, then every- CommerceItemin the- Ordermust have its costs explicitly accounted for with one or more- PaymentGroupCommerceItemRelationshipobjects, as follows:- If a - CommerceItemhas a- PaymentGroupCommerceItemRelationshipof type- PaymentAmountRemaining, then that relationship accounts for the cost of the- CommerceItemregardless of whether the- CommerceItemhas other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.- If a - CommerceItemhas one or more- PaymentGroupCommerceItemRelationshipobjects of type- PaymentAmount, but no- PaymentGroupCommerceItemRelationshipof type- PaymentAmountRemaining, then the total cost covered by all of the relationships must be equal to or greater than the total cost of the- CommerceItem.
Accounting for Shipping Costs
If the shipping costs of an Order are assigned to one or more payment groups, then during checkout the order’s shipping costs are accounted for according to the following rules:
- If there is only one - PaymentGroupin the- Orderand no relationships exist between that- PaymentGroupand the shipping groups in the- Order, then the shipping costs for the- Orderimplicitly are accounted for by that- PaymentGroup.
- If there is only one - PaymentGroupin the- Orderand relationships exist between that- PaymentGroupand the shipping groups in the- Order, or if there is more than one- PaymentGroupin the- Order, then every- ShippingGroupin the- Ordermust have its costs explicitly accounted for by one or more- PaymentGroupShippingGroupRelationshipobjects, as follows:- If a - ShippingGrouphas a- PaymentGroupShippingGroupRelationshipof type- ShippingAmountRemaining, then that relationship accounts for the cost of the- ShippingGroupregardless of whether the- ShippingGrouphas other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.- If a - ShippingGrouphas one or more- PaymentGroupShippingGroupRelationshipobjects of type- ShippingAmount, but no- PaymentGroupShippingGroupRelationshipof type- ShippingAmountRemaining, then the total cost covered by all of the relationships must be equal to or greater than the total cost of the- ShippingGroup.
Accounting for Tax
If the tax of an Order is assigned to one or more payment groups, then during checkout the order’s tax cost is accounted for according to the following rules:
- If the - Ordercontains a- PaymentGroupOrderRelationshipof type- TaxAmountRemaining, then the order’s tax cost is accounted for regardless of whether or not the- Orderhas other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.
- If the - Ordercontains one or more- PaymentGroupOrderRelationshipobjects of type- TaxAmount, then the sum of the amounts in the relationships must be equal to or greater than the total tax amount of the- Orderto account for tax payment.

