Say I have two price fields, thumbtacks at $1/unit and ketchup at $20/unit (it's very good ketchup). Suppose they each have a different financial type, such as "Office" and "Condiments".
If I use the order api to create a contribution where you've bought one of each this looks fine. I get correct looking records in civicrm_line_item etc. The problem is when I record the payment. It properly records two items in civicrm_financial_item corresponding to the line items, but then in civicrm_entity_financial_trxn, it properly creates two records, but the entity_id for both of them points to the same entry in civicrm_financial_item. This then shows up in the UI on the contribution as "Condiments, Condiments" for the payment instead of "Office, Condiments".
When I record the same contribution from the start using the UI and the price set, it has entity_id pointing to the separate items, as I'd expect, and in the UI shows "Office, Condiments" for the payment.
The code looks something like this:
$result = civicrm_api3('Order', 'create', [ 'contact_id' => 17, 'financial_type_id' => 'Donation', // this seems irrelevant 'receive_date' => date('YmdHis'), 'contribution_status_id' => 'Pending', // this is required according to the docs - the payment below completes it 'line_items' => [ [ 'params' => , 'line_item' => [ [ 'label' => 'line 1', 'qty' => 1, 'unit_price' => '1', 'line_total' => '1', 'financial_type_id' => 22, // Office 'price_field_id' => 12, // this seems almost irrelevant - using "1" has the same effect but then oddly doesn't show the line item breakdown when viewing the contribution ], // It doesn't seem to make a difference if I put the 2nd line item here or as a separate array in the outer array. // It's the payment part that is creating the wrong entity_id. [ 'label' => 'line 2', 'qty' => 1, 'unit_price' => '20', 'line_total' => '20', 'financial_type_id' => 23, // Condiments 'price_field_id' => 13, ], ], ], ], 'api.Payment.create' => ['total_amount' => 21], ]);