}
}
+ /**
+ * Begin post processing.
+ *
+ * This function aims to start to bring together common postProcessing functions.
+ *
+ * Eventually these are also shared with the front end forms & may need to be moved to where they can also
+ * access this function.
+ */
+ protected function beginPostProcess() {
+ if (in_array('credit_card_exp_date', array_keys($this->_params))) {
+ $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
+ $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
+ }
+
+ $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
+ }
+
+
+ /**
+ * Add the billing address to the contact who paid.
+ *
+ * Note that this function works based on the presence or otherwise of billing fields & can be called regardless of
+ * whether they are 'expected' (due to assumptions about the payment processor type or the setting to collect billing
+ * for pay later.
+ */
+ protected function processBillingAddress() {
+ $fields = array();
+
+ $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')
+ );
+ }
+ // Add additional parameters that the payment processors are used to receiving.
+ if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
+ $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
+ }
+ if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) {
+ $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
+ }
+ }
+
}
$submittedValues['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
}
- $params = $this->_params = $submittedValues;
+ $params = $submittedValues;
+ $this->_params = array_merge($this->_params, $submittedValues);
// Mapping requiring documentation.
$this->_params['payment_processor'] = $submittedValues['payment_processor_id'];
$now = date('YmdHis');
- $fields = array();
// we need to retrieve email address
if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
$this->assign('displayName', $this->userDisplayName);
}
- // Set email for primary location.
- $fields['email-Primary'] = 1;
- $params['email-Primary'] = $this->userEmail;
-
- // 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
- $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
-
- $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
- $fields["address_name-{$this->_bltID}"] = 1;
-
- $nameFields = array('first_name', 'middle_name', 'last_name');
- foreach ($nameFields as $name) {
- $fields[$name] = 1;
- if (array_key_exists("billing_$name", $params)) {
- $params[$name] = $params["billing_{$name}"];
- $params['preserveDBName'] = TRUE;
- }
- }
-
+ $this->_contributorEmail = $this->userEmail;
+ $this->_contributorContactID = $contactID;
+ $this->processBillingAddress();
if (!empty($params['source'])) {
unset($params['source']);
}
- CRM_Contact_BAO_Contact::createProfileContact($params, $fields,
- $contactID,
- NULL, NULL,
- CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
- $contactID,
- 'contact_type'
- )
- );
-
- // add all the additional payment params we need
- if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
- $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
- }
- if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) {
- $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
- }
-
- if (in_array('credit_card_exp_date', array_keys($this->_params))) {
- $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
- $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
- }
- $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $this->_params['total_amount'];
$this->_params['amount_level'] = 0;
$this->_params['description'] = ts("Contribution submitted by a staff person using contributor's credit card");
protected function submit($submittedValues, $action, $pledgePaymentID) {
$softParams = $softIDs = array();
$pId = $contribution = $isRelatedId = FALSE;
+ $this->_params = $submittedValues;
+ $this->beginPostProcess();
if (!empty($submittedValues['price_set_id']) && $action & CRM_Core_Action::UPDATE) {
$line = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution');
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.
*/
$this->assign('is_pay_later', TRUE);
}
if ($this->_mode) {
- // set default country from config if no country set
- $config = CRM_Core_Config::singleton();
- if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
- $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
- }
-
- if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
- $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
- }
-
- $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
- $defaults = array_merge($defaults, $billingDefaults);
-
+ $defaults = $this->getBillingDefaults($defaults);
// hack to simplify credit card entry for testing
// $defaults['credit_card_type'] = 'Visa';
// $defaults['credit_card_number'] = '4807731747657838';
$this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
if ($this->_mode) {
- // set default country from config if no country set
- $config = CRM_Core_Config::singleton();
- if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
- $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
- }
-
- if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
- $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
- }
-
- $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
- $defaults = array_merge($defaults, $billingDefaults);
-
+ $defaults = $this->getBillingDefaults($defaults);
}
return $defaults;
}
}
}
+ /**
+ * @param $defaults
+ *
+ * @return array
+ */
+ protected function getBillingDefaults($defaults) {
+ // set default country from config if no country set
+ $config = CRM_Core_Config::singleton();
+ if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
+ $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
+ }
+
+ if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
+ $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
+ }
+
+ $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
+ return array_merge($defaults, $billingDefaults);
+ }
+
}