public function onManipulateAvailablePaymentMethods(array &$payments, string $group, array $options) : void

Fires before returning the available methods of payment.


Description

Trigger hook to allow the plugins to manipulate the list containing all the payment methods that are going to be displayed.

Here it is possible to discard specific payments or even add new ones at runtime.


Parameters

&$payments

(array)  An array of available payments (objects).

$group

(string)  The group to which the payments belong (appointments, packages or subscriptions).

$options

(array)  An array of options to filter the payments.

  • id_employee - takes only the payments assigned to the specified employee (for appointments group only);
  • strict - validates the publishing options of the payment (by default it relies on the current client section).

Return Value

None.


Example

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

/**
 * Trigger event to allow the plugins to manipulate the list containing
 * all the payment methods that are going to be displayed.
 *
 * @param   array   &$payments  An array of available payments.
 * @param   string  $group      The group to which the payments belong.
 * @param   array   $options    An array of options to filter the payments.
 *
 * @return  void
 */
public function onManipulateAvailablePaymentMethods(&$payments, $group, $options)
{
    // get current month
    $mon = (int) JHtml::_('date', 'now', 'n');

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

    // we are in summer, get rid of payment with ID #5
    $payments = array_filter($payments, function($p)
    {
        return $p->id != 5;
    });
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-08 14:44
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information