* 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.
+ *
+ * @param int $contactID
+ * @param string $email
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
- protected function processBillingAddress() {
+ protected function processBillingAddress(int $contactID, string $email): void {
$fields = [];
$fields['email-Primary'] = 1;
- $this->_params['email-5'] = $this->_params['email-Primary'] = $this->_contributorEmail;
+ $this->_params['email-5'] = $this->_params['email-Primary'] = $email;
// now set the values for the billing location.
foreach (array_keys($this->_fields) as $name) {
$fields[$name] = 1;
$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) {
+ if ($contactID == $this->_contactID) {
$fields["email-{$this->_bltID}"] = 1;
}
}
//here we are setting up the billing contact - if different from the member they are already created
// but they will get billing details assigned
- $addressParams['contact_id'] = $this->_contributorContactID;
+ $addressParams['contact_id'] = $contactID;
CRM_Contact_BAO_Contact::createProfileContact($addressParams, $fields,
- $this->_contributorContactID, NULL, NULL,
- CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contributorContactID, 'contact_type')
+ $contactID, NULL, NULL,
+ CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type')
);
}
public function submit($submittedValues) {
$this->_params = $submittedValues;
$this->beginPostProcess();
+ // _contributorContactID may no longer need to be set - setting it here
+ // was for use in processBillingAddress
$this->_contributorContactID = $this->_contactID;
- $this->processBillingAddress();
+ $this->processBillingAddress($this->_contactID, (string) $this->_contributorEmail);
$participantId = NULL;
if ($this->_component === 'event') {
$participantId = $this->_id;
$now = date('YmdHis');
- $this->_contributorEmail = $this->getContactValue('email_primary.email');
- $this->_contributorContactID = $contactID;
- $this->processBillingAddress();
+ $this->processBillingAddress($contactID, (string) $this->getContactValue('email_primary.email'));
if (!empty($params['source'])) {
unset($params['source']);
}
$this->beginPostProcess();
$now = CRM_Utils_Date::getToday(NULL, 'YmdHis');
$this->assign('receive_date', CRM_Utils_Array::value('receive_date', $this->_params, CRM_Utils_Time::date('Y-m-d H:i:s')));
- $this->processBillingAddress();
+ $this->processBillingAddress($this->getContributionContactID(), (string) $this->_contributorEmail);
$this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params,
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee')