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);
$routeName = $response->getContent() == 'ok' ? 'url_return_ok' : 'url_return_ko';
// redirect the user to the correct page
$response = new Response('', 302, array('Location' => $this->router->generate($this->getOption($routeName), $params, UrlGeneratorInterface::ABSOLUTE_URL), 'Content-Type' => 'text/plain'));
$response->setPrivate();
return $response;
}
/** * useless test .... * * @return void */ public function testPassPayment() { $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $router->expects($this->exactly(2))->method('generate')->will($this->returnValue('http://foo.bar/ok-url')); $client = $this->getMock('Buzz\\Client\\ClientInterface'); $browser = new Browser($client); $payment = new PassPayment($router, $browser); $payment->setCode('free_1'); $basket = $this->getMock('Sonata\\Component\\Basket\\Basket'); $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface'); $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface'); $transaction->expects($this->exactly(2))->method('get')->will($this->returnCallback(array($this, 'callback'))); $transaction->expects($this->once())->method('setTransactionId'); $date = new \DateTime(); $date->setTimeStamp(strtotime('30/11/1981')); $date->setTimezone(new \DateTimeZone('Europe/Paris')); $order = new PassPaymentTest_Order(); $order->setCreatedAt($date); $this->assertEquals('free_1', $payment->getCode(), 'Pass Payment return the correct code'); $this->assertTrue($payment->isAddableProduct($basket, $product)); $this->assertTrue($payment->isBasketValid($basket)); $this->assertTrue($payment->isRequestValid($transaction)); $this->assertFalse($payment->isCallbackValid($transaction)); $this->assertFalse($payment->sendConfirmationReceipt($transaction)); $transaction->expects($this->any())->method('getOrder')->will($this->returnValue($order)); $this->assertTrue($payment->isCallbackValid($transaction)); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $payment->handleError($transaction)); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $payment->sendConfirmationReceipt($transaction)); $response = $payment->sendbank($order); $this->assertTrue($response->headers->has('Location')); $this->assertEquals('http://foo.bar/ok-url', $response->headers->get('Location')); $this->assertFalse($response->isCacheable()); $this->assertEquals($payment->getOrderReference($transaction), '0001231'); $payment->applyTransactionId($transaction); }