public function onSearchAvailablePayment( object $payment, string $group ) : bool

Fires while checking whether a payment gateway can be used or not.


Description

Trigger hook to let external plugins apply additional filters while searching for a compatible payment gateway. The filter applies once for each payment gateway separately.

When this hook is triggered, the system already validated the standard conditions and the payment gateway has been approved for the usage.

In case the payment is discarded, it won't be reported within the selection list of payments.


Parameters

$payment

(object)  An object holding the details of the payment to check.

$group

(string)  The section in which the customer is paying ("restaurant" or "takeaway").

Return Value

Boolean. Use false to discard the payment gateway.


Example

The example below automatically turns off a specific payment during Summer.

/**
 * Trigger event to let external plugins apply additional filters while 
 * searching for a compatible payment gateway.
 * The hook will be executed only in case all the other filters
 * accepted the payment for the usage.
 *
 * @param   object  $payment  The payment database record.
 * @param   string  $group    The group to check ("restaurant" or "takeaway").
 *
 * @return  bool    True to accept the payment, false to discard it.
 */
public function onSearchAvailablePayment($payment, $group)
{
    if ($payment->id != 5) {
        // go ahead
        return false;
    }

    // payment found, get current month
    $mon = (int) date('n');

    // make sure we are not in Summer
    if (in_array($mon, [6, 7, 8]) {
        // discard payment
        return false;
    }

    return true;
}

Changelog

Version Description
1.9 The $group argument has been changed from int to string and the accepted types have been changed accordingly: 1 in "restaurant"; 2 in "takeaway".
Removed the $user and $total arguments as they were out of context.
1.8.3 Introduced.
Last Update: 2023-12-29 14:15
Helpful?
See Also: