// if entity is pledge then build pledge param
if ($entity === 'pledge') {
$paymentParams += $entityParams;
+ // Pledges are not stored as entity_id in the line_item table.
+ CRM_Core_Error::deprecatedWarning('This should be unreachable & tests show it is never tested.');
+ civicrm_api3('PledgePayment', 'create', $paymentParams);
}
- elseif ($entity === 'membership') {
- $paymentParams['isSkipLineItem'] = TRUE;
+ if ($entity === 'participant') {
+ civicrm_api3('ParticipantPayment', 'create', $paymentParams);
}
- civicrm_api3($entity . '_payment', 'create', $paymentParams);
+
}
}
return civicrm_api3_create_success($contribution['values'] ?? [], $params, 'Order', 'create');
foreach ($contributions as $contribution) {
$lineItems = $this->callAPISuccess('LineItem', 'get', [
'contribution_id' => $contribution['id'],
- 'return' => ['tax_amount', 'line_total'],
+ 'return' => ['tax_amount', 'line_total', 'entity_table', 'entity_id'],
])['values'];
$total = 0;
$taxTotal = 0;
+ $memberships = [];
+ $participants = [];
foreach ($lineItems as $lineItem) {
$total += $lineItem['line_total'];
$taxTotal += (float) ($lineItem['tax_amount'] ?? 0);
+ if ($lineItem['entity_table'] === 'civicrm_membership') {
+ $memberships[] = $lineItem['entity_id'];
+ }
+ if ($lineItem['entity_table'] === 'civicrm_participant') {
+ $participants[] = $lineItem['entity_id'];
+ }
+ }
+ $membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', ['contribution_id' => $contribution['id'], 'return' => 'membership_id'])['values'];
+ $participantPayments = $this->callAPISuccess('ParticipantPayment', 'get', ['contribution_id' => $contribution['id'], 'return' => 'participant_id'])['values'];
+ $this->assertCount(count($memberships), $membershipPayments);
+ // @todo not working yet.
+ // $this->assertCount(count($participants), $participantPayments);
+ foreach ($membershipPayments as $payment) {
+ $this->assertContains($payment['membership_id'], $memberships);
}
$this->assertEquals($taxTotal, (float) ($contribution['tax_amount'] ?? 0));
$this->assertEquals($total + $taxTotal, $contribution['total_amount']);