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

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

public getPaymentCallbackResponse ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function getPaymentCallbackResponse(Request $request)
    {
        // retrieve the transaction
        $transaction = $this->createTransaction($request);
        $order = $this->getValidOrder($transaction);
        $event = new PaymentEvent($order, $transaction);
        $this->getEventDispatcher()->dispatch(PaymentEvents::PRE_CALLBACK, $event);
        // start the payment callback
        $response = $this->getPayment($transaction->getPaymentCode())->callback($transaction);
        $this->transactionManager->save($transaction);
        $this->orderManager->save($order);
        $event = new PaymentEvent($order, $transaction, $response);
        $this->getEventDispatcher()->dispatch(PaymentEvents::POST_CALLBACK, $event);
        $this->notificationBackend->createAndPublish('sonata_payment_order_process', array('order_id' => $order->getId(), 'transaction_id' => $transaction->getId()));
        return $response;
    }

Usage Example

Пример #1
0
 public function testGetPaymentCallbackResponse()
 {
     $response = new Response();
     $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));
     $payment->expects($this->once())->method('callback')->will($this->returnValue($response));
     $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(3))->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();
     $cbResponse = $handler->getPaymentCallbackResponse($request);
     $this->assertEquals($response, $cbResponse);
 }