4 * Class CRM_Event_Cart_Form_Checkout_Payment
6 class CRM_Event_Cart_Form_Checkout_Payment
extends CRM_Event_Cart_Form_Cart
{
7 public $all_participants;
8 public $financial_type_id;
11 public $_fields = array();
12 public $_paymentProcessor;
15 public $payment_required = TRUE;
16 public $payer_contact_id;
17 public $is_pay_later = FALSE;
18 public $pay_later_receipt;
21 * @param array $params
27 public function registerParticipant($params, &$participant, $event) {
28 $transaction = new CRM_Core_Transaction();
30 // handle register date CRM-4320
31 $registerDate = date('YmdHis');
32 $participantParams = array(
33 'id' => $participant->id
,
34 'event_id' => $event->id
,
35 'register_date' => $registerDate,
36 'source' => CRM_Utils_Array
::value('participant_source', $params, $this->description
),
37 //'fee_level' => $participant->fee_level,
38 'is_pay_later' => $this->is_pay_later
,
39 'fee_amount' => CRM_Utils_Array
::value('amount', $params, 0),
40 //XXX why is this a ref to participant and not contact?:
41 //'registered_by_id' => $this->payer_contact_id,
42 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
45 if ($participant->must_wait
) {
46 $participant_status = 'On waitlist';
48 elseif (CRM_Utils_Array
::value('is_pay_later', $params, FALSE)) {
49 $participant_status = 'Pending from pay later';
52 $participant_status = 'Registered';
54 $participant_statuses = CRM_Event_PseudoConstant
::participantStatus();
55 $participantParams['status_id'] = array_search($participant_status, $participant_statuses);
56 $participant_status_label = CRM_Utils_Array
::value($participantParams['status_id'], CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'));
57 $participantParams['participant_status'] = $participant_status_label;
59 $this->assign('isOnWaitlist', $participant->must_wait
);
61 if ($this->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
62 $participantParams['is_test'] = 1;
65 $participantParams['is_test'] = 0;
68 if (self
::is_administrator()) {
69 if (!empty($params['note'])) {
71 'participant_id' => $participant->id
,
72 'contact_id' => self
::getContactID(),
73 'note' => $params['note'],
75 CRM_Event_BAO_Participant
::update_note($note_params);
79 $participant->copyValues($participantParams);
82 if (!empty($params['contributionID'])) {
83 $payment_params = array(
84 'participant_id' => $participant->id
,
85 'contribution_id' => $params['contributionID'],
88 $paymentParticpant = CRM_Event_BAO_ParticipantPayment
::create($payment_params, $ids);
91 $transaction->commit();
93 $event_values = array();
94 CRM_Core_DAO
::storeValues($event, $event_values);
97 if (CRM_Utils_Array
::value('is_show_location', $event_values) == 1) {
98 $locationParams = array(
99 'entity_id' => $participant->event_id
,
100 'entity_table' => 'civicrm_event',
102 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
103 CRM_Core_BAO_Address
::fixAddress($location['address'][1]);
106 list($pre_id, $post_id) = CRM_Event_Cart_Form_MerParticipant
::get_profile_groups($participant->event_id
);
107 $payer_values = array(
111 if ($this->payer_contact_id
) {
112 $payer_contact_details = CRM_Contact_BAO_Contact
::getContactDetails($this->payer_contact_id
);
113 $payer_values = array(
114 'email' => $payer_contact_details[1],
115 'name' => $payer_contact_details[0],
119 'params' => array($participant->id
=> $participantParams),
120 'event' => $event_values,
121 'location' => $location,
122 'custom_pre_id' => $pre_id,
123 'custom_post_id' => $post_id,
124 'payer' => $payer_values,
126 CRM_Event_BAO_Event
::sendMail($participant->contact_id
, $values, $participant->id
);
131 public function buildPaymentFields() {
132 $payment_processor_id = NULL;
133 $can_pay_later = TRUE;
134 $pay_later_text = "";
135 $this->pay_later_receipt
= "";
136 foreach ($this->cart
->get_main_events_in_carts() as $event_in_cart) {
137 if ($payment_processor_id == NULL && $event_in_cart->event
->payment_processor
!= NULL) {
138 $payment_processor_id = $event_in_cart->event
->payment_processor
;
139 $this->financial_type_id
= $event_in_cart->event
->financial_type_id
;
142 if ($event_in_cart->event
->payment_processor
!= NULL && $event_in_cart->event
->payment_processor
!= $payment_processor_id) {
143 CRM_Core_Error
::statusBounce(ts('When registering for multiple events all events must use the same payment processor. '));
146 if (!$event_in_cart->event
->is_pay_later
) {
147 $can_pay_later = FALSE;
151 $pay_later_text = $event_in_cart->event
->pay_later_text
;
152 $this->pay_later_receipt
= $event_in_cart->event
->pay_later_receipt
;
156 if ($payment_processor_id == NULL) {
157 CRM_Core_Error
::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'));
160 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($payment_processor_id, $this->_mode
);
161 $this->assign('paymentProcessor', $this->_paymentProcessor
);
163 CRM_Core_Payment_Form
::buildPaymentForm($this, $this->_paymentProcessor
, FALSE);
165 if ($can_pay_later || self
::is_administrator()) {
166 $this->addElement('checkbox', 'is_pay_later',
169 $this->addElement('checkbox', 'payment_completed',
170 ts('Payment Completed')
172 $this->assign('pay_later_instructions', $this->pay_later_receipt
);
176 public function buildQuickForm() {
178 $this->line_items
= array();
179 $this->sub_total
= 0;
180 $this->_price_values
= $this->getValuesForPage('ParticipantsAndPrices');
182 // iterate over each event in cart
183 foreach ($this->cart
->get_main_events_in_carts() as $event_in_cart) {
184 $this->process_event_line_item($event_in_cart);
185 foreach ($this->cart
->get_events_in_carts_by_main_event_id($event_in_cart->event_id
) as $subevent) {
186 $this->process_event_line_item($subevent, 'subevent');
190 $this->total
= $this->sub_total
;
191 $this->payment_required
= ($this->total
> 0);
192 $this->assign('payment_required', $this->payment_required
);
193 $this->assign('line_items', $this->line_items
);
194 $this->assign('sub_total', $this->sub_total
);
195 $this->assign('total', $this->total
);
198 'name' => ts('Go Back'),
199 'spacing' => '  ',
204 'name' => ts('Complete Transaction'),
205 'spacing' => ' ',
210 $this->add('text', 'billing_contact_email', 'Billing Email', '', TRUE);
211 $this->assign('collect_billing_email', TRUE);
213 if (self
::is_administrator()) {
214 $this->add('textarea', 'note', 'Note');
215 $this->add('text', 'source', 'Source', array('size' => 80));
216 $instruments = array();
217 CRM_Core_OptionGroup
::getAssoc('payment_instrument', $instruments, TRUE);
219 foreach ($instruments as $type) {
220 $options[] = $this->createElement('radio', NULL, '', $type['label'], $type['value']);
222 $this->addGroup($options, 'payment_type', ts("Alternative Payment Type"));
223 $this->add('text', 'check_number', ts('Check No.'), array('size' => 20));
224 $this->addElement('checkbox', 'is_pending', ts('Create a pending registration'));
226 $this->assign('administrator', TRUE);
228 $this->addButtons($buttons);
230 $this->addFormRule(array('CRM_Event_Cart_Form_Checkout_Payment', 'formRule'), $this);
232 if ($this->payment_required
) {
233 $this->buildPaymentFields();
238 * @param $event_in_cart
241 public function process_event_line_item(&$event_in_cart, $class = NULL) {
243 $price_set_id = CRM_Price_BAO_PriceSet
::getFor("civicrm_event", $event_in_cart->event_id
);
244 $amount_level = NULL;
246 $event_price_values = array();
247 foreach ($this->_price_values
as $key => $value) {
248 if (preg_match("/event_{$event_in_cart->event_id}_(price.*)/", $key, $matches)) {
249 $event_price_values[$matches[1]] = $value;
252 $price_sets = CRM_Price_BAO_PriceSet
::getSetDetail($price_set_id, TRUE);
253 $price_set = $price_sets[$price_set_id];
254 $price_set_amount = array();
255 CRM_Price_BAO_PriceSet
::processAmount($price_set['fields'], $event_price_values, $price_set_amount);
256 $cost = $event_price_values['amount'];
257 $amount_level = $event_price_values['amount_level'];
258 $price_details[$price_set_id] = $price_set_amount;
261 // iterate over each participant in event
262 foreach ($event_in_cart->participants
as & $participant) {
263 $participant->cost
= $cost;
264 $participant->fee_level
= $amount_level;
265 $participant->price_details
= $price_details;
268 $this->add_line_item($event_in_cart, $class);
272 * @param $event_in_cart
275 public function add_line_item($event_in_cart, $class = NULL) {
278 $not_waiting_participants = array();
279 foreach ($event_in_cart->not_waiting_participants() as $participant) {
280 $amount +
= $participant->cost
;
281 $cost = max($cost, $participant->cost
);
282 $not_waiting_participants[] = array(
283 'display_name' => CRM_Contact_BAO_Contact
::displayName($participant->contact_id
),
286 $waiting_participants = array();
287 foreach ($event_in_cart->waiting_participants() as $participant) {
288 $waiting_participants[] = array(
289 'display_name' => CRM_Contact_BAO_Contact
::displayName($participant->contact_id
),
292 $this->line_items
[] = array(
295 'event' => $event_in_cart->event
,
296 'participants' => $not_waiting_participants,
297 'num_participants' => count($not_waiting_participants),
298 'num_waiting_participants' => count($waiting_participants),
299 'waiting_participants' => $waiting_participants,
303 $this->sub_total +
= $amount;
309 public function getDefaultFrom() {
310 $values = CRM_Core_OptionGroup
::values('from_email_address');
315 * @param $events_in_cart
316 * @param array $params
318 public function emailReceipt($events_in_cart, $params) {
319 $contact_details = CRM_Contact_BAO_Contact
::getContactDetails($this->payer_contact_id
);
320 $state_province = new CRM_Core_DAO_StateProvince();
321 $state_province->id
= $params["billing_state_province_id-{$this->_bltID}"];
322 $state_province->find();
323 $state_province->fetch();
324 $country = new CRM_Core_DAO_Country();
325 $country->id
= $params["billing_country_id-{$this->_bltID}"];
328 foreach ($this->line_items
as & $line_item) {
329 $location_params = array('entity_id' => $line_item['event']->id
, 'entity_table' => 'civicrm_event');
330 $line_item['location'] = CRM_Core_BAO_Location
::getValues($location_params, TRUE);
331 CRM_Core_BAO_Address
::fixAddress($line_item['location']['address'][1]);
333 $send_template_params = array(
334 'table' => 'civicrm_msg_template',
335 'contactId' => $this->payer_contact_id
,
336 'from' => $this->getDefaultFrom(),
337 'groupName' => 'msg_tpl_workflow_event',
339 'toEmail' => $contact_details[1],
340 'toName' => $contact_details[0],
341 'tplParams' => array(
342 'billing_name' => "{$params['billing_first_name']} {$params['billing_last_name']}",
343 'billing_city' => $params["billing_city-{$this->_bltID}"],
344 'billing_country' => $country->name
,
345 'billing_postal_code' => $params["billing_postal_code-{$this->_bltID}"],
346 'billing_state' => $state_province->abbreviation
,
347 'billing_street_address' => $params["billing_street_address-{$this->_bltID}"],
348 'credit_card_exp_date' => $params['credit_card_exp_date'],
349 'credit_card_type' => $params['credit_card_type'],
350 'credit_card_number' => "************" . substr($params['credit_card_number'], -4, 4),
351 // XXX cart->get_discounts
352 'discounts' => $this->discounts
,
353 'email' => $contact_details[1],
354 'events_in_cart' => $events_in_cart,
355 'line_items' => $this->line_items
,
356 'name' => $contact_details[0],
357 'transaction_id' => $params['trxn_id'],
358 'transaction_date' => $params['trxn_date'],
359 'is_pay_later' => $this->is_pay_later
,
360 'pay_later_receipt' => $this->pay_later_receipt
,
362 'valueName' => 'event_registration_receipt',
363 'PDFFilename' => ts('confirmation') . '.pdf',
365 $template_params_to_copy = array(
369 'billing_postal_code',
371 'billing_street_address',
372 'credit_card_exp_date',
374 'credit_card_number',
376 foreach ($template_params_to_copy as $template_param_to_copy) {
377 $this->set($template_param_to_copy, $send_template_params['tplParams'][$template_param_to_copy]);
380 CRM_Core_BAO_MessageTemplate
::sendTemplate($send_template_params);
390 public static function formRule($fields, $files, $self) {
393 if ($self->payment_required
&& empty($self->_submitValues
['is_pay_later'])) {
394 $payment = CRM_Core_Payment
::singleton($self->_mode
, $self->_paymentProcessor
, CRM_Core_DAO
::$_nullObject);
395 $error = $payment->checkConfig($self->_mode
);
397 $errors['_qf_default'] = $error;
399 CRM_Core_Form
::validateMandatoryFields($self->_fields
, $fields, $errors);
401 // validate payment instrument values (e.g. credit card number)
402 CRM_Core_Payment_Form
::validatePaymentInstrument($self->_paymentProcessor
['id'], $fields, $errors, $self);
405 return empty($errors) ?
TRUE : $errors;
411 public function validate() {
412 if ($this->is_pay_later
) {
413 $this->_fields
['credit_card_number']['is_required'] = FALSE;
414 $this->_fields
['cvv2']['is_required'] = FALSE;
415 $this->_fields
['credit_card_exp_date']['is_required'] = FALSE;
416 $this->_fields
['credit_card_type']['is_required'] = FALSE;
418 return parent
::validate();
421 public function preProcess() {
422 $params = $this->_submitValues
;
423 $this->is_pay_later
= CRM_Utils_Array
::value('is_pay_later', $params, FALSE) && !CRM_Utils_Array
::value('payment_completed', $params);
425 parent
::preProcess();
428 public function postProcess() {
430 $transaction = new CRM_Core_Transaction();
432 $params = $this->_submitValues
;
434 $main_participants = $this->cart
->get_main_event_participants();
435 foreach ($main_participants as $participant) {
437 $ids = array('contact_id' => $participant->contact_id
);
438 $contact = CRM_Contact_BAO_Contact
::retrieve($ids, $defaults);
439 $contact->is_deleted
= 0;
444 if (array_key_exists('billing_contact_email', $params)) {
445 $this->payer_contact_id
= self
::find_or_create_contact($this->getContactID(), array(
446 'email' => $params['billing_contact_email'],
447 'first_name' => $params['billing_first_name'],
448 'last_name' => $params['billing_last_name'],
449 'is_deleted' => FALSE,
452 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
453 $this->payer_contact_id
,
456 $billing_fields = array(
457 "billing_first_name" => 1,
458 "billing_middle_name" => 1,
459 "billing_last_name" => 1,
460 "billing_street_address-{$this->_bltID}" => 1,
461 "billing_city-{$this->_bltID}" => 1,
462 "billing_state_province_id-{$this->_bltID}" => 1,
463 "billing_postal_code-{$this->_bltID}" => 1,
464 "billing_country_id-{$this->_bltID}" => 1,
465 "address_name-{$this->_bltID}" => 1,
466 "email-{$this->_bltID}" => 1,
469 $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);
471 $params["email-{$this->_bltID}"] = $params['billing_contact_email'];
472 CRM_Contact_BAO_Contact
::createProfileContact(
475 $this->payer_contact_id
,
483 $params['now'] = date('YmdHis');
484 $params['invoiceID'] = md5(uniqid(rand(), TRUE));
485 $params['amount'] = $this->total
;
486 $params['financial_type_id'] = $this->financial_type_id
;
487 if ($this->payment_required
&& empty($params['is_pay_later'])) {
488 $trxnDetails = $this->make_payment($params);
489 $params['trxn_id'] = $trxnDetails['trxn_id'];
490 $params['trxn_date'] = $trxnDetails['trxn_date'];
491 $params['currencyID'] = $trxnDetails['currency'];
493 $this->cart
->completed
= TRUE;
495 $this->set('last_event_cart_id', $this->cart
->id
);
497 $contribution_statuses = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
498 $params['payment_instrument_id'] = NULL;
499 if (!empty($params['is_pay_later'])) {
500 $params['payment_instrument_id'] = CRM_Core_OptionGroup
::getValue('payment_instrument', 'Check', 'name');
504 $params['payment_instrument_id'] = CRM_Core_OptionGroup
::getValue('payment_instrument', 'Credit Card', 'name');
506 if ($this->is_pay_later
&& empty($params['payment_completed'])) {
507 $params['contribution_status_id'] = array_search('Pending', $contribution_statuses);
510 $params['contribution_status_id'] = array_search('Completed', $contribution_statuses);
511 $params['participant_status'] = 'Registered';
512 $params['is_pay_later'] = 0;
514 if ($trxnDetails == NULL) {
515 $params['trxn_id'] = $trxn_prefix . strftime("%Y%m%d%H%M%S");
516 $params['trxn_date'] = $params['now'];
519 if ($this->payment_required
) {
520 $this->emailReceipt($this->cart
->events_in_carts
, $params);
523 // n.b. we need to process the subparticipants before main event
524 // participants so that session attendance can be included in the email
525 $main_participants = $this->cart
->get_main_event_participants();
526 $this->all_participants
= array();
527 foreach ($main_participants as $main_participant) {
528 $this->all_participants
= array_merge($this->all_participants
, $this->cart
->get_subparticipants($main_participant));
530 $this->all_participants
= array_merge($this->all_participants
, $main_participants);
532 $this->sub_trxn_index
= 0;
533 foreach ($this->all_participants
as $mer_participant) {
534 $event_in_cart = $this->cart
->get_event_in_cart_by_event_id($mer_participant->event_id
);
536 $this->sub_trxn_index +
= 1;
538 unset($params['contributionID']);
539 if ($mer_participant->must_wait
) {
540 $this->registerParticipant($params, $mer_participant, $event_in_cart->event
);
543 $params['amount'] = $mer_participant->cost
- $mer_participant->discount_amount
;
545 if ($event_in_cart->event
->financial_type_id
&& $mer_participant->cost
) {
546 $params['financial_type_id'] = $event_in_cart->event
->financial_type_id
;
547 $params['participant_contact_id'] = $mer_participant->contact_id
;
548 $contribution = $this->record_contribution($mer_participant, $params, $event_in_cart->event
);
549 // Record civicrm_line_item
550 CRM_Price_BAO_LineItem
::processPriceSet($mer_participant->id
, $mer_participant->price_details
, $contribution, $entity_table = 'civicrm_participant');
552 $this->registerParticipant($params, $mer_participant, $event_in_cart->event
);
555 $this->trxn_id
= $params['trxn_id'];
556 $this->trxn_date
= $params['trxn_date'];
557 $this->saveDataToSession();
558 $transaction->commit();
562 * @param array $params
567 public function make_payment(&$params) {
568 $config = CRM_Core_Config
::singleton();
569 if (isset($params["billing_state_province_id-{$this->_bltID}"]) && $params["billing_state_province_id-{$this->_bltID}"]) {
570 $params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($params["billing_state_province_id-{$this->_bltID}"]);
573 if (isset($params["billing_country_id-{$this->_bltID}"]) && $params["billing_country_id-{$this->_bltID}"]) {
574 $params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($params["billing_country_id-{$this->_bltID}"]);
576 $params['ip_address'] = CRM_Utils_System
::ipAddress();
577 $params['currencyID'] = $config->defaultCurrency
;
578 $params['payment_action'] = 'Sale';
580 $payment = &CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
581 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $params, $params, TRUE);
582 $params['month'] = $params['credit_card_exp_date']['M'];
583 $params['year'] = $params['credit_card_exp_date']['Y'];
584 $result = &$payment->doDirectPayment($params);
585 if (is_a($result, 'CRM_Core_Error')) {
586 CRM_Core_Error
::displaySessionError($result);
587 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/event/cart_checkout', "_qf_Payment_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE));
590 elseif (!$result['trxn_id']) {
591 CRM_Core_Error
::fatal(ts("Financial institution didn't return a transaction id."));
593 $trxnDetails = array(
594 'trxn_id' => $result['trxn_id'],
595 'trxn_date' => $result['now'],
596 'currency' => CRM_Utils_Array
::value('currencyID', $result),
602 * @param $mer_participant
603 * @param array $params
609 public function record_contribution(&$mer_participant, &$params, $event) {
610 if (self
::is_administrator() && !empty($params['payment_type'])) {
611 $params['payment_instrument_id'] = $params['payment_type'];
614 if ($this->payer_contact_id
) {
615 $payer = $this->payer_contact_id
;
617 elseif (self
::getContactID()) {
618 $payer = self
::getContactID();
621 $payer = $params['participant_contact_id'];
624 $contribParams = array(
625 'contact_id' => $payer,
626 'financial_type_id' => $params['financial_type_id'],
627 'receive_date' => $params['now'],
628 'total_amount' => $params['amount'],
629 'amount_level' => $mer_participant->fee_level
,
630 'net_amount' => $params['amount'],
631 'invoice_id' => "{$params['invoiceID']}-{$this->sub_trxn_index}",
632 'trxn_id' => "{$params['trxn_id']}-{$this->sub_trxn_index}",
633 'currency' => CRM_Utils_Array
::value('currencyID', $params),
634 'source' => $event->title
,
635 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
636 'contribution_status_id' => $params['contribution_status_id'],
637 'payment_instrument_id' => $params['payment_instrument_id'],
638 'check_number' => CRM_Utils_Array
::value('check_number', $params),
642 if (is_array($this->_paymentProcessor
)) {
643 $contribParams['payment_processor'] = $this->_paymentProcessor
['id'];
646 $contribution = &CRM_Contribute_BAO_Contribution
::add($contribParams);
647 if (is_a($contribution, 'CRM_Core_Error')) {
648 CRM_Core_Error
::fatal(ts("There was an error creating a contribution record for your event. Please report this error to the webmaster. Details: %1", array(1 => $contribution->getMessages($contribution))));
650 $mer_participant->contribution_id
= $contribution->id
;
651 $params['contributionID'] = $contribution->id
;
653 return $contribution;
656 public function saveDataToSession() {
657 $session_line_items = array();
658 foreach ($this->line_items
as $line_item) {
659 $session_line_item = array();
660 $session_line_item['amount'] = $line_item['amount'];
661 $session_line_item['cost'] = $line_item['cost'];
662 $session_line_item['event_id'] = $line_item['event']->id
;
663 $session_line_items[] = $session_line_item;
665 $this->set('line_items', $session_line_items);
666 $this->set('payment_required', $this->payment_required
);
667 $this->set('is_pay_later', $this->is_pay_later
);
668 $this->set('pay_later_receipt', $this->pay_later_receipt
);
669 $this->set('trxn_id', $this->trxn_id
);
670 $this->set('trxn_date', $this->trxn_date
);
671 $this->set('total', $this->total
);
677 public function setDefaultValues() {
679 $defaults = parent
::setDefaultValues();
681 $config = CRM_Core_Config
::singleton();
682 $default_country = new CRM_Core_DAO_Country();
683 $default_country->iso_code
= $config->defaultContactCountry();
684 $default_country->find(TRUE);
685 $defaults["billing_country_id-{$this->_bltID}"] = $default_country->id
;
687 if (self
::getContactID() && !self
::is_administrator()) {
688 $params = array('id' => self
::getContactID());
689 $contact = CRM_Contact_BAO_Contact
::retrieve($params, $defaults);
691 foreach ($contact->email
as $email) {
692 if ($email['is_billing']) {
693 $defaults["billing_contact_email"] = $email['email'];
696 if (empty($defaults['billing_contact_email'])) {
697 foreach ($contact->email
as $email) {
698 if ($email['is_primary']) {
699 $defaults["billing_contact_email"] = $email['email'];
704 $defaults["billing_first_name"] = $contact->first_name
;
705 $defaults["billing_middle_name"] = $contact->middle_name
;
706 $defaults["billing_last_name"] = $contact->last_name
;
708 $billing_address = CRM_Event_Cart_BAO_MerParticipant
::billing_address_from_contact($contact);
710 if ($billing_address != NULL) {
711 $defaults["billing_street_address-{$this->_bltID}"] = $billing_address['street_address'];
712 $defaults["billing_city-{$this->_bltID}"] = $billing_address['city'];
713 $defaults["billing_postal_code-{$this->_bltID}"] = $billing_address['postal_code'];
714 $defaults["billing_state_province_id-{$this->_bltID}"] = $billing_address['state_province_id'];
715 $defaults["billing_country_id-{$this->_bltID}"] = $billing_address['country_id'];
719 $defaults["source"] = $this->description
;