/**
  * Process the confirmation of an order. This method should be  called
  * once the module has performed the required checks to confirm a valid payment.
  *
  * @param int $order_id the order ID
  */
 public function confirmPayment($order_id)
 {
     try {
         $order_id = intval($order_id);
         if (null !== ($order = $this->getOrder($order_id))) {
             $this->getLog()->addInfo($this->getTranslator()->trans("Processing confirmation of order ref. %ref, ID %id", array('%ref' => $order->getRef(), '%id' => $order->getId())));
             $event = new OrderEvent($order);
             $event->setStatus(OrderStatusQuery::getPaidStatus()->getId());
             $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
             $this->getLog()->addInfo($this->getTranslator()->trans("Order ref. %ref, ID %id has been successfully paid.", array('%ref' => $order->getRef(), '%id' => $order->getId())));
         }
     } catch (\Exception $ex) {
         $this->getLog()->addError($this->getTranslator()->trans("Error occured while processing order ref. %ref, ID %id: %err", array('%err' => $ex->getMessage(), '%ref' => !isset($order) ? "?" : $order->getRef(), '%id' => !isset($order) ? "?" : $order->getId())));
         throw $ex;
     }
 }
예제 #2
0
파일: Order.php 프로젝트: badelas/thelia
 /**
  * @param  ModelOrder                               $order
  * @param $newStatus
  * @param $canceledStatus
  * @throws \Thelia\Exception\TheliaProcessException
  */
 public function updateQuantity(ModelOrder $order, $newStatus)
 {
     $canceledStatus = OrderStatusQuery::getCancelledStatus()->getId();
     $paidStatus = OrderStatusQuery::getPaidStatus()->getId();
     if ($newStatus == $canceledStatus || $order->isCancelled()) {
         $this->updateQuantityForCanceledOrder($order, $newStatus, $canceledStatus);
     } elseif ($paidStatus == $newStatus && $order->isNotPaid() && $order->getVersion() == 1) {
         $this->updateQuantityForPaidOrder($order);
     }
 }
예제 #3
0
 public function pay(Order $order)
 {
     $event = new OrderEvent($order);
     $event->setStatus(OrderStatusQuery::getPaidStatus()->getId());
     $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
 }
예제 #4
0
 /**
  * @param $order_id
  * @return \Thelia\Core\HttpFoundation\Response
  */
 public function ok($order_id)
 {
     /*
      * Check if token&order are valid
      */
     $token = null;
     $order = $this->checkorder($order_id, $token);
     /*
      * $payerid string value returned by paypal
      * $logger PaypalApiLogManager used to log transctions with paypal
      */
     $payerid = $this->getRequest()->get('PayerID');
     $logger = new PaypalApiLogManager();
     if (!empty($payerid)) {
         /*
          * $config ConfigInterface Object that contains configuration
          * $api PaypalApiCredentials Class used by the library to store and use 3T login(username, password, signature)
          * $sandbox bool true if sandbox is enabled
          */
         $config = new PaypalConfig();
         $config->pushValues();
         $api = new PaypalApiCredentials($config);
         $sandbox = $api->getConfig()->getSandbox();
         /*
          * Send getExpressCheckout & doExpressCheckout
          * empty cart
          */
         $getExpressCheckout = new PaypalNvpOperationsGetExpressCheckoutDetails($api, $token);
         $request = new PaypalNvpMessageSender($getExpressCheckout, $sandbox);
         $response = $request->send();
         $logger->logTransaction($response);
         $response = PaypalApiManager::nvpToArray($response);
         if (isset($response['ACK']) && $response['ACK'] === 'Success' && isset($response['PAYERID']) && $response['PAYERID'] === $payerid && isset($response['TOKEN']) && $response['TOKEN'] === $token) {
             $doExpressCheckout = new PaypalNvpOperationsDoExpressCheckoutPayment($api, round($order->getTotalAmount(), 2), $order->getCurrency()->getCode(), $payerid, PaypalApiManager::PAYMENT_TYPE_SALE, $token, URL::getInstance()->absoluteUrl("/module/paypal/listen"));
             $request = new PaypalNvpMessageSender($doExpressCheckout, $token);
             $response = $request->send();
             $logger->logTransaction($response);
             $response = PaypalApiManager::nvpToArray($response);
             /*
              * In case of pending status, log the reason to get usefull information (multi-currency problem, ...)
              */
             if (isset($response['ACK']) && $response['ACK'] === "Success" && isset($response['PAYMENTINFO_0_PAYMENTSTATUS']) && $response['PAYMENTINFO_0_PAYMENTSTATUS'] === "Pending") {
                 $logger->logText('Paypal transaction is pending. Reason: ' . $response['PAYMENTINFO_0_PENDINGREASON'], 'NOTICE');
             }
             /*
              * In case of success, go to success page
              * In case of error, show it
              */
             if (isset($response['ACK']) && $response['ACK'] === "Success" && isset($response['PAYMENTINFO_0_PAYMENTSTATUS']) && $response['PAYMENTINFO_0_PAYMENTSTATUS'] === "Completed" && isset($response['TOKEN']) && $response['TOKEN'] === $token) {
                 /*
                  * Set order status as paid
                  */
                 $event = new OrderEvent($order);
                 $event->setStatus(OrderStatusQuery::getPaidStatus()->getId());
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 $this->redirectToSuccessPage($order_id);
             }
         }
     }
     /*
      * If no redirection done ( === error ): Empty cart
      */
     return $this->render("order-failed", ["failed_order_id" => $order_id]);
 }