class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_ContributionBase {
/**
- * the id of the contact associated with this contribution
+ * The id of the contact associated with this contribution
*
* @var int
* @public
*
* @param array $params
* @param integer $contactID
- * @param $financialTypeID
+ * @param int $financialTypeID
* @param $online
- * @param $contributionPageId
+ * @param int $contributionPageId
* @param $nonDeductibleAmount
- * @param $campaignId
- *
+ * @param int $campaignId
* @param $isMonetary
- *
* @param $pending
* @param $paymentProcessorOutcome
* @param $receiptDate
- *
- * @param $recurringContributionID
+ * @param int $recurringContributionID
* @param $isTest
+ * @param int $addressID
+ * @param int $softCreditToID
+ * @param array $lineItems
*
- * @param $addressID
- *
- * @param $softCreditToID
- *
- * @param $lineItems
- *
- * @internal param $financialType
* @return array
*/
public static function getContributionParams($params, $contactID, $financialTypeID, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending,
'receive_date' => (CRM_Utils_Array::value('receive_date', $params)) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'),
'non_deductible_amount' => $nonDeductibleAmount,
'total_amount' => $params['amount'],
+ 'tax_amount' => CRM_Utils_Array::value('tax_amount', $params),
'amount_level' => CRM_Utils_Array::value('amount_level', $params),
'invoice_id' => $params['invoiceID'],
'currency' => $params['currencyID'],
$contributionParams['payment_instrument_id'] = 1;
}
}
+ if ($paymentProcessorOutcome) {
+ $contributionParams['payment_processor'] = CRM_Utils_Array::value('payment_processor', $paymentProcessorOutcome);
+ }
if (!$pending && $paymentProcessorOutcome) {
$contributionParams += array(
'fee_amount' => CRM_Utils_Array::value('fee_amount', $paymentProcessorOutcome),
'receipt_date' => $receiptDate,
// also add financial_trxn details as part of fix for CRM-4724
'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $paymentProcessorOutcome),
- 'payment_processor' => CRM_Utils_Array::value('payment_processor', $paymentProcessorOutcome),
);
}
}
/**
- * Function to set variables up before form is built
+ * Set variables up before form is built
*
* @return void
* @access public
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $this->get('amount');
+ $this->_params['tax_amount'] = $this->get('tax_amount');
$this->_useForMember = $this->get('useForMember');
}
/**
- * Function to actually build the form
+ * Build the form object
*
* @return void
* @access public
$amount_block_is_active = $this->get('amount_block_is_active');
$this->assign('amount_block_is_active', $amount_block_is_active);
+ $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,'contribution_invoice_settings');
+ $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
+ if ($invoicing) {
+ $getTaxDetails = FALSE;
+ $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
+ foreach ($this->_lineItem as $key => $value) {
+ foreach ($value as $v) {
+ if (isset($v['tax_rate'])) {
+ if ($v['tax_rate'] != '') {
+ $getTaxDetails = TRUE;
+ }
+ }
+ }
+ }
+ $this->assign('getTaxDetails', $getTaxDetails);
+ $this->assign('taxTerm', $taxTerm);
+ $this->assign('totalTaxAmount', $params['tax_amount']);
+ }
if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
$option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
$productID = $params['selectProduct'];
}
$defaults = array();
- $fields = array();
- foreach ($this->_fields as $name => $dontCare) {
- if ($name != 'onbehalf' || $name != 'honor') {
- $fields[$name] = 1;
- }
- }
+ $fields = array_fill_keys(array_keys($this->_fields), 1);
$fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
$contact = $this->_params;
foreach ($fields as $name => $dontCare) {
- if (isset($contact[$name])) {
+ // Recursively set defaults for nested fields
+ if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' || $name == 'honor')) {
+ foreach ($contact[$name] as $fieldName => $fieldValue) {
+ if (is_array($fieldValue) && !in_array($this->_fields[$name][$fieldName]['html_type'], array('Multi-Select','AdvMulti-Select'))) {
+ foreach ($fieldValue as $key => $value) {
+ $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
+ }
+ }
+ else {
+ $defaults["{$name}[{$fieldName}]"] = $fieldValue;
+ }
+ }
+ }
+ elseif (isset($contact[$name])) {
$defaults[$name] = $contact[$name];
if (substr($name, 0, 7) == 'custom_') {
$timeField = "{$name}_time";
}
/**
- * overwrite action, since we are only showing elements in frozen mode
+ * Overwrite action, since we are only showing elements in frozen mode
* no help display needed
*
* @return int
}
/**
- * This function sets the default values for the form. Note that in edit/view mode
+ * Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
* @access public
*/
public function postProcess() {
$contactID = $this->getContactID();
-
+ $isPayLater = $this->_params['is_pay_later'];
+ if ($this->_params['payment_processor'] == 0) {
+ $this->_params['is_pay_later'] = $isPayLater = TRUE;
+ }
// add a description field at the very beginning
$this->_params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
//unset the billing parameters if it is pay later mode
//to avoid creation of billing location
- if ($params['is_pay_later']) {
+ if ($isPayLater && !$this->_isBillingAddressRequiredForPayLater) {
$billingFields = array(
'billing_first_name',
'billing_middle_name',
}
}
}
- $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems);
+ $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater);
if (!$this->_amount > 0.0 || !$membershipParams['amount']) {
// we need to explicitly create a CMS user in case of free memberships
// since it is done under processConfirm for paid memberships
}
$fieldTypes = array('Contact', 'Organization', 'Contribution');
}
+ $financialTypeID = $this->wrangleFinancialTypeID($contributionTypeId);
CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams,
$premiumParams, $contactID,
- $contributionTypeId,
+ $financialTypeID,
'contribution',
- $fieldTypes
+ $fieldTypes,
+ ($this->_mode == 'test') ? 1 : 0,
+ $isPayLater
);
}
}
+ /**
+ * This wrangling of the financialType ID was happening in a shared function rather than in the form it relates to & hence has been moved to that form
+ * Pledges are not relevant to the membership code so that portion will not go onto the membership form.
+ *
+ * Comments from previous refactor indicate doubt as to what was going on
+ * @param int $contributionTypeId
+ *
+ * @return null|string
+ */
+ function wrangleFinancialTypeID($contributionTypeId) {
+ if (isset($paymentParams['financial_type'])) {
+ $contributionTypeId = $paymentParams['financial_type'];
+ }
+ elseif (!empty($this->_values['pledge_id'])) {
+ $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge',
+ $this->_values['pledge_id'],
+ 'financial_type_id'
+ );
+ }
+ return $contributionTypeId;
+ }
+
/**
* Process the form
*
- * @param $premiumParams
+ * @param array $premiumParams
* @param $contribution
*
* @return void
/**
* Process the contribution
*
- * @param $form
+ * @param CRM_Core_Form $form
* @param array $params
* @param array $result
* @param integer $contactID
// a better fix would be to set the values in the respective forms rather than require
// a function being shared by two forms to deal with their respective values
// moving it to the BAO & not taking the $form as a param would make sense here.
- if(!isset($params['is_email_receipt'])){
+ if(!isset($params['is_email_receipt']) && !empty($form->_values['is_email_receipt'])){
$params['is_email_receipt'] = CRM_Utils_Array::value( 'is_email_receipt', $form->_values );
}
$recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType, $online);
}
if (isset($params['amount'])) {
+ $isMonetary = NULL;
+ if (!empty($form->_values['is_monetary'])) {
+ $isMonetary = $form->_values['is_monetary'];
+ }
$contribParams = self::getContributionParams(
- $params, $contactID, $financialType->id, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $form->_values['is_monetary'], $pending, $result, $receiptDate,
+ $params, $contactID, $financialType->id, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate,
$recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems
);
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams);
+
+ $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,'contribution_invoice_settings');
+ $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
+ if ($invoicing) {
+ $totalTaxAmount = 0;
+ $dataArray = array();
+ foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
+ foreach ($lineItemValue as $key => $value) {
+ if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
+ if (isset($dataArray[$value['tax_rate']])) {
+ $dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
+ }
+ else {
+ $dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
+ }
+ }
+ }
+ }
+ $smarty = CRM_Core_Smarty::singleton();
+ $smarty->assign('dataArray', $dataArray);
+ $smarty->assign('totalTaxAmount', $params['tax_amount']);
+ }
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
/**
* Create the recurring contribution record
*
+ * @param CRM_Core_Form $form
+ * @param array $params
+ * @param integer $contactID
+ * @param string $contributionType
+ * @param bool $online
+ *
+ * @return mixed
*/
static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE) {
// return if this page is not set for recurring
// CRM-14354: For an auto-renewing membership with an additional contribution,
// if separate payments is not enabled, make sure only the membership fee recurs
- if ($form->_membershipBlock['is_separate_payment'] === '0'
+ if (!empty($form->_membershipBlock)
+ && $form->_membershipBlock['is_separate_payment'] === '0'
&& isset($params['selectMembership'])
&& $form->_values['is_allow_other_amount'] == '1'
) {
}
/**
- * Function to add on behalf of organization and it's location
+ * Add on behalf of organization and it's location
*
* @param $behalfOrganization array array of organization info
* @param $contactID int individual contact id. One
* who is doing the process of signup / contribution.
*
* @param $values array form values array
- * @param $params
+ * @param array $params
* @param null $fields
*
* @return void
* Function used to se pcp related defaults / params
* This is used by contribution and also event pcps
*
- * @param object $page form object
+ * @param CRM_Core_Form $page form object
* @param array $params associated array
*
* @return array
* @param array $fieldTypes
* @param array $premiumParams
* @param array $membershipLineItems line items specifically relating to memberships
+ * @param $isPayLater
*/
- public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems) {
+ public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater) {
try {
$membershipTypeIDs = (array) $membershipParams['selectMembership'];
$membershipTypes = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIDs);
CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID,
$this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $contributionTypeId,
- $membershipLineItems
+ $membershipLineItems, $isPayLater
);
$this->assign('membership_assign', TRUE);
$this->set('membershipTypeID', $membershipParams['selectMembership']);
* And under certain circumstances sets
* $this->_params['amount'] = null;
*
- * @param $priceSetID
+ * @param int $priceSetID
*
- * @internal param $isQuickConfig
- * @internal param $priceField
*/
public function setFormAmountFields($priceSetID) {
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config');
}
}
+ /**
+ * @param array $params
+ *
+ * @throws CiviCRM_API3_Exception
+ */
static function submit($params) {
$form = new CRM_Contribute_Form_Contribution_Confirm();
$form->_id = $params['id'];
$form->_contributeMode = 'notify';
}
}
+ else {
+ $form->_params['payment_processor'] = 0;
+ }
$priceFields = $priceFields[$priceSetID]['fields'];
CRM_Price_BAO_PriceSet::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
$form->_lineItem = array($priceSetID => $lineItems);
/**
* Helper function for static submit function - set relevant params - help us to build up an array that we can pass in
- * @param $id
+ * @param int $id
* @param array $params
*
* @return array