Copied!

VoterInterface

VoterInterface.php : 47

A voter decides if a payment method is available for a given cart.

The following example is a voter disabling an offline payment method if the cart contains any virtual products:

final class OfflineVoter implements VoterInterface
{
    public function vote(PaymentMethodInterface $method, CartInterface $cart): bool
    {
        foreach ($cart->getEntries() as $entry) {
            if ($entry->getProduct()->getProductType()->isVirtual()) {
                return false;
            }
        }

        return true;
    }
}

The \Ibexa\Contracts\Payment\PaymentMethod\Voter\VoterInterface implementations must be registered as a service with ibexa.payment.payment_method.voter tag and its type attribute associating the voter to a payment method's identifier.

services:
   App\PaymentMethod\OfflineVoter:
       tags:
            - name: ibexa.payment.payment_method.voter
              type: offline

Methods

publicvote()

VoterInterface.php : 52

Returns true if the payment method is available for the given cart, false otherwise.

public vote(PaymentMethodInterface $method, CartInterface $cart) : bool

Parameters

Name Type Default value Description
$method PaymentMethodInterface - -
$cart CartInterface - -

Return values

bool