protected $fromEmailId = NULL;
- protected $_fromEmails = NULL;
-
protected $_view = NULL;
public $_action = NULL;
CRM_Utils_System::setTitle($title);
return;
}
- $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
-
$entityType = 'contribution';
if ($this->_component == 'event') {
$entityType = 'participant';
$this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id');
$eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
- $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId);
}
else {
$this->_contributionId = $this->_id;
- $this->_fromEmails['from_email_id'] = CRM_Core_BAO_Email::getFromEmail();
}
- $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $entityType);
$paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE);
+ $paymentAmt = CRM_Contribute_BAO_Contribution::getContributionBalance($this->_id);
$this->_amtPaid = $paymentDetails['paid'];
$this->_amtTotal = $paymentDetails['total'];
- if (!empty($paymentInfo['refund_due'])) {
- $paymentAmt = $this->_refund = $paymentInfo['refund_due'];
+ if ($paymentAmt < 0) {
+ $this->_refund = $paymentAmt;
$this->_paymentType = 'refund';
}
- elseif (!empty($paymentInfo['amount_owed'])) {
- $paymentAmt = $this->_owed = $paymentInfo['amount_owed'];
+ elseif ($paymentAmt > 0) {
+ $this->_owed = $paymentAmt;
$this->_paymentType = 'owed';
}
else {
//add receipt for offline contribution
$this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
- $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']);
+ if ($this->_component === 'event') {
+ $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
+ }
+
+ $this->add('select', 'from_email_address', ts('Receipt From'), CRM_Financial_BAO_Payment::getValidFromEmailsForPayment($eventID ?? NULL));
$this->add('textarea', 'receipt_text', ts('Confirmation Message'));
$this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
}
- $buttonName = $this->_refund ? 'Record Refund' : 'Record Payment';
+ $buttonName = $this->_refund ? ts('Record Refund') : ts('Record Payment');
$this->addButtons([
[
'type' => 'upload',
- 'name' => ts('%1', [1 => $buttonName]),
+ 'name' => $buttonName,
'js' => $js,
'isDefault' => TRUE,
],
/**
* Process Payments.
+ *
* @param array $submittedValues
*
+ * @throws \CiviCRM_API3_Exception
*/
public function submit($submittedValues) {
$this->_params = $submittedValues;
if ($this->_component == 'event') {
$participantId = $this->_id;
}
- $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution',
- 'contribution_status_id',
- ['labelColumn' => 'name']
- );
- $contributionStatusID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_contributionId, 'contribution_status_id');
- if ($contributionStatuses[$contributionStatusID] == 'Pending') {
- civicrm_api3('Contribution', 'create',
- [
- 'id' => $this->_contributionId,
- 'contribution_status_id' => array_search('Partially paid', $contributionStatuses),
- 'is_pay_later' => 0,
- ]
- );
- }
if ($this->_mode) {
// process credit card
$statusMsg = ts('The payment record has been processed.');
// send email
if (!empty($paymentID) && !empty($this->_params['is_email_receipt'])) {
- $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $paymentID])['values'][$paymentID];
+ $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $paymentID, 'from' => $submittedValues['from_email_address']])['values'][$paymentID];
if ($sendResult['is_sent']) {
$statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
}
$this->assign('displayName', $this->userDisplayName);
}
- $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
// function to get correct amount level consistently. Remove setting of the amount level in
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
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));
+ CRM_Core_Error::statusBounce($e->getMessage(), CRM_Utils_System::url('civicrm/payment/add', $urlParams));
}
}
if (!empty($params['contribution_id'])) {
$this->_contributionId = $params['contribution_id'];
- $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_contributionId, $entityType);
$paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_contributionId, $entityType, FALSE, TRUE);
+ $paymentAmount = CRM_Contribute_BAO_Contribution::getContributionBalance($this->_contributionId);
$this->_amtPaid = $paymentDetails['paid'];
$this->_amtTotal = $paymentDetails['total'];
- if (!empty($paymentInfo['refund_due'])) {
- $this->_refund = $paymentInfo['refund_due'];
+ if ($paymentAmount < 0) {
+ $this->_refund = $paymentAmount;
$this->_paymentType = 'refund';
}
- elseif (!empty($paymentInfo['amount_owed'])) {
- $this->_owed = $paymentInfo['amount_owed'];
+ elseif ($paymentAmount > 0) {
+ $this->_owed = $paymentAmount;
$this->_paymentType = 'owed';
}
}