foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) {
if ($payment_processor_id == NULL && $event_in_cart->event->payment_processor != NULL) {
$payment_processor_id = $event_in_cart->event->payment_processor;
- $this->financial_type_id = $event_in_cart->event->financial_type_id;
+ $this->financial_type_id = $event_in_cart->event->financial_type_id;
}
else {
if ($event_in_cart->event->payment_processor != NULL && $event_in_cart->event->payment_processor != $payment_processor_id) {
CRM_Price_BAO_PriceSet::processAmount($price_set['fields'], $event_price_values, $price_set_amount);
$cost = $event_price_values['amount'];
$amount_level = $event_price_values['amount_level'];
+ $price_details[$price_set_id] = $price_set_amount;
}
// iterate over each participant in event
foreach ($event_in_cart->participants as & $participant) {
$participant->cost = $cost;
$participant->fee_level = $amount_level;
+ $participant->price_details = $price_details;
}
$this->add_line_item($event_in_cart, $class);
function postProcess() {
$transaction = new CRM_Core_Transaction();
- $trxn = NULL;
+ $trxnDetails = NULL;
$params = $this->_submitValues;
$main_participants = $this->cart->get_main_event_participants();
$params['now'] = date('YmdHis');
$params['invoiceID'] = md5(uniqid(rand(), TRUE));
$params['amount'] = $this->total;
- $params['financial_type_id'] = $this->financial_type_id;
+ $params['financial_type_id'] = $this->financial_type_id;
if ($this->payment_required && empty($params['is_pay_later'])) {
- $trxn = $this->make_payment($params);
- $params['trxn_id'] = $trxn->trxn_id;
- $params['trxn_date'] = $trxn->trxn_date;
- $params['currencyID'] = $trxn->currency;
- $params['financial_trxn_id'] = $trxn->id;
+ $trxnDetails = $this->make_payment($params);
+ $params['trxn_id'] = $trxnDetails['trxn_id'];
+ $params['trxn_date'] = $trxnDetails['trxn_date'];
+ $params['currencyID'] = $trxnDetails['currency'];
}
$this->cart->completed = TRUE;
$this->cart->save();
$params['participant_status'] = 'Registered';
$params['is_pay_later'] = 0;
}
- if ($trxn == NULL) {
+ if ($trxnDetails == NULL) {
$params['trxn_id'] = $trxn_prefix . strftime("%Y%m%d%H%M%S");
$params['trxn_date'] = $params['now'];
}
$this->registerParticipant($params, $mer_participant, $event_in_cart->event);
}
else {
- // XXX move
$params['amount'] = $mer_participant->cost - $mer_participant->discount_amount;
- if ($event_in_cart->event->financial_type_id && $mer_participant->cost) {
- $params['financial_type_id'] = $event_in_cart->event->financial_type_id;
+ if ($event_in_cart->event->financial_type_id && $mer_participant->cost) {
+ $params['financial_type_id'] = $event_in_cart->event->financial_type_id;
$params['participant_contact_id'] = $mer_participant->contact_id;
- $this->record_contribution($mer_participant, $params, $event_in_cart->event);
+ $contribution = $this->record_contribution($mer_participant, $params, $event_in_cart->event );
+ // Record civicrm_line_item
+ CRM_Price_BAO_LineItem::processPriceSet($mer_participant->id, $mer_participant->price_details, $contribution, $entity_table = 'civicrm_participant');
}
$this->registerParticipant($params, $mer_participant, $event_in_cart->event);
}
elseif (!$result['trxn_id']) {
CRM_Core_Error::fatal(ts("Financial institution didn't return a transaction id."));
}
-
- $trxnParams = array(
- 'trxn_date' => $params['now'],
- 'trxn_type' => 'Debit',
- 'total_amount' => $params['amount'],
- 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result),
- 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']),
- 'currency' => CRM_Utils_Array::value('currencyID', $params),
- 'payment_processor' => $this->_paymentProcessor['payment_processor_type'],
+ $trxnDetails = array(
'trxn_id' => $result['trxn_id'],
+ 'trxn_date' => $result['now'],
+ 'currency' => CRM_Utils_Array::value('currencyID', $result),
);
- $trxn = new CRM_Financial_DAO_FinancialTrxn();
- $trxn->copyValues($trxnParams);
- if (!CRM_Utils_Rule::currencyCode($trxn->currency)) {
- $config = CRM_Core_Config::singleton();
- $trxn->currency = $config->defaultCurrency;
- }
- $trxn->save();
-
- return $trxn;
+ return $trxnDetails;
}
function record_contribution(&$mer_participant, &$params, $event) {
'receive_date' => $params['now'],
'total_amount' => $params['amount'],
'amount_level' => $mer_participant->fee_level,
- 'fee_amount' => $mer_participant->cost,
'net_amount' => $params['amount'],
'invoice_id' => "{$params['invoiceID']}-{$this->sub_trxn_index}",
'trxn_id' => "{$params['trxn_id']}-{$this->sub_trxn_index}",
'contribution_status_id' => $params['contribution_status_id'],
'payment_instrument_id' => $params['payment_instrument_id'],
'check_number' => CRM_Utils_Array::value('check_number', $params),
+ 'skipLineItem' => 1,
);
- $contribution = &CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
+ if (is_array($this->_paymentProcessor)) {
+ $contribParams['payment_processor'] = $this->_paymentProcessor['id'];
+ }
+
+ $contribution = &CRM_Contribute_BAO_Contribution::add($contribParams);
if (is_a($contribution, 'CRM_Core_Error')) {
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\n", array(1 => $contribution->getMessages($contribution))));
}
$mer_participant->contribution_id = $contribution->id;
$params['contributionID'] = $contribution->id;
- $params['receive_date'] = $contribution->receive_date;
- if (!empty($params['financial_trxn_id'])) {
- $entity_financial_trxn_params = array(
- 'entity_table' => "civicrm_contribution",
- 'entity_id' => $contribution->id,
- 'financial_trxn_id' => $params['financial_trxn_id'],
- 'amount' => $params['amount'],
- 'currency' => CRM_Utils_Array::value('currencyID', $params),
- );
- $entity_trxn =& new CRM_Financial_DAO_EntityFinancialTrxn();
- $entity_trxn->copyValues($entity_financial_trxn_params);
- $entity_trxn->save();
- }
+
+ return $contribution;
}
function saveDataToSession() {