From 9cd8bfb0ee1fda683ed5b6443dd7832c90a677a6 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 24 Jul 2023 15:11:20 +0100 Subject: [PATCH] Fix missing financial_account_id for recurring contributions --- src/WebformCivicrmPostProcess.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/WebformCivicrmPostProcess.php b/src/WebformCivicrmPostProcess.php index ad47688df..fabed4904 100644 --- a/src/WebformCivicrmPostProcess.php +++ b/src/WebformCivicrmPostProcess.php @@ -2340,10 +2340,9 @@ private function processContribution() { if (empty($item['contribution_id'])) { $item['contribution_id'] = $id; } - $priceSetId = 'default_contribution_amount'; + // Membership if (!empty($item['membership_id'])) { - $priceSetId = 'default_membership_type_amount'; $item['entity_id'] = $item['membership_id']; $lineItemArray = $this->utils->wf_civicrm_api('LineItem', 'get', [ 'entity_table' => "civicrm_membership", @@ -2359,13 +2358,19 @@ private function processContribution() { if (!isset($firstLineItem['contribution_id'])) { $item['id'] = $firstLineItem['id']; } + $item['price_field_id'] = $firstLineItem['price_field_id']; + $item['price_field_value_id'] = $firstLineItem['price_field_value_id']; } } - $item['price_field_id'] = $this->utils->wf_civicrm_api('PriceField', 'get', [ - 'sequential' => 1, - 'price_set_id' => $priceSetId, - 'options' => ['limit' => 1], - ])['id'] ?? NULL; + if (!isset($item['price_field_id'])) { + $priceFieldParams['where'][] = ['name', '=', 'contribution_amount']; + $priceFieldParams['where'][] = ['price_set_id.name', '=', 'default_contribution_amount']; + $item['price_field_id'] = $this->utils->wf_civicrm_api4('PriceField', 'get', $priceFieldParams, 0)['id']; + + $priceFieldParams['where'][] = ['name', '=', 'contribution_amount']; + $priceFieldParams['where'][] = ['price_field_id', '=', $item['price_field_id']]; + $item['price_field_value_id'] = $this->utils->wf_civicrm_api4('PriceField', 'get', $priceFieldParams, 0)['id']; + } // Save the line_item $line_result = $this->utils->wf_civicrm_api('line_item', 'create', $item);