Order API Throw an error when adding tax amount on line items
Order API not factoring in tax amounts when comparing against contribution total.
Overview: When creating an Order using Order API a check is done to compare Contribution's total_amount against the sum of line item's line_total's. If Contribution total amount and Line Items' total are not equal, Order creation will fail.
As we know:
- The line item line_total do not include any tax. Tax will be recorded separately in line item tax_amount field.
- The contribution total_amount do include tax. A separate contribution tax_amount field also records the amount of tax.
Since the validation only compares the sum of line_totals with contribution total_amount, whenever there is tax, the validation will fail.
For illustration consider following data set that should create 1 contribution with 2 line items for memberships.
order_data =
{
'is_pay_later': True,
'contact_id': 240L,
'payment_instrument_id': 6,
'line_items': [{
'line_item': {
'42': {
'price_field_value_id': 60L,
'price_field_id': 36L,
'entity_id': 1249L,
'tax_amount': 2.0,
'line_total': 10.0,
'financial_type_id': 2,
'label': 'General',
'entity_table': 'civicrm_membership',
'unit_price': 10,
'qty': '1'}}}, {
'line_item': {
'43': {
'price_field_value_id': 61L,
'price_field_id': 37L,
'entity_id': 1248L,
'tax_amount': 1.67,
'line_total': 8.33,
'financial_type_id': 2,
'label': 'Concession',
'entity_table': 'civicrm_membership',
'unit_price': '8.33',
'qty': '1'}}}],
'tax_amount': 3.67,
'total_amount': 22.0,
'contribution_recur_id': 605L,
'financial_type_id': 2,
'fee_amount': 0,
'payment_processor_id': 5L,
'receive_date': u'2019-08-01',
'contribution_status_id': 2}
Current situation: Calling the Order API to create Order with given data results with "Line item total doesn't match with total amount". This is because total_amount (22.0) <> sum of line_totals (18.33)
How should it be: The Line Items check should consider tax_amounts of line_items and order creation should succeed.