Sonata\Component\Payment\Pool::addMethod PHP Method

addMethod() public method

add a payment method into the pool.
public addMethod ( Sonata\Component\Payment\PaymentInterface $instance )
$instance Sonata\Component\Payment\PaymentInterface
    public function addMethod(PaymentInterface $instance)
    {
        if (null === $instance->getCode()) {
            throw new \RuntimeException(sprintf('Payment handler of class %s must return a code on getCode method. Please refer to the documentation (https://sonata-project.org/bundles/ecommerce/master/doc/reference/bundles/payment/index.html)', get_class($instance)));
        }
        $this->methods[$instance->getCode()] = $instance;
    }

Usage Example

Example #1
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Payment handler of class Sonata\Component\Payment\PassPayment must return a code on getCode method. Please refer to the documentation (https://sonata-project.org/bundles/ecommerce/master/doc/reference/bundles/payment/index.html)
  */
 public function testAddMethodError()
 {
     $pool = new Pool();
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $payment = new PassPayment($router);
     $pool->addMethod($payment);
 }
All Usage Examples Of Sonata\Component\Payment\Pool::addMethod