示例#1
0
 /**
  * @param OrderInterface  $order
  * @param BasketInterface $basket
  *
  * @return BasketInterface
  */
 public function transformIntoBasket(OrderInterface $order, BasketInterface $basket)
 {
     $event = new OrderTransformEvent($order);
     $this->eventDispatcher->dispatch(TransformerEvents::PRE_ORDER_TO_BASKET_TRANSFORM, $event);
     // we reset the current basket
     $basket->reset(true);
     $basket->setCurrency($order->getCurrency());
     $basket->setLocale($order->getLocale());
     // We are free to convert !
     foreach ($order->getOrderElements() as $orderElement) {
         /*
          * @var $orderElement OrderElementInterface
          */
         $provider = $this->productPool->getProvider($orderElement->getProductType());
         $manager = $this->productPool->getManager($orderElement->getProductType());
         $product = $manager->findOneBy(array('id' => $orderElement->getProductId()));
         if (!$product) {
             continue;
         }
         $basketElement = $provider->createBasketElement($product, $orderElement->getOptions());
         $basketElement->setQuantity($orderElement->getQuantity());
         $provider->basketAddProduct($basket, $product, $basketElement);
     }
     $basket->setCustomer($order->getCustomer());
     $basket->buildPrices();
     $event = new BasketTransformEvent($basket);
     $this->eventDispatcher->dispatch(TransformerEvents::POST_ORDER_TO_BASKET_TRANSFORM, $event);
     return $basket;
 }
 /**
  * {@inheritdoc}
  */
 public function order(OrderInterface $order)
 {
     if (!$order->getId()) {
         throw new \RuntimeException('The order is not persisted into the database');
     }
     $this->generateReference($order, $this->registry->getManager()->getClassMetadata(get_class($order))->table['name']);
 }
 /**
  * @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);
 }
示例#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;
 }
示例#5
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'));
 }
 /**
  * Adds the delivery information from $order to $invoice
  *
  * @param InvoiceInterface $invoice
  * @param OrderInterface   $order
  */
 protected function addDelivery(InvoiceInterface $invoice, OrderInterface $order)
 {
     /** @var InvoiceElementInterface $invoiceElement */
     $invoiceElement = $this->invoiceElementManager->create();
     $invoiceElement->setQuantity(1);
     $invoiceElement->setPrice($order->getDeliveryCost());
     $invoiceElement->setUnitPrice($order->getDeliveryCost());
     $invoiceElement->setTotal($order->getDeliveryCost());
     $invoiceElement->setVatRate(0);
     $invoiceElement->setDesignation($this->deliveryPool->getMethod($order->getDeliveryMethod())->getName());
     $invoiceElement->setDescription($this->deliveryPool->getMethod($order->getDeliveryMethod())->getName());
     $invoiceElement->setInvoice($invoice);
     $invoice->addInvoiceElement($invoiceElement);
 }
示例#7
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;
 }
示例#8
0
 /**
  * Gets formatted address lines from $order
  *
  * @param  OrderInterface $order
  * @return string
  */
 protected function getAddress(OrderInterface $order)
 {
     $ret = $order->getBillingAddress1();
     if (null !== $order->getBillingAddress2()) {
         $ret .= " " . $order->getBillingAddress2();
     }
     if (null !== $order->getBillingAddress3()) {
         $ret .= " " . $order->getBillingAddress3();
     }
     return $ret;
 }
示例#9
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));
 }
示例#10
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;
 }
示例#11
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;
 }
示例#12
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()));
 }