Sonata\Component\Payment\Scellius\ScelliusPayment::isCallbackValid PHP Method

isCallbackValid() public method

public isCallbackValid ( Sonata\Component\Payment\TransactionInterface $transaction )
$transaction Sonata\Component\Payment\TransactionInterface
    public function isCallbackValid(TransactionInterface $transaction)
    {
        if (!$transaction->getOrder()) {
            return false;
        }
        if ($transaction->get('check') == $this->generateUrlCheck($transaction->getOrder())) {
            return true;
        }
        $transaction->setState(TransactionInterface::STATE_KO);
        $transaction->setStatusCode(TransactionInterface::STATUS_WRONG_CALLBACK);
        $transaction->addInformation('The callback is not valid');
        return false;
    }

Usage Example

 public function testIsCallbackValid()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $generator = $this->getMock('Sonata\\Component\\Payment\\Scellius\\ScelliusTransactionGeneratorInterface');
     $payment = new ScelliusPayment($router, $logger, $templating, $generator, true);
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $order->expects($this->any())->method('getCreatedAt')->will($this->returnValue(new \DateTime()));
     $check = sha1($order->getReference() . $order->getCreatedAt()->format("m/d/Y:G:i:s") . $order->getId());
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->once())->method('getOrder')->will($this->returnValue(null));
     $this->assertFalse($payment->isCallbackValid($transaction));
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->exactly(2))->method('getOrder')->will($this->returnValue($order));
     $transaction->expects($this->once())->method('get')->will($this->returnValue($check));
     $this->assertTrue($payment->isCallbackValid($transaction));
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->exactly(2))->method('getOrder')->will($this->returnValue($order));
     $transaction->expects($this->once())->method('get')->will($this->returnValue('untest'));
     $transaction->expects($this->once())->method('setState');
     $transaction->expects($this->once())->method('setStatusCode');
     $transaction->expects($this->once())->method('addInformation');
     $this->assertFalse($payment->isCallbackValid($transaction));
 }