private function wf_crm_webform_postprocess::createBillingContact in Webform CiviCRM Integration 7.4
Same name and namespace in other branches
- 7.5 includes/wf_crm_webform_postprocess.inc \wf_crm_webform_postprocess::createBillingContact()
Create contact 1 if not already existing (required by contribution.transact)
Return value
int
1 call to wf_crm_webform_postprocess::createBillingContact()
- wf_crm_webform_postprocess::validate in includes/
wf_crm_webform_postprocess.inc - Called after a webform is submitted Or, for a multipage form, called after each page
File
- includes/
wf_crm_webform_postprocess.inc, line 1698
Class
Code
private function createBillingContact() {
$cid = wf_crm_aval($this->existing_contacts, 1);
if (!$cid) {
$contact = $this->data['contact'][1];
// Only use middle name from billing if we are using the rest of the billing name as well
if (empty($contact['contact'][1]['first_name']) && !empty($this->billing_params['middle_name'])) {
$contact['contact'][1]['middle_name'] = $this->billing_params['middle_name'];
}
$contact['contact'][1] += array(
'first_name' => $this->billing_params['first_name'],
'last_name' => $this->billing_params['last_name'],
);
$cid = $this
->findDuplicateContact($contact);
}
$address = array(
'street_address' => $this->billing_params['street_address'],
'city' => $this->billing_params['city'],
'country_id' => $this->billing_params['country_id'],
'state_province_id' => wf_crm_aval($this->billing_params, 'state_province_id'),
'postal_code' => $this->billing_params['postal_code'],
'location_type_id' => 'Billing',
);
$email = array(
'email' => $this->billing_params['email'],
'location_type_id' => 'Billing',
);
if (!$cid) {
$cid = $this
->createContact($contact);
}
else {
foreach (array(
'address',
'email',
) as $loc) {
$result = wf_civicrm_api($loc, 'get', array(
'contact_id' => $cid,
'location_type_id' => 'Billing',
));
// Use first id if we have any results
if (!empty($result['values'])) {
$ids = array_keys($result['values']);
${$loc}['id'] = $ids[0];
}
}
}
if ($cid) {
$address['contact_id'] = $email['contact_id'] = $this->ent['contact'][1]['id'] = $cid;
wf_civicrm_api('address', 'create', $address);
wf_civicrm_api('email', 'create', $email);
}
return $cid;
}