public sendbank ( Sonata\Component\Order\OrderInterface $order ) | ||
$order | Sonata\Component\Order\OrderInterface |
public function sendbank(OrderInterface $order)
{
$params = array('bank' => $this->getCode(), 'reference' => $order->getReference(), 'check' => $this->generateUrlCheck($order));
// call the callback handler ...
$url = $this->router->generate($this->getOption('url_callback'), $params, UrlGeneratorInterface::ABSOLUTE_URL);
$response = $this->browser->get($url);
if ($response->getContent() == 'ok') {
$routeName = 'url_return_ok';
} else {
$routeName = 'url_return_ko';
$this->logger->critical(sprintf('The CheckPayment received a ko result : %s', $response->getContent()));
}
// redirect the user to the correct page
$response = new Response('', 302, array('Location' => $this->router->generate($this->getOption($routeName), $params, UrlGeneratorInterface::ABSOLUTE_URL)));
$response->setPrivate();
return $response;
}
public function testSendbank() { $date = new \DateTime(); $date->setTimeStamp(strtotime('30/11/1981')); $date->setTimezone(new \DateTimeZone('Europe/Paris')); $order = new CheckPaymentTest_Order(); $order->setCreatedAt($date); $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $router->expects($this->exactly(2))->method('generate')->will($this->returnValue('http://foo.bar/ok-url')); $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface'); $client = $this->getMock('Buzz\\Client\\ClientInterface'); $client->expects($this->once())->method('send')->will($this->returnCallback(function ($request, $response) { $response->setContent('ok'); })); $browser = new Browser($client); $payment = new CheckPayment($router, $logger, $browser); $response = $payment->sendbank($order); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); $this->assertEquals(302, $response->getStatusCode()); $this->assertEquals('http://foo.bar/ok-url', $response->headers->get('Location')); $this->assertFalse($response->isCacheable()); }