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
PaymentGroup
in theOrder
and no relationships exist between thatPaymentGroup
and the commerce items in theOrder
, then the cost of all commerce items in theOrder
implicitly is accounted for by thatPaymentGroup
.If there is only one
PaymentGroup
in theOrder
and relationships exist between thatPaymentGroup
and the commerce items in theOrder
, or if there is more than onePaymentGroup
in theOrder
, then everyCommerceItem
in theOrder
must have its costs explicitly accounted for with one or morePaymentGroupCommerceItemRelationship
objects, as follows:If a
CommerceItem
has aPaymentGroupCommerceItemRelationship
of typePaymentAmountRemaining
, then that relationship accounts for the cost of theCommerceItem
regardless of whether theCommerceItem
has other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.If a
CommerceItem
has one or morePaymentGroupCommerceItemRelationship
objects of typePaymentAmount
, but noPaymentGroupCommerceItemRelationship
of 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
PaymentGroup
in theOrder
and no relationships exist between thatPaymentGroup
and the shipping groups in theOrder
, then the shipping costs for theOrder
implicitly are accounted for by thatPaymentGroup
.If there is only one
PaymentGroup
in theOrder
and relationships exist between thatPaymentGroup
and the shipping groups in theOrder
, or if there is more than onePaymentGroup
in theOrder
, then everyShippingGroup
in theOrder
must have its costs explicitly accounted for by one or morePaymentGroupShippingGroupRelationship
objects, as follows:If a
ShippingGroup
has aPaymentGroupShippingGroupRelationship
of typeShippingAmountRemaining
, then that relationship accounts for the cost of theShippingGroup
regardless of whether theShippingGroup
has other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.If a
ShippingGroup
has one or morePaymentGroupShippingGroupRelationship
objects of typeShippingAmount
, but noPaymentGroupShippingGroupRelationship
of 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
Order
contains aPaymentGroupOrderRelationship
of typeTaxAmountRemaining
, then the order’s tax cost is accounted for regardless of whether or not theOrder
has other payment relationships. This is because a “remaining” relationship covers everything not accounted for by other payment relationships.If the
Order
contains one or morePaymentGroupOrderRelationship
objects of typeTaxAmount
, then the sum of the amounts in the relationships must be equal to or greater than the total tax amount of theOrder
to account for tax payment.