Sonata\Component\Payment\PaymentHandler::handleConfirmation PHP Метод

handleConfirmation() публичный Метод

public handleConfirmation ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function handleConfirmation(Request $request)
    {
        $transaction = $this->createTransaction($request);
        $order = $this->getValidOrder($transaction);
        $event = new PaymentEvent($order, $transaction);
        $this->getEventDispatcher()->dispatch(PaymentEvents::CONFIRMATION, $event);
        return $order;
    }

Usage Example

Пример #1
0
 public function testHandleConfirmation()
 {
     $payment = $this->getMock('Sonata\\Component\\Payment\\PaymentInterface');
     $payment->expects($this->once())->method('getOrderReference')->will($this->returnValue('42'));
     $payment->expects($this->once())->method('isRequestValid')->will($this->returnValue(true));
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $om = $this->getMock('Sonata\\Component\\Order\\OrderManagerInterface');
     $om->expects($this->once())->method('findOneBy')->will($this->returnValue($order));
     $ps = $this->getMock('Sonata\\Component\\Payment\\PaymentSelectorInterface');
     $ps->expects($this->exactly(2))->method('getPayment')->will($this->returnValue($payment));
     $ref = $this->getMock('Sonata\\Component\\Generator\\ReferenceInterface');
     $tm = $this->getMock('Sonata\\Component\\Payment\\TransactionManagerInterface');
     $tm->expects($this->once())->method('create')->will($this->returnValue(new Transaction()));
     $nb = $this->getMockBuilder('Sonata\\NotificationBundle\\Backend\\RuntimeBackend')->disableOriginalConstructor()->getMock();
     $handler = new PaymentHandler($om, $ps, $ref, $tm, $nb);
     $request = new Request();
     $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface');
     $confirmOrder = $handler->handleConfirmation($request);
     $this->assertEquals($confirmOrder, $order);
 }