Consolidate invoice determination
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 5 Dec 2023 02:54:03 +0000 (15:54 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 5 Dec 2023 02:54:03 +0000 (15:54 +1300)
CRM/Event/Form/Participant.php

index fe384b1d26fc442e6737a306a86fb2986484c92d..73fac2784f226b110ead9c6c9eb02e78019091fa 100644 (file)
@@ -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;
+  }
+
 }