}
CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, CRM_Utils_Request::retrieve('payment_instrument_id', 'Integer'));
+ $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL);
+
$attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialTrxn');
- $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL);
$label = ($this->_refund) ? ts('Refund Amount') : ts('Payment Amount');
$this->addMoney('total_amount',
$label,
TRUE, 'currency', NULL
);
- $this->add('select', 'payment_instrument_id',
- ts('Payment Method'),
- array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
- FALSE,
- array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
- );
-
- $this->add('text', 'check_number', ts('Check Number'), $attributes['financial_trxn_check_number']);
- $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
-
//add receipt for offline contribution
$this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
$this->assign('component', $this->_component);
$this->assign('email', $this->_contributorEmail);
- $this->add('text', 'fee_amount', ts('Fee Amount'),
- $attributes['fee_amount']
- );
- $this->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
-
- $this->add('text', 'net_amount', ts('Net Amount'),
- $attributes['net_amount']
- );
- $this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
-
$js = NULL;
+ // render backoffice payment fields only on offline mode
if (!$this->_mode) {
$js = array('onclick' => "return verify( );");
+
+ $this->add('select', 'payment_instrument_id',
+ ts('Payment Method'),
+ array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
+ FALSE,
+ array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
+ );
+
+ $this->add('text', 'check_number', ts('Check Number'), $attributes['financial_trxn_check_number']);
+ $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
+
+ $this->add('text', 'fee_amount', ts('Fee Amount'),
+ $attributes['fee_amount']
+ );
+ $this->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
+
+ $this->add('text', 'net_amount', ts('Net Amount'),
+ $attributes['net_amount']
+ );
+ $this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
}
$buttonName = $this->_refund ? 'Record Refund' : 'Record Payment';
public function submit($submittedValues) {
$this->_params = $submittedValues;
$this->beginPostProcess();
+ $this->_contributorContactID = $this->_contactID;
+ $this->processBillingAddress();
$participantId = NULL;
if ($this->_component == 'event') {
$participantId = $this->_id;
if ($this->_mode) {
// process credit card
$this->assign('contributeMode', 'direct');
- $this->processCreditCard($this->_params);
+ $this->processCreditCard();
}
$defaults = array();
CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
}
- /**
- * @param $submittedValues
- */
- public function processCreditCard($submittedValues) {
+ public function processCreditCard() {
$config = CRM_Core_Config::singleton();
$session = CRM_Core_Session::singleton();
- $unsetParams = array(
- 'trxn_id',
- 'payment_instrument_id',
- 'contribution_status_id',
- );
- foreach ($unsetParams as $key) {
- if (isset($submittedValues[$key])) {
- unset($submittedValues[$key]);
- }
- }
-
- // Get the required fields value only.
- $params = $submittedValues;
-
$now = date('YmdHis');
$fields = array();
// we need to retrieve email address
- if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
+ if ($this->_context == 'standalone' && !empty($this->_params['is_email_receipt'])) {
list($this->userDisplayName,
$this->userEmail
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
$this->assign('displayName', $this->userDisplayName);
}
- //set email for primary location.
- $fields['email-Primary'] = 1;
- $params['email-Primary'] = $this->_contributorEmail;
-
- // now set the values for the billing location.
- foreach ($this->_fields as $name => $dontCare) {
- $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;
-
- $ctype = civicrm_api3('Contact', 'getvalue', array(
- 'return' => "contact_type",
- 'id' => $this->_contactId,
- ));
-
- $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;
- }
- }
-
- if (!empty($params['source'])) {
- unset($params['source']);
- }
- $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields,
- $this->_contactId,
- NULL, NULL,
- $ctype
- );
-
- // Add all the additional payment params we need.
- $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}"]);
- $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
+ $this->formatParamsForPaymentProcessor($this->_params);
$this->_params['amount'] = $this->_params['total_amount'];
// @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
$this->_params['receive_date'] = $this->_params['trxn_date'];
}
+ if (empty($this->_params['receive_date'])) {
+ $this->_params['receive_date'] = date('YmdHis');
+ }
+
if (empty($this->_params['invoice_id'])) {
$this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
}
$this->_params['invoiceID'] = $this->_params['invoice_id'];
}
- $this->assignBillingName($params);
$this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
- $params,
+ $this->_params,
$this->_bltID
));
//Add common data to formatted params
+ $params = $this->_params;
CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this);
// at this point we've created a contact and stored its address etc
// all the payment processors expect the name and address to be in the
$paymentParams['contributionPageID'] = NULL;
if (!empty($this->_params['is_email_receipt'])) {
$paymentParams['email'] = $this->_contributorEmail;
- $paymentParams['is_email_receipt'] = 1;
+ $paymentParams['is_email_receipt'] = TRUE;
}
else {
- $paymentParams['is_email_receipt'] = 0;
- $this->_params['is_email_receipt'] = 0;
- }
- if (!empty($this->_params['receive_date'])) {
- $paymentParams['receive_date'] = $this->_params['receive_date'];
- }
- if (!empty($this->_params['receive_date'])) {
- $paymentParams['receive_date'] = $this->_params['receive_date'];
+ $paymentParams['is_email_receipt'] = $this->_params['is_email_receipt'] = FALSE;
}
$result = NULL;
$result = $payment->doPayment($paymentParams);
}
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
- //set the contribution mode.
- $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}";
- if ($this->_mode) {
- $urlParams .= "&mode={$this->_mode}";
- }
- CRM_Core_Error::displaySessionError($result);
- CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/add', $urlParams));
+ Civi::log()->error('Payment processor exception: ' . $e->getMessage());
+ $urlParams = "action=add&cid={$this->_contactId}&id={$this->_contributionId}&component={$this->_component}&mode={$this->_mode}";
+ CRM_Core_Error::statusBounce(CRM_Utils_System::url($e->getMessage(), 'civicrm/payment/add', $urlParams));
}
}
- if ($result) {
+ if (!empty($result)) {
$this->_params = array_merge($this->_params, $result);
}
// email receipt sending
// send message template
if ($this->_component == 'event') {
- $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
- $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
- CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $eventId, $events, $returnProperties);
- $event = $events[$eventId];
- unset($event['start_date']);
- unset($event['end_date']);
+ // fetch event information from participant ID using API
+ $eventId = civicrm_api3('Participant', 'getvalue', array(
+ 'return' => "event_id",
+ 'id' => $this->_id,
+ ));
+ $event = civicrm_api3('Event', 'getsingle', array('id' => $eventId));
$this->assign('event', $event);
$this->assign('isShowLocation', $event['is_show_location']);
// assign payment info here
$paymentConfig['confirm_email_text'] = CRM_Utils_Array::value('confirm_email_text', $params);
$this->assign('paymentConfig', $paymentConfig);
+
+ $this->assign('totalAmount', $this->_amtTotal);
+
$isRefund = ($this->_paymentType == 'refund') ? TRUE : FALSE;
$this->assign('isRefund', $isRefund);
if ($isRefund) {
$this->assign('totalPaid', $this->_amtPaid);
- $this->assign('totalAmount', $this->_amtTotal);
$this->assign('refundAmount', $params['total_amount']);
}
else {
$balance = $this->_amtTotal - ($this->_amtPaid + $params['total_amount']);
$paymentsComplete = ($balance == 0) ? 1 : 0;
$this->assign('amountOwed', $balance);
- $this->assign('totalAmount', $this->_amtTotal);
$this->assign('paymentAmount', $params['total_amount']);
$this->assign('paymentsComplete', $paymentsComplete);
}
// assign trxn details
$this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $params));
$this->assign('receive_date', CRM_Utils_Array::value('trxn_date', $params));
- $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
- if (array_key_exists('payment_instrument_id', $params)) {
- $this->assign('paidBy',
- CRM_Utils_Array::value($params['payment_instrument_id'],
- $paymentInstrument
- )
- );
- }
+ $this->assign('paidBy', CRM_Core_PseudoConstant::getLabel(
+ 'CRM_Contribute_BAO_Contribute',
+ 'payment_instrument_id',
+ $params['payment_instrument_id']
+ ));
$this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
$sendTemplateParams = array(
}
$this->_fields = array();
+ $this->set('cid', $this->_contactId);
+ parent::preProcess();
$this->submit($params);
}