class CRM_Financial_BAO_Payment

This class contains payment related functions.

Methods

create(array $params)

Function to process additional payment for partial and refund contributions.

static array
sendConfirmation(array $params)

Send an email confirming a payment that has been received.

static array
getValidFromEmailsForPayment(int $eventID = NULL)

Get valid from emails for payment.

static array
loadRelatedEntities(int $id)

Load entities related to the current payment id.

static int
getPaymentContactID(int $contributionID)

No description

static array
getConfirmationTemplateParameters(array $entities)

No description

static array
filterUntestedTemplateVariables(array $params)

Filter out any untested variables.

static bool
isPaymentCompletesContribution(int $contributionID, float $paymentAmount)

Does this payment complete the contribution

static array
getPayableLineItems($params)

Get the line items for the contribution.

static float
getAmountOfLineItemPaid(int $lineItemID)

Get the amount paid so far against this line item.

static 
reverseAllocationsFromPreviousPayment(array $params, int $trxnID)

Reverse the entity financial transactions associated with the cancelled payment.

static int
getNewFinancialItemID(array $lineItem, string $trxn_date, int $contactID, string $currency)

Create a financial items & return the ID.

Details

at line 55
static CRM_Financial_DAO_FinancialTrxn create(array $params)

Function to process additional payment for partial and refund contributions.

This function is called via API payment.create function. All forms that add payments should use this.

Parameters

array $params
  • contribution_id
    • total_amount
    • line_item

Return Value

CRM_Financial_DAO_FinancialTrxn

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception

at line 181
static array sendConfirmation(array $params)

Send an email confirming a payment that has been received.

Parameters

array $params

Return Value

array

Exceptions

CiviCRM_API3_Exception

at line 212
static array getValidFromEmailsForPayment(int $eventID = NULL)

Get valid from emails for payment.

Parameters

int $eventID

Return Value

array

at line 238
static protected array loadRelatedEntities(int $id)

Load entities related to the current payment id.

This gives us all the data we need to send an email confirmation but avoiding getting anything not tested for the confirmations. We retrieve the 'full' event as it has been traditionally assigned in full.

Parameters

int $id

Return Value

array
  • contact = ['id' => x, 'display_name' => y, 'email' => z]
    • event = [.... full event details......]
    • contribution = ['id' => x],
    • payment = [payment info + payment summary info]

Exceptions

CiviCRM_API3_Exception

at line 282
static int getPaymentContactID(int $contributionID)

Parameters

int $contributionID

Return Value

int

Exceptions

CiviCRM_API3_Exception
CiviCRM_API3_Exception

at line 300
static array getConfirmationTemplateParameters(array $entities)

Parameters

array $entities Related entities as an array keyed by the various entities.

Return Value

array Values required for the notification - contact_id - template_variables - event (DAO of event if relevant)

at line 335
static array filterUntestedTemplateVariables(array $params)

Filter out any untested variables.

This just serves to highlight if any variables are added without a unit test also being added.

(if hit then add a unit test for the param & add to this array).

Parameters

array $params

Return Value

array

at line 384
static protected bool isPaymentCompletesContribution(int $contributionID, float $paymentAmount)

Does this payment complete the contribution

Parameters

int $contributionID
float $paymentAmount

Return Value

bool

at line 426
static protected array getPayableLineItems($params)

Get the line items for the contribution.

Retrieve the line items and wrangle the following

  • get the outstanding balance on a line item basis.
  • determine what amount is being paid on this line item - we get the total being paid for the whole contribution and determine the ratio of the balance that is being paid and then assign apply that ratio to each line item.
  • if overrides have been passed in we use those amounts instead.

Parameters

$params

Return Value

array

Exceptions

CiviCRM_API3_Exception

at line 469
static protected float getAmountOfLineItemPaid(int $lineItemID)

Get the amount paid so far against this line item.

Parameters

int $lineItemID

Return Value

float

Exceptions

CiviCRM_API3_Exception

at line 500
static protected reverseAllocationsFromPreviousPayment(array $params, int $trxnID)

Reverse the entity financial transactions associated with the cancelled payment.

The reversals are linked to the new payemnt.

Parameters

array $params
int $trxnID

Exceptions

CiviCRM_API3_Exception

at line 543
static protected int getNewFinancialItemID(array $lineItem, string $trxn_date, int $contactID, string $currency)

Create a financial items & return the ID.

Ideally this will never be called.

However, I hit a scenario in testing where 'something' had created a pending payment with no financial items and that would result in a fatal error without handling here. I failed to replicate & am not investigating via a new test methodology https://github.com/civicrm/civicrm-core/pull/15706

After this is in I will do more digging & once I feel confident new instances are not being created I will add deprecation notices into this function with a view to removing.

However, I think we want to add it in 5.20 as there is a risk of users experiencing an error if there is incorrect data & we need time to ensure that what I hit was not a 'thing. (it might be the demo site data is a bit flawed & that was the issue).

Parameters

array $lineItem
string $trxn_date
int $contactID
string $currency

Return Value

int

Exceptions

CiviCRM_API3_Exception