From e29f06d27791fe9deee5136cf2f07f662d487b37 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 4 Dec 2023 14:00:37 +1300 Subject: [PATCH] Clean up payment create --- CRM/Contribute/Form/AdditionalPayment.php | 53 ++++++++++------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 7a707d09f2..912deb2844 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -313,25 +313,28 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $this->_params = $submittedValues; $this->beginPostProcess(); $this->processBillingAddress($this->_contactID, (string) $this->_contributorEmail); - $participantId = NULL; - if ($this->_component === 'event') { - $participantId = $this->_id; - } - + $paymentResult = []; if ($this->_mode) { // process credit card - $this->processCreditCard(); - } - - // @todo we should clean $ on the form & pass in skipCleanMoney - $trxnsData = $this->_params; - if ($this->isARefund()) { - $trxnsData['total_amount'] = -$trxnsData['total_amount']; - } - $trxnsData['participant_id'] = $participantId; - $trxnsData['contribution_id'] = $this->_contributionId; - // From the - $trxnsData['is_send_contribution_notification'] = FALSE; + $paymentResult = $this->processCreditCard(); + } + + $totalAmount = $this->getSubmittedValue('total_amount'); + $trxnsData = [ + 'total_amount' => $this->isARefund() ? -$totalAmount : $totalAmount, + 'check_number' => $this->getSubmittedValue('check_number'), + 'fee_amount' => $paymentResult['fee_amount'] ?? 0, + 'contribution_id' => $this->getContributionID(), + 'payment_processor_id' => $this->getPaymentProcessorID(), + 'card_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $this->getSubmittedValue('credit_card_type')), + 'pan_truncation' => substr($this->getSubmittedValue('credit_card_number'), -4), + 'trxn_result_code' => $paymentResult['trxn_result_code'] ?? NULL, + 'payment_instrument_id' => $this->getSubmittedValue('payment_instrument_id'), + 'trxn_id' => $paymentResult['trxn_id'] ?? NULL, + 'trxn_date' => $this->getSubmittedValue('trxn_date'), + // This form sends payment notification only, for historical reasons. + 'is_send_contribution_notification' => FALSE, + ]; $paymentID = civicrm_api3('Payment', 'create', $trxnsData)['id']; if ($this->getContributionID() && CRM_Core_Permission::access('CiviMember')) { @@ -360,23 +363,12 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract } public function processCreditCard(): ?array { - $config = CRM_Core_Config::singleton(); - $session = CRM_Core_Session::singleton(); - // we need to retrieve email address if ($this->_context === 'standalone' && !empty($this->_params['is_email_receipt'])) { [$displayName] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId); $this->assign('displayName', $displayName); } - $this->_params['amount'] = $this->_params['total_amount']; - // @todo - stop setting amount level in this function - use $this->order->getAmountLevel() - $this->_params['amount_level'] = 0; - $this->_params['currencyID'] = CRM_Utils_Array::value('currency', - $this->_params, - $config->defaultCurrency - ); - if (empty($this->_params['invoice_id'])) { $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE)); } @@ -394,7 +386,9 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract // so we copy stuff over to first_name etc. $paymentParams = $this->_params; $paymentParams['contactID'] = $this->_contactId; - CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE); + $paymentParams['amount'] = $this->getSubmittedValue('total_amount'); + $paymentParams['currency'] = $this->getCurrency(); + CRM_Core_Payment_Form::mapParams($this->_bltID, $this->getSubmittedValues(), $paymentParams, TRUE); $paymentParams['contributionPageID'] = NULL; if (!empty($this->_params['is_email_receipt'])) { @@ -419,7 +413,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract CRM_Core_Error::statusBounce($e->getMessage(), CRM_Utils_System::url('civicrm/payment/add', $urlParams)); } } - if (!empty($result)) { $this->_params = array_merge($this->_params, $result); } -- 2.25.1