getReference() public method

Get reference.
public getReference ( ) : string
return string $reference
Exemplo n.º 1
0
 /**
  * @param \Sonata\Component\Order\OrderInterface $order
  *
  * @throws \RuntimeException
  *
  * @return string
  */
 public function generateUrlCheck(OrderInterface $order)
 {
     if (!$order->getCreatedAt() instanceof \DateTime) {
         throw new \RuntimeException(sprintf('The order must have a creation date - id:%s, reference:%s ', $order->getId(), $order->getReference()));
     }
     return sha1($order->getReference() . $order->getCreatedAt()->format("m/d/Y:G:i:s") . $order->getId() . $this->getOption('shop_secret_key'));
 }
 /**
  * @param \Sonata\Component\Order\OrderInterface $order
  *
  * @throws \RuntimeException
  *
  * @return string
  */
 public function generate(OrderInterface $order)
 {
     if (strlen($order->getReference()) != 12) {
         throw new \RuntimeException('Invalid reference length');
     }
     return substr($order->getReference(), -6);
 }
 /**
  * Transforms an order into an invoice
  *
  * @param OrderInterface   $order
  * @param InvoiceInterface $invoice
  */
 public function transformFromOrder(OrderInterface $order, InvoiceInterface $invoice)
 {
     $event = new OrderTransformEvent($order);
     $this->eventDispatcher->dispatch(TransformerEvents::PRE_ORDER_TO_INVOICE_TRANSFORM, $event);
     $invoice->setName($order->getBillingName());
     $invoice->setAddress1($order->getBillingAddress1());
     $invoice->setAddress2($order->getBillingAddress2());
     $invoice->setAddress3($order->getBillingAddress3());
     $invoice->setCity($order->getBillingCity());
     $invoice->setCountry($order->getBillingCountryCode());
     $invoice->setPostcode($order->getBillingPostcode());
     $invoice->setEmail($order->getBillingEmail());
     $invoice->setFax($order->getBillingFax());
     $invoice->setMobile($order->getBillingMobile());
     $invoice->setPhone($order->getBillingPhone());
     $invoice->setReference($order->getReference());
     $invoice->setCurrency($order->getCurrency());
     $invoice->setCustomer($order->getCustomer());
     $invoice->setTotalExcl($order->getTotalExcl());
     $invoice->setTotalInc($order->getTotalInc());
     $invoice->setPaymentMethod($order->getPaymentMethod());
     $invoice->setLocale($order->getLocale());
     foreach ($order->getOrderElements() as $orderElement) {
         $invoiceElement = $this->createInvoiceElementFromOrderElement($orderElement);
         $invoiceElement->setInvoice($invoice);
         $invoice->addInvoiceElement($invoiceElement);
     }
     if ($order->getDeliveryCost() > 0) {
         $this->addDelivery($invoice, $order);
     }
     $invoice->setStatus(InvoiceInterface::STATUS_OPEN);
     $event = new InvoiceTransformEvent($invoice);
     $this->eventDispatcher->dispatch(TransformerEvents::POST_ORDER_TO_INVOICE_TRANSFORM, $event);
 }
Exemplo n.º 4
0
 /**
  * Handle the callback.
  *
  * @param OrderInterface $order
  * @param string         $action
  *
  * @return Response
  */
 public function processCallback(OrderInterface $order, $action)
 {
     $params = array('bank' => $this->getCode(), 'reference' => $order->getReference(), 'check' => $this->generateUrlCheck($order), 'action' => $action);
     $url = $this->router->generate($this->getOption('url_callback'), $params, true);
     $response = $this->browser->get($url);
     $routeName = 'ok' === $response->getContent() ? 'url_return_ok' : 'url_return_ko';
     $response = new RedirectResponse($this->router->generate($this->getOption($routeName), $params, true), 302, array('Content-Type' => 'text/plain'));
     $response->setPrivate();
     return $response;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 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;
 }
Exemplo n.º 6
0
 /**
  * Generates absolute URL for route specified in $optionKey and $order
  *
  * @param string         $optionKey
  * @param OrderInterface $order
  */
 protected function generateAbsoluteUrlFromOption($optionKey, OrderInterface $order)
 {
     return $this->router->generate($this->getOption($optionKey), array('bank' => $this->getCode(), 'reference' => $order->getReference(), 'check' => $this->generateUrlCheck($order)), true);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 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, true), 'cancel_return_url' => $this->router->generate($this->getOption('url_return_ko'), $params, true), 'automatic_response_url' => $this->router->generate($this->getOption('url_callback'), $params, true), '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'), join(' ', $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));
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 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, true);
     $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, true)));
     $response->setPrivate();
     return $response;
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 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;
 }
Exemplo n.º 10
0
 /**
  * @param  \Sonata\Component\Order\OrderInterface $order
  * @return void
  */
 public function setOrder(OrderInterface $order)
 {
     $this->order = $order;
     $this->addInformation(sprintf('The transaction is linked to the Order : id = `%s` / Reference = `%s`', $order->getId(), $order->getReference()));
 }