* @param int $membershipOrg
* @param int $membershipTypeID
* @param float $total_amount
+ * @param int $priceSetId
*
* @return array
*/
- public static function getQuickConfigMembershipLineItems($membershipOrg, $membershipTypeID, $total_amount) {
- $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
+ public static function setQuickConfigMembershipParameters($membershipOrg, $membershipTypeID, $total_amount, $priceSetId) {
$priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
// The name of the price field corresponds to the membership_type organization contact.
return $contribution;
}
- /**
- * Record line items for default membership.
- * @deprecated
- *
- * Use getQuickConfigMembershipLineItems
- *
- * @param CRM_Core_Form $qf
- * @param array $membershipType
- * Array with membership type and organization.
- *
- * @return int $priceSetId
- */
- public static function createLineItems(&$qf, $membershipType) {
- $qf->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
- $qf->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
-
- // The name of the price field corresponds to the membership_type organization contact.
- $editedFieldParams = array(
- 'price_set_id' => $priceSetId,
- 'name' => $membershipType[0],
- );
- $editedResults = array();
- CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
-
- if (!empty($editedResults)) {
- unset($qf->_priceSet['fields']);
- $qf->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
- unset($qf->_priceSet['fields'][$editedResults['id']]['options']);
- $fid = $editedResults['id'];
- $editedFieldParams = array(
- 'price_field_id' => $editedResults['id'],
- 'membership_type_id' => $membershipType[1],
- );
- $editedResults = array();
- CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
- $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
- if (!empty($qf->_params['total_amount'])) {
- $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $qf->_params['total_amount'];
- }
- }
-
- $fieldID = key($qf->_priceSet['fields']);
- $qf->_params['price_' . $fieldID] = CRM_Utils_Array::value('id', $editedResults);
- return $priceSetId;
- }
-
/**
* @todo document me - I seem a bit out of date....
*/
public static function getSelectedMemberships($priceSet, $params) {
$memTypeSelected = array();
$priceFieldIDS = self::getPriceFieldIDs($params, $priceSet);
- if (!empty($priceSet) && is_array($priceFieldIDS)) {
+ if (isset($params['membership_type_id']) && !empty($params['membership_type_id'][1])) {
+ $memTypeSelected = array($params['membership_type_id'][1] => $params['membership_type_id'][1]);
+ }
+ else {
foreach ($priceFieldIDS as $priceFieldId) {
if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
$memTypeSelected[$id] = $id;
}
}
}
- else {
- $memTypeSelected = array($params['membership_type_id'][1] => $params['membership_type_id'][1]);
- }
return $memTypeSelected;
}
public static function formRule($params, $files, $self) {
$errors = array();
- $priceSetId = CRM_Utils_Array::value('price_set_id', $params);
- $priceSetDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId);
+ $priceSetId = self::getPriceSetID($params);
+ $priceSetDetails = self::getPriceSetDetails($params);
$selectedMemberships = self::getSelectedMemberships($priceSetDetails[$priceSetId], $params);
- if ($priceSetId) {
+
+ if (!empty($params['price_set_id'])) {
CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $params, $errors);
$priceFieldIDS = self::getPriceFieldIDs($params, $priceSetDetails);
return $errors;
}
-
if (!empty($params['record_contribution']) && empty($params['payment_instrument_id'])) {
$errors['payment_instrument_id'] = ts('Payment Method is a required field.');
}
$membershipType = NULL;
$mailSend = FALSE;
- $priceSetID = CRM_Utils_Array::value('price_set_id', $formValues);
+ $formValues = $this->setPriceSetParameters($formValues);
$params = $softParams = $ids = array();
// In form mode these are set in preProcess.
//TODO: set memberships, fixme
$this->setContextVariables($formValues);
- $priceSetDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID);
+
$this->_memTypeSelected = self::getSelectedMemberships(
- $priceSetDetails[$priceSetID],
+ $this->_priceSet,
$formValues
);
if (empty($formValues['financial_type_id'])) {
- $formValues['financial_type_id'] = $priceSetDetails[$priceSetID]['financial_type_id'];
+ $formValues['financial_type_id'] = $this->_priceSet['financial_type_id'];
}
$config = CRM_Core_Config::singleton();
//take the required membership recur values.
if ($this->_mode && !empty($formValues['auto_renew'])) {
- $params['is_recur'] = $this->_params['is_recur'] = $formValues['is_recur'] = TRUE;
+ $params['is_recur'] = $formValues['is_recur'] = TRUE;
$mapping = array(
'frequency_interval' => 'duration_interval',
'frequency_unit' => 'duration_unit',
$recurMembershipTypeValues
);
if (!$count) {
- $this->_params[$mapVal] = $formValues[$mapVal] = CRM_Utils_Array::value($mapParam,
+ $formValues[$mapVal] = CRM_Utils_Array::value($mapParam,
$recurMembershipTypeValues
);
}
}
}
- // process price set and get total amount and line items.
- if (!$priceSetID) {
- $priceSetID = CRM_Member_BAO_Membership::createLineItems(
- $this,
- $formValues['membership_type_id'],
- NULL
- );
- }
- $isQuickConfig = FALSE;
- if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetID, 'is_quick_config')) {
- $isQuickConfig = 1;
- }
+ $isQuickConfig = $this->_priceSet['is_quick_config'];
+
$termsByType = array();
- $lineItem = array();
+ $lineItem = array($this->_priceSetId => array());
+
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
- $this->_params, $lineItem[$priceSetID]);
- if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
- $params['tax_amount'] = $this->_params['tax_amount'];
+ $formValues, $lineItem[$this->_priceSetId]);
+
+ if (CRM_Utils_Array::value('tax_amount', $formValues)) {
+ $params['tax_amount'] = $formValues['tax_amount'];
}
- $params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
+ $params['total_amount'] = CRM_Utils_Array::value('amount', $formValues);
$submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
- if (!empty($lineItem[$priceSetID])) {
- foreach ($lineItem[$priceSetID] as &$li) {
+ if (!empty($lineItem[$this->_priceSetId])) {
+ foreach ($lineItem[$this->_priceSetId] as &$li) {
if (!empty($li['membership_type_id'])) {
if (!empty($li['membership_num_terms'])) {
$termsByType[$li['membership_type_id']] = $li['membership_num_terms'];
//CRM-13981, allow different person as a soft-contributor of chosen type
if ($this->_contributorContactID != $this->_contactID) {
$params['contribution_contact_id'] = $this->_contributorContactID;
- if (!empty($this->_params['soft_credit_type_id'])) {
- $softParams['soft_credit_type_id'] = $this->_params['soft_credit_type_id'];
+ if (!empty($formValues['soft_credit_type_id'])) {
+ $softParams['soft_credit_type_id'] = $formValues['soft_credit_type_id'];
$softParams['contact_id'] = $this->_contactID;
}
}
}
$createdMemberships = array();
if ($this->_mode) {
- if (empty($formValues['total_amount']) && !$priceSetID) {
- // if total amount not provided minimum for membership type is used
- $params['total_amount'] = $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
- $formValues['membership_type_id'][1], 'minimum_fee'
- );
- }
- else {
- $params['total_amount'] = CRM_Utils_Array::value('total_amount', $formValues, 0);
- }
+ $params['total_amount'] = CRM_Utils_Array::value('total_amount', $formValues, 0);
- if ($priceSetID && !$isQuickConfig) {
+ if (!$isQuickConfig) {
$params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet',
- $priceSetID,
+ $this->_priceSetId,
'financial_type_id'
);
}
);
//get the payment processor id as per mode.
- $params['payment_processor_id'] = $this->_params['payment_processor_id'] = $formValues['payment_processor_id'] = $this->_paymentProcessor['id'];
+ $params['payment_processor_id'] = $formValues['payment_processor_id'] = $this->_paymentProcessor['id'];
$now = date('YmdHis');
$fields = array();
}
// add all the additional payment params we need
- $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"]
+ $formValues["state_province-{$this->_bltID}"] = $formValues["billing_state_province-{$this->_bltID}"]
= CRM_Core_PseudoConstant::stateProvinceAbbreviation($formValues["billing_state_province_id-{$this->_bltID}"]);
- $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($formValues["billing_country_id-{$this->_bltID}"]);
+ $formValues["country-{$this->_bltID}"] = $formValues["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($formValues["billing_country_id-{$this->_bltID}"]);
- $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($formValues);
- $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($formValues);
- $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
- $this->_params['amount'] = $params['total_amount'];
- $this->_params['currencyID'] = $config->defaultCurrency;
- $this->_params['description'] = ts("Contribution submitted by a staff person using member's credit card for signup");
- $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
- $this->_params['financial_type_id'] = $params['financial_type_id'];
+ $formValues['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($formValues);
+ $formValues['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($formValues);
+ $formValues['ip_address'] = CRM_Utils_System::ipAddress();
+ $formValues['amount'] = $params['total_amount'];
+ $formValues['currencyID'] = $config->defaultCurrency;
+ $formValues['description'] = ts("Contribution submitted by a staff person using member's credit card for signup");
+ $formValues['invoiceID'] = md5(uniqid(rand(), TRUE));
+ $formValues['financial_type_id'] = $params['financial_type_id'];
// 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
// so we copy stuff over to first_name etc.
- $paymentParams = $this->_params;
+ $paymentParams = $formValues;
$paymentParams['contactID'] = $this->_contributorContactID;
//CRM-10377 if payment is by an alternate contact then we need to set that person
// as the contact in the payment params
if ($this->_contributorContactID != $this->_contactID) {
- if (!empty($this->_params['soft_credit_type_id'])) {
+ if (!empty($formValues['soft_credit_type_id'])) {
$softParams['contact_id'] = $params['contact_id'];
- $softParams['soft_credit_type_id'] = $this->_params['soft_credit_type_id'];
+ $softParams['soft_credit_type_id'] = $formValues['soft_credit_type_id'];
}
}
- if (!empty($this->_params['send_receipt'])) {
+ if (!empty($formValues['send_receipt'])) {
$paymentParams['email'] = $this->_contributorEmail;
}
- CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
-
+ CRM_Core_Payment_Form::mapParams($this->_bltID, $formValues, $paymentParams, TRUE);
// CRM-7137 -for recurring membership,
// we do need contribution and recurring records.
$result = NULL;
$financialType = new CRM_Financial_DAO_FinancialType();
$financialType->id = $params['financial_type_id'];
$financialType->find(TRUE);
-
+ $this->_params = $formValues;
$contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this,
$paymentParams,
NULL,
'line_item' => $lineItem,
'is_test' => $isTest,
'campaign_id' => CRM_Utils_Array::value('campaign_id', $paymentParams),
- 'contribution_page_id' => CRM_Utils_Array::value('contribution_page_id', $this->_params),
+ 'contribution_page_id' => CRM_Utils_Array::value('contribution_page_id', $formValues),
'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)),
'thankyou_date' => CRM_Utils_Array::value('thankyou_date', $paymentParams),
'payment_instrument_id' => $this->_paymentProcessor['payment_instrument_id'],
$payment = $this->_paymentProcessor['object'];
try {
$result = $payment->doPayment($paymentParams);
- $this->_params = array_merge($this->_params, $result);
+ $formValues = array_merge($formValues, $result);
// Assign amount to template if payment was successful.
$this->assign('amount', $params['total_amount']);
}
}
}
- if ($this->_params['payment_status_id'] != array_search('Completed', $allContributionStatus)) {
+ if ($formValues['payment_status_id'] != array_search('Completed', $allContributionStatus)) {
$params['status_id'] = array_search('Pending', $allMemberStatus);
$params['skipStatusCal'] = TRUE;
// unset send-receipt option, since receipt will be sent when ipn is received.
- unset($this->_params['send_receipt'], $formValues['send_receipt']);
+ unset($formValues['send_receipt'], $formValues['send_receipt']);
//as membership is pending set dates to null.
$memberDates = array(
'join_date' => 'joinDate',
}
}
$params['receive_date'] = $now;
- $params['invoice_id'] = $this->_params['invoiceID'];
+ $params['invoice_id'] = $formValues['invoiceID'];
$params['contribution_source'] = ts('%1 Membership Signup: Credit card or direct debit (by %2)',
array(1 => $membershipType, 2 => $userName)
);
$params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result);
$params['payment_instrument_id'] = 1;
$params['is_test'] = ($this->_mode == 'live') ? 0 : 1;
- if (!empty($this->_params['send_receipt'])) {
+ if (!empty($formValues['send_receipt'])) {
$params['receipt_date'] = $now;
}
else {
$params['receipt_date'] = NULL;
}
- $this->set('params', $this->_params);
+ $this->set('params', $formValues);
$this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $result));
$this->assign('receive_date',
CRM_Utils_Date::mysqlToIso($params['receive_date'])
// process -
// @see http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=261062657#Payments&AccountsRoadmap-Movetowardsalwaysusinga2-steppaymentprocess
$membershipParams['contribution_status_id'] = CRM_Utils_Array::value('payment_status_id', $result);
- unset($membershipParams['lineItems']);
+ if (!empty($paymentParams['is_recur'])) {
+ // The earlier process created the line items (although we want to get rid of the earlier one in favour
+ // of a single path!
+ unset($membershipParams['lineItems']);
+ }
+
$membership = CRM_Member_BAO_Membership::create($membershipParams, $ids);
$params['contribution'] = CRM_Utils_Array::value('contribution', $membershipParams);
unset($params['lineItems']);
}
}
- if (!empty($lineItem[$priceSetID])) {
+ if (!empty($lineItem[$this->_priceSetId])) {
$invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
$taxAmount = FALSE;
$totalTaxAmount = 0;
- foreach ($lineItem[$priceSetID] as & $priceFieldOp) {
+ foreach ($lineItem[$this->_priceSetId] as & $priceFieldOp) {
if (!empty($priceFieldOp['membership_type_id'])) {
$priceFieldOp['start_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'], '%B %E%f, %Y') : '-';
$priceFieldOp['end_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'], '%B %E%f, %Y') : '-';
}
if ($invoicing) {
$dataArray = array();
- foreach ($lineItem[$priceSetID] as $key => $value) {
+ foreach ($lineItem[$this->_priceSetId] 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);