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

sendbank() public method

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));
        $cmdLineParameters = array('merchant_id' => $this->getOption('merchant_id'), 'merchant_country' => $this->getOption('merchant_country'), 'pathfile' => $this->getOption('pathfile'), 'language' => $this->getLanguage($order), 'payment_means' => $this->getOption('payment_means'), 'header_flag' => $this->getOption('header_flag'), 'capture_day' => $this->getOption('capture_day'), 'capture_mode' => $this->getOption('capture_mode'), 'bgcolor' => $this->getOption('bgcolor'), 'block_align' => $this->getOption('block_align'), 'block_order' => $this->getOption('block_order'), 'textcolor' => $this->getOption('textcolor'), 'normal_return_logo' => $this->getOption('normal_return_logo'), 'cancel_return_logo' => $this->getOption('cancel_return_logo'), 'submit_logo' => $this->getOption('submit_logo'), 'logo_id' => $this->getOption('logo_id'), 'logo_id2' => $this->getOption('logo_id2'), 'advert' => $this->getOption('advert'), 'background_id' => $this->getOption('background_id'), 'templatefile' => $this->getOption('templatefile'), 'amount' => $this->getAmount($order->getTotalInc(), $order->getCurrency()->getLabel()), 'currency_code' => $this->getCurrencyCode($order->getCurrency()->getLabel()), 'transaction_id' => $this->transactionGenerator->generate($order), 'normal_return_url' => $this->router->generate($this->getOption('url_return_ok'), $params, UrlGeneratorInterface::ABSOLUTE_URL), 'cancel_return_url' => $this->router->generate($this->getOption('url_return_ko'), $params, UrlGeneratorInterface::ABSOLUTE_URL), 'automatic_response_url' => $this->router->generate($this->getOption('url_callback'), $params, UrlGeneratorInterface::ABSOLUTE_URL), 'caddie' => 'mon_caddie', 'customer_id' => $order->getCustomer()->getId(), 'customer_email' => $order->getCustomer()->getEmail(), 'customer_ip_address' => '', 'data' => $this->getOption('data'), 'return_context' => '', 'target' => '', 'order_id' => $order->getReference());
        // clean parameters
        $cmdLineOptions = array();
        foreach ($cmdLineParameters as $option => $value) {
            $cmdLineOptions[] = sprintf('%s=%s', $option, $this->encodeString($value));
        }
        $cmd = sprintf('cd %s && %s %s', $this->getOption('base_folder'), $this->getOption('request_command'), implode(' ', $cmdLineOptions));
        $this->logger->debug(sprintf('Running command : %s', $cmd));
        $process = new Process($cmd);
        $process->run();
        if (!$process->isSuccessful()) {
            throw new \RuntimeException(sprintf('Error %d when executing Scellius command: "%s".', $process->getExitCode(), trim($process->getErrorOutput())));
        }
        //sortie de la fonction : $result=!code!error!buffer!
        //    - code=0  : la fonction génère une page html contenue dans la variable buffer
        //    - code=-1 : La fonction retourne un message d'erreur dans la variable error
        $data = explode('!', $process->getOutput());
        if (count($data) != 5) {
            throw new \RuntimeException('Invalid data count');
        }
        if ($data[1] == 0) {
            $scellius = array('valid' => true, 'content' => $data[3]);
        } else {
            $scellius = array('valid' => false, 'content' => $data[2]);
        }
        return $this->templating->renderResponse($this->getOption('template'), array('order' => $order, 'scellius' => $scellius, 'debug' => $this->debug, 'parameters' => $cmdLineParameters));
    }

Usage Example

 public function testValidSendbankPayment()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $templating->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'callbackValidsendbank')));
     $generator = $this->getMock('Sonata\\Component\\Payment\\Scellius\\ScelliusTransactionGeneratorInterface');
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $customer->expects($this->once())->method('getId')->will($this->returnValue(42));
     $customer->expects($this->once())->method('getEmail')->will($this->returnValue('*****@*****.**'));
     $order = new ScelliusPaymentTest_Order();
     $order->setCreatedAt($date);
     $order->setId(2);
     $order->setReference('FR');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->setCurrency($currency);
     $order->setCustomer($customer);
     $order->setLocale('es');
     $payment = new ScelliusPayment($router, $logger, $templating, $generator, true);
     $payment->setCode('free_1');
     $payment->setOptions(array('base_folder' => __DIR__, 'request_command' => 'cat request_ok.txt && echo '));
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }