public function onSwitchPaymentSavePackagesOrder(int &$id_payment, array &$payments ) : void

Fires after fetching the payment method selected by the customer.


Description

Trigger hook to manipulate the selected method of payment. In case the total to pay is equals to 0.00, this hook won't be triggered.


Parameters

&$id_payment

(int)  The ID of the payment to use. The $payments argument must own a payment record with that ID, otherwise an error will be thrown. It is possible to set the ID to 0 to skip the payment process.

&$payments

(array)  A list containing all the supported payments. The array must contain the payment that matches the ID of the selected method of payment. In case the ID is going to be assigned to an unpublished gateway, that payment must be pushed within the list.

Return Value

None.


Example

The following example explains how to pick a payment that is not contained within the list of available payments.

/**
 * Trigger event to manipulate the selected payment gateway.
 *
 * @param   integer  &$id_payment  The selected payment gateways.
 * @param   array    &$payments    An array of available payments.
 *
 * @return  void
 */
public function onSwitchPaymentSavePackagesOrder(&$id_payment, &$payments)
{
    // take the payment with ID equals to 5, load event if unpublished ($strict = true)
    $new_payment = VikAppointments::getPayment($id = 5, $strict = false);

    // register payment within the list
    $payments[] = $new_payment;

    // switch selected payment
    $id_payment = 5;
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-08 15:06
Helpful?