Sonata\Component\Payment\CheckPayment::sendConfirmationReceipt PHP Method

sendConfirmationReceipt() public method

public sendConfirmationReceipt ( Sonata\Component\Payment\TransactionInterface $transaction )
$transaction Sonata\Component\Payment\TransactionInterface
    public function sendConfirmationReceipt(TransactionInterface $transaction)
    {
        $order = $transaction->getOrder();
        if (!$order) {
            $transaction->setState(TransactionInterface::STATE_KO);
            $transaction->setStatusCode(TransactionInterface::STATUS_ORDER_UNKNOWN);
            $transaction->addInformation('The order does not exist');
            return false;
        }
        $transaction->setStatusCode(TransactionInterface::STATUS_VALIDATED);
        $transaction->setState(TransactionInterface::STATE_OK);
        $order->setStatus(OrderInterface::STATUS_PENDING);
        $order->setPaymentStatus(TransactionInterface::STATUS_PENDING);
        $order->setValidatedAt($transaction->getCreatedAt());
        return new Response('ok', 200, array('Content-Type' => 'text/plain'));
    }

Usage Example

Example #1
0
 public function testSendConfirmationReceipt()
 {
     $order = new CheckPaymentTest_Order();
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->exactly(2))->method('getOrder')->will($this->onConsecutiveCalls(null, $order));
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $browser = new Browser();
     $payment = new CheckPayment($router, $logger, $browser);
     $payment->setCode('free_1');
     // first call : the order is not set
     $response = $payment->sendConfirmationReceipt($transaction);
     $this->assertFalse($response, '::sendConfirmationReceipt return false on invalid order');
     // second call : the order is set
     $response = $payment->sendConfirmationReceipt($transaction);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response, '::sendConfirmationReceipt return a Response object');
     $this->assertEquals('ok', $response->getContent(), '::getContent returns ok');
 }