*/
public $_totalAmount;
+ /**
+ * Monetary fields that may be submitted.
+ *
+ * These should get a standardised format in the beginPostProcess function.
+ *
+ * These fields are common to many forms. Some may override this.
+ */
+ protected $submittableMoneyFields = ['total_amount', 'net_amount', 'non_deductible_amount', 'fee_amount', 'tax_amount', 'amount'];
+
/**
* Set variables up before form is built.
*/
$taxAmount = 0;
foreach ($this->_params as $k => $v) {
+ $this->cleanMoneyFields($v);
if ($v == 'skip') {
continue;
}
$now = date('YmdHis');
$this->_params = $this->get('params');
+ $this->cleanMoneyFields($this->_params);
+
if (!empty($this->_params[0]['contact_id'])) {
// unclear when this would be set & whether it could be checked in getContactID.
// perhaps it relates to when cid is in the url
}
$contribParams['skipLineItem'] = 1;
+ $contribParams['skipCleanMoney'] = 1;
// create contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams);
// CRM-11124
$_REQUEST['id'] = $form->_eventId = $params['id'];
$form->controller = new CRM_Event_Controller_Registration();
$form->_params = $params['params'];
- $form->_amount = $form->_totalAmount = CRM_Utils_Array::value('totalAmount', $params);
+ // This happens in buildQuickForm so emulate here.
+ $form->_amount = $form->_totalAmount = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('totalAmount', $params));
$form->set('params', $params['params']);
$form->_values['custom_pre_id'] = array();
$form->_values['custom_post_id'] = array();
return array();
}
+ /**
+ * Clean money fields from the form.
+ *
+ * @param array $params
+ */
+ protected function cleanMoneyFields(&$params) {
+ foreach ($this->submittableMoneyFields as $moneyField) {
+ foreach ($params as $index => $paramField) {
+ if (isset($paramField[$moneyField])) {
+ $params[$index][$moneyField] = CRM_Utils_Rule::cleanMoney($paramField[$moneyField]);
+ }
+ }
+ }
+ }
+
}
/**
* Initial test of submit function for paid event.
*
+ * @param string $thousandSeparator
+ *
+ * @dataProvider getThousandSeparators
+ *
* @throws \Exception
*/
- public function testPaidSubmit() {
+ public function testPaidSubmit($thousandSeparator) {
+ $this->setCurrencySeparators($thousandSeparator);
$paymentProcessorID = $this->processorCreate();
$params = array('is_monetary' => 1, 'financial_type_id' => 1);
$event = $this->eventCreate($params);
'contributeMode' => 'direct',
'registerByID' => $individualID,
'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID),
- 'totalAmount' => 800,
+ 'totalAmount' => $this->formatMoneyInput(8000.67),
'params' => array(
array(
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
- 'amount' => '800.00',
+ 'amount' => $this->formatMoneyInput(8000.67),
'tax_amount' => NULL,
'year' => '2019',
'month' => '1',
));
$this->callAPISuccessGetCount('Participant', array(), 1);
$contribution = $this->callAPISuccessGetSingle('Contribution', array());
+ $this->assertEquals(8000.67, $contribution['total_amount']);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',