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 theOrderand no relationships exist between thatPaymentGroupand the commerce items in theOrder, then the cost of all commerce items in theOrderimplicitly is accounted for by thatPaymentGroup.If there is only one
PaymentGroupin theOrderand relationships exist between thatPaymentGroupand the commerce items in theOrder, or if there is more than onePaymentGroupin theOrder, then everyCommerceItemin theOrdermust have its costs explicitly accounted for with one or morePaymentGroupCommerceItemRelationshipobjects, as follows:If a
CommerceItemhas aPaymentGroupCommerceItemRelationshipof typePaymentAmountRemaining, then that relationship accounts for the cost of theCommerceItemregardless of whether theCommerceItemhas other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.If a
CommerceItemhas one or morePaymentGroupCommerceItemRelationshipobjects of typePaymentAmount, but noPaymentGroupCommerceItemRelationshipof typePaymentAmountRemaining, then the total cost covered by all of the relationships must be equal to or greater than the total cost of theCommerceItem.
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 theOrderand no relationships exist between thatPaymentGroupand the shipping groups in theOrder, then the shipping costs for theOrderimplicitly are accounted for by thatPaymentGroup.If there is only one
PaymentGroupin theOrderand relationships exist between thatPaymentGroupand the shipping groups in theOrder, or if there is more than onePaymentGroupin theOrder, then everyShippingGroupin theOrdermust have its costs explicitly accounted for by one or morePaymentGroupShippingGroupRelationshipobjects, as follows:If a
ShippingGrouphas aPaymentGroupShippingGroupRelationshipof typeShippingAmountRemaining, then that relationship accounts for the cost of theShippingGroupregardless of whether theShippingGrouphas other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.If a
ShippingGrouphas one or morePaymentGroupShippingGroupRelationshipobjects of typeShippingAmount, but noPaymentGroupShippingGroupRelationshipof typeShippingAmountRemaining, then the total cost covered by all of the relationships must be equal to or greater than the total cost of theShippingGroup.
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 aPaymentGroupOrderRelationshipof typeTaxAmountRemaining, then the order’s tax cost is accounted for regardless of whether or not theOrderhas other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.If the
Ordercontains one or morePaymentGroupOrderRelationshipobjects of typeTaxAmount, then the sum of the amounts in the relationships must be equal to or greater than the total tax amount of theOrderto account for tax payment.

