Currenlty the membership form is not saving correctly & giving enotices.
Am modifiying to be using the same code for both forms as part of this
fix.
Conflicts:
CRM/Member/Form/Membership.php
CRM-17089 consolidated billing name assignment between the forms
CRM-17089 fix & consolidate saving of billing fields
/**
* @param $form
+ * @param array $params Parameters from the form.
*/
- public static function postProcess($form) {
- $params = $form->_params;
+ public static function postProcess($form, $params) {
if (!empty($form->_honor_block_is_active) && !empty($params['soft_credit_type_id'])) {
$honorId = NULL;
$contactID = $contributionParams['contact_id'];
$isEmailReceipt = !empty($form->_values['is_email_receipt']);
- // How do these vary from params? These are currently passed to
- // - custom data function....
- $formParams = $form->_params;
- $isSeparateMembershipPayment = empty($formParams['separate_membership_payment']) ? FALSE : TRUE;
- $pledgeID = empty($formParams['pledge_id']) ? NULL : $formParams['pledge_id'];
+ $isSeparateMembershipPayment = empty($params['separate_membership_payment']) ? FALSE : TRUE;
+ $pledgeID = empty($params['pledge_id']) ? NULL : $params['pledge_id'];
if (!$isSeparateMembershipPayment && !empty($form->_values['pledge_block_id']) &&
- (!empty($formParams['is_pledge']) || $pledgeID)) {
+ (!empty($params['is_pledge']) || $pledgeID)) {
$isPledge = TRUE;
}
else {
}
//CRM-13981, processing honor contact into soft-credit contribution
- CRM_Contact_Form_ProfileContact::postProcess($form);
+ CRM_Contact_Form_ProfileContact::postProcess($form, $params);
// process soft credit / pcp pages
CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
if ($pledgeID) {
//when user doing pledge payments.
//update the schedule when payment(s) are made
- foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
+ foreach ($params['pledge_amount'] as $paymentId => $dontCare) {
$scheduledAmount = CRM_Core_DAO::getFieldValue(
'CRM_Pledge_DAO_PledgePayment',
$paymentId,
}
if ($online && $contribution) {
- CRM_Core_BAO_CustomValueTable::postProcess($form->_params,
+ CRM_Core_BAO_CustomValueTable::postProcess($params,
'civicrm_contribution',
$contribution->id,
'Contribution'
*/
public $_priceSet;
+ /**
+ * Values submitted to the form, processed along the way.
+ *
+ * @var array
+ */
+ protected $_params = array();
+
public function preProcess() {
// Check for edit permission.
if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
return $formValues;
}
+ /**
+ * Add the billing address to the contact who paid.
+ */
+ protected function processBillingAddress() {
+ $fields = array();
+
+ // set email for primary location.
+ $fields['email-Primary'] = 1;
+ $this->_params['email-5'] = $this->_params['email-Primary'] = $this->_contributorEmail;
+ // now set the values for the billing location.
+ foreach (array_keys($this->_fields) as $name) {
+ $fields[$name] = 1;
+ }
+
+ // also add location name to the array
+ $this->_params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $this->_params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $this->_params) . ' ' . CRM_Utils_Array::value('billing_last_name', $this->_params);
+ $this->_params["address_name-{$this->_bltID}"] = trim($this->_params["address_name-{$this->_bltID}"]);
+
+ $fields["address_name-{$this->_bltID}"] = 1;
+
+ //ensure we don't over-write the payer's email with the member's email
+ if ($this->_contributorContactID == $this->_contactID) {
+ $fields["email-{$this->_bltID}"] = 1;
+ }
+
+ list($hasBillingField, $addressParams) = CRM_Contribute_BAO_Contribution::getPaymentProcessorReadyAddressParams($this->_params, $this->_bltID);
+ $nameFields = array('first_name', 'middle_name', 'last_name');
+
+ foreach ($nameFields as $name) {
+ $fields[$name] = 1;
+ if (array_key_exists("billing_$name", $this->_params)) {
+ $this->_params[$name] = $this->_params["billing_{$name}"];
+ $this->_params['preserveDBName'] = TRUE;
+ }
+ }
+
+ if ($hasBillingField) {
+ $addressParams = array_merge($this->_params, $addressParams);
+ //here we are setting up the billing contact - if different from the member they are already created
+ // but they will get billing details assigned
+ CRM_Contact_BAO_Contact::createProfileContact($addressParams, $fields,
+ $this->_contributorContactID, NULL, NULL,
+ CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type')
+ );
+ }
+ }
+
+ /**
+ * Assign billing name to the template.
+ */
+ protected function assignBillingName() {
+ $name = '';
+ if (!empty($this->_params['billing_first_name'])) {
+ $name = $this->_params['billing_first_name'];
+ }
+
+ if (!empty($this->_params['billing_middle_name'])) {
+ $name .= " {$this->_params['billing_middle_name']}";
+ }
+
+ if (!empty($this->_params['billing_last_name'])) {
+ $name .= " {$this->_params['billing_last_name']}";
+ }
+ $this->assign('billingName', $name);
+ }
+
+ /**
+ * Wrapper function for unit tests.
+ *
+ * @param array $formValues
+ */
+ public function testSubmit($formValues) {
+ $this->_memType = $formValues['membership_type_id'][1];
+ $this->_params = $formValues;
+ $this->submit();
+ }
+
}
// get the submitted form values.
$this->_params = $this->controller->exportValues($this->_name);
- $this->submit($this->_params);
+ $this->submit();
$this->setUserContext();
}
$form->assign('customValues', $customValues);
if ($form->_mode) {
- $name = '';
- if (!empty($form->_params['billing_first_name'])) {
- $name = $form->_params['billing_first_name'];
- }
-
- if (!empty($form->_params['billing_middle_name'])) {
- $name .= " {$form->_params['billing_middle_name']}";
- }
-
- if (!empty($form->_params['billing_last_name'])) {
- $name .= " {$form->_params['billing_last_name']}";
- }
-
- $form->assign('billingName', $name);
-
// assign the address formatted up for display
$addressParts = array(
"street_address-{$form->_bltID}",
*
* This is also accessed by unit tests.
*
- * @param array $formValues
- *
* @return array
*/
- public function submit($formValues) {
+ public function submit() {
$isTest = ($this->_mode == 'test') ? 1 : 0;
-
+ $this->storeContactFields($this->_params);
+ $formValues = $this->_params;
$joinDate = $startDate = $endDate = NULL;
$membershipTypes = $membership = $calcDate = array();
$membershipType = NULL;
$mailSend = FALSE;
$formValues = $this->setPriceSetParameters($formValues);
-
$params = $softParams = $ids = array();
$allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
$allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
+ $this->processBillingAddress();
if ($this->_id) {
$ids['membership'] = $params['id'] = $this->_id;
}
}
- $this->storeContactFields($formValues);
-
$params['contact_id'] = $this->_contactID;
$fields = array(
//get the payment processor id as per mode.
$params['payment_processor_id'] = $formValues['payment_processor_id'] = $this->_paymentProcessor['id'];
-
- $now = date('YmdHis');
- $fields = array();
-
- // set email for primary location.
- $fields['email-Primary'] = 1;
- $formValues['email-5'] = $formValues['email-Primary'] = $this->_memberEmail;
- $params['register_date'] = $now;
-
- // now set the values for the billing location.
- foreach ($this->_fields as $name => $dontCare) {
- $fields[$name] = 1;
- }
-
- // also add location name to the array
- $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues);
-
- $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]);
-
- $fields["address_name-{$this->_bltID}"] = 1;
- //ensure we don't over-write the payer's email with the member's email
- if ($this->_contributorContactID == $this->_contactID) {
- $fields["email-{$this->_bltID}"] = 1;
- }
-
- $nameFields = array('first_name', 'middle_name', 'last_name');
-
- foreach ($nameFields as $name) {
- $fields[$name] = 1;
- if (array_key_exists("billing_$name", $formValues)) {
- $formValues[$name] = $formValues["billing_{$name}"];
- $formValues['preserveDBName'] = TRUE;
- }
- }
- if ($this->_contributorContactID == $this->_contactID) {
- //see CRM-12869 for discussion of why we don't do this for separate payee payments
- CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields,
- $this->_contributorContactID, NULL, NULL,
- CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type')
- );
- }
+ $params['register_date'] = date('YmdHis');
// add all the additional payment params we need
$formValues["state_province-{$this->_bltID}"] = $formValues["billing_state_province-{$this->_bltID}"]
}
}
}
+ $now = date('YmdHis');
$params['receive_date'] = $now;
$params['invoice_id'] = $formValues['invoiceID'];
$params['contribution_source'] = ts('%1 Membership Signup: Credit card or direct debit (by %2)',
// although at some point we should switch in the templates.
$formValues['receipt_text_signup'] = $formValues['receipt_text'];
// send email receipt
+ $this->assignBillingName();
$mailSend = self::emailReceipt($this, $formValues, $membership);
}
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
*/
/**
/**
* Process the renewal form.
- *
- *
- * @return void
*/
public function postProcess() {
// get the submitted form values.
$now = CRM_Utils_Date::getToday(NULL, 'YmdHis');
$this->convertDateFieldsToMySQL($this->_params);
$this->assign('receive_date', $this->_params['receive_date']);
- $this->processBillingAddress($now);
+ $this->processBillingAddress();
list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID'));
$this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params,
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee')
}
}
- /**
- * Wrapper function for unit tests.
- *
- * @param array $formValues
- */
- public function testSubmit($formValues) {
- $this->_memType = $formValues['membership_type_id'][1];
- $this->_params = $formValues;
- $this->submit($formValues);
- }
-
- protected function assignBillingName() {
- $name = '';
- if (!empty($this->_params['billing_first_name'])) {
- $name = $this->_params['billing_first_name'];
- }
-
- if (!empty($this->_params['billing_middle_name'])) {
- $name .= " {$this->_params['billing_middle_name']}";
- }
-
- if (!empty($this->_params['billing_last_name'])) {
- $name .= " {$this->_params['billing_last_name']}";
- }
- $this->assign('billingName', $name);
- }
-
- /**
- * Add the billing address to the contact who paid.
- */
- protected function processBillingAddress() {
- $fields = array();
-
- // set email for primary location.
- $fields['email-Primary'] = 1;
- $this->_params['email-5'] = $this->_params['email-Primary'] = $this->_contributorEmail;
-
- // also add location name to the array
- $this->_params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $this->_params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $this->_params) . ' ' . CRM_Utils_Array::value('billing_last_name', $this->_params);
-
- $this->_params["address_name-{$this->_bltID}"] = trim($this->_params["address_name-{$this->_bltID}"]);
-
- $fields["address_name-{$this->_bltID}"] = 1;
- $fields["email-{$this->_bltID}"] = 1;
-
- list($hasBillingField, $addressParams) = CRM_Contribute_BAO_Contribution::getPaymentProcessorReadyAddressParams($this->_params, $this->_bltID);
-
- $addressParams['preserveDBName'] = TRUE;
- if ($hasBillingField) {
- $addressParams = array_merge($this->_params, $addressParams);
- //here we are setting up the billing contact - if different from the member they are already created
- // but they will get billing details assigned
- CRM_Contact_BAO_Contact::createProfileContact($addressParams, $fields,
- $this->_contributorContactID, NULL, NULL,
- CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type')
- );
- }
- }
-
}
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
);
- $form->submit($params);
+ $form->_contactID = $this->_individualId;
+ $form->testSubmit($params);
$membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
$this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0);
$contribution = $this->callAPISuccess('Contribution', 'get', array(
$this->createLoggedInUser();
$params = $this->getBaseSubmitParams();
$form->_mode = 'test';
-
- $form->submit($params);
+ $form->_contactID = $this->_individualId;
+ $form->testSubmit($params);
$membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
$this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
), 1);
}
+ /**
+ * Test the submit function of the membership form.
+ */
+ public function testSubmitPayLaterWithBilling() {
+ $form = $this->getForm(NULL);
+ $this->createLoggedInUser();
+ $params = array(
+ 'cid' => $this->_individualId,
+ 'join_date' => date('m/d/Y', time()),
+ 'start_date' => '',
+ 'end_date' => '',
+ // This format reflects the 23 being the organisation & the 25 being the type.
+ 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'auto_renew' => '0',
+ 'max_related' => '',
+ 'num_terms' => '2',
+ 'source' => '',
+ 'total_amount' => '50.00',
+ //Member dues, see data.xml
+ 'financial_type_id' => '2',
+ 'soft_credit_type_id' => '',
+ 'soft_credit_contact_id' => '',
+ 'payment_instrument_id' => 4,
+ 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
+ 'receipt_text_signup' => 'Thank you text',
+ 'payment_processor_id' => $this->_paymentProcessorID,
+ 'record_contribution' => TRUE,
+ 'trxn_id' => 777,
+ 'contribution_status_id' => 2,
+ 'billing_first_name' => 'Test',
+ 'billing_middlename' => 'Last',
+ 'billing_street_address-5' => '10 Test St',
+ 'billing_city-5' => 'Test',
+ 'billing_state_province_id-5' => '1003',
+ 'billing_postal_code-5' => '90210',
+ 'billing_country_id-5' => '1228',
+ );
+ $form->_contactID = $this->_individualId;
+
+ $form->testSubmit($params);
+ $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ 'contact_id' => $this->_individualId,
+ 'contribution_status_id' => 2,
+ ));
+ $this->assertEquals($contribution['trxn_id'], 777);
+
+ $this->callAPISuccessGetCount('LineItem', array(
+ 'entity_id' => $membership['id'],
+ 'entity_table' => 'civicrm_membership',
+ 'contribution_id' => $contribution['id'],
+ ), 1);
+ $this->callAPISuccessGetSingle('address', array(
+ 'contact_id' => $this->_individualId,
+ 'street_address' => '10 Test St',
+ 'postal_code' => 90210,
+ ));
+ }
+
/**
* Test the submit function of the membership form.
*/
$this->createLoggedInUser();
$params = $this->getBaseSubmitParams();
$form->_mode = 'test';
-
- $form->submit($params);
+ $form->_contactID = $this->_individualId;
+ $form->testSubmit($params);
$membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
$this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);