From bc67148de31ca67984a085dca90050210c4eadd3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 5 Dec 2023 15:54:03 +1300 Subject: [PATCH] Consolidate invoice determination --- CRM/Event/Form/Participant.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index fe384b1d26..73fac2784f 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -926,7 +926,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $this->_params = $this->prepareParamsForPaymentProcessor($this->_params); $this->_params['amount'] = $params['fee_amount']; $this->_params['amount_level'] = $params['amount_level']; - $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE)); // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the @@ -950,6 +949,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $paymentParams['fee_amount'] = NULL; $paymentParams['description'] = $this->getSourceText(); try { + $paymentParams['invoiceID'] = $this->getInvoiceID(); $result = $payment->doPayment($paymentParams); } catch (\Civi\Payment\Exception\PaymentProcessorException $e) { @@ -1520,7 +1520,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment 'total_amount' => $params['amount'], 'tax_amount' => $params['tax_amount'], 'amount_level' => $params['amount_level'], - 'invoice_id' => $params['invoiceID'], + 'invoice_id' => $this->getInvoiceID(), 'currency' => $this->getCurrency(), 'source' => $this->getSourceText(), 'is_pay_later' => FALSE, @@ -1992,4 +1992,14 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_ ]), $maxLength); } + /** + * @return string + */ + public function getInvoiceID(): string { + if (!$this->invoiceID) { + $this->invoiceID = md5(uniqid(rand(), TRUE)); + } + return $this->invoiceID; + } + } -- 2.25.1