Sonata\Component\Payment\Paypal::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('order' => $order->getReference(), 'bank' => $this->getCode(), 'check' => $this->generateUrlCheck($order));
        $fields = array('cmd' => '_xclick', 'charset' => 'utf-8', 'business' => $this->getOption('account'), 'cert_id' => $this->getOption('cert_id'), 'no_shipping' => '1', 'lc' => 'EN', 'no_note' => '1', 'invoice' => $order->getReference(), 'amount' => $order->getTotalInc(), 'currency_code' => $order->getCurrency(), 'item_name' => 'Order ' . $order->getReference(), 'bn' => 'Sonata/1.0', 'first_name' => $order->getBillingName(), 'last_name' => '', 'address1' => $order->getBillingAddress1(), 'address2' => $order->getBillingAddress2(), 'city' => $order->getBillingCity(), 'zip' => $order->getBillingPostcode(), 'country' => $order->getBillingCountryCode(), 'custom' => $this->generateUrlCheck($order), 'notify_url' => $this->router->generate($this->getOption('url_callback'), $params, UrlGeneratorInterface::ABSOLUTE_URL), 'cancel_return' => $this->router->generate($this->getOption('url_return_ko'), $params, UrlGeneratorInterface::ABSOLUTE_URL), 'return' => $this->router->generate($this->getOption('url_return_ok'), $params, UrlGeneratorInterface::ABSOLUTE_URL));
        if ($this->getOption('debug', false)) {
            $html = '<html><body>' . "\n";
        } else {
            $html = '<html><body onload="document.getElementById(\'submit_button\').disabled = \'disabled\'; document.getElementById(\'formPaiement\').submit();">' . "\n";
        }
        $method = $this->getOption('method', 'encrypt');
        $html .= sprintf('<form action="%s" method="%s" id="formPaiement" >' . "\n", $this->getOption('url_action'), 'POST');
        $html .= '<input type="hidden" name="cmd" value="_s-xclick">' . "\n";
        $html .= sprintf('<input type="hidden" name="encrypted" value="%s" />', call_user_func(array($this, $method), $fields));
        $html .= '<p>' . $this->translator->trans('process_to_paiement_bank_page', array(), 'PaymentBundle') . '</p>';
        $html .= '<input type="submit" id="submit_button" value="' . $this->translator->trans('process_to_paiement_btn', array(), 'PaymentBundle') . '" />';
        $html .= '</form>';
        $html .= '</body></html>';
        if ($this->getOption('debug', false)) {
            echo "<!-- Encrypted Array : \n" . print_r($fields, 1) . '-->';
        }
        $response = new \Symfony\Component\HttpFoundation\Response($html, 200, array('Content-Type' => 'text/html'));
        $response->setPrivate(true);
        return $response;
    }

Usage Example

Example #1
0
 public function testSendbank()
 {
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $paypal = new Paypal($router, $translator);
     $options = array('cert_file' => __DIR__ . '/PaypalTestFiles/cert_file', 'key_file' => __DIR__ . '/PaypalTestFiles/key_file', 'paypal_cert_file' => __DIR__ . '/PaypalTestFiles/paypal_cert_file', 'openssl' => __DIR__ . '/PaypalTestFiles/openssl');
     $paypal->setOptions($options);
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $order->expects($this->any())->method('getCreatedAt')->will($this->returnValue(new \DateTime()));
     $sendbank = $paypal->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $sendbank);
     $this->assertContains('<input type="hidden" name="cmd" value="_s-xclick">', $sendbank->getContent());
 }