Ejemplo n.º 1
0
 public function service()
 {
     $paypalManager = PaypalManager::getInstance();
     $order_id = $_REQUEST['order_id'];
     $ordersManager = OrdersManager::getInstance($this->config, $this->args);
     list($paymentAmount, $shippingUsd) = $ordersManager->getOrderTotalUsdToPay($order_id);
     $currencyCodeType = "USD";
     $paymentType = "Sale";
     $returnURL = "https://pcstore.am/dyn/main_checkout_paypal/do_order_confirm";
     $cancelURL = "https://pcstore.am/dyn/main_checkout_paypal/do_order_cancel";
     $items = array();
     $items[] = array('name' => 'Pcstore Order Number #' . $order_id, 'amt' => $paymentAmount, 'qty' => 1);
     $_SESSION["Payment_Amount"] = $paymentAmount + $shippingUsd;
     $resArray = $paypalManager->CallShortcutExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items, $shippingUsd);
     $ack = strtoupper($resArray["ACK"]);
     if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
         $ordersManager->updateTextField($order_id, '3rd_party_payment_token', $resArray["TOKEN"]);
         $paypalManager->RedirectToPayPal($resArray["TOKEN"]);
     } else {
         //Display a user friendly Error on the page using any of the following error information returned by PayPal
         $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
         $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
         $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
         $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
         echo "SetExpressCheckout API call failed. ";
         echo "Detailed Error Message: " . $ErrorLongMsg;
         echo "Short Error Message: " . $ErrorShortMsg;
         echo "Error Code: " . $ErrorCode;
         echo "Error Severity Code: " . $ErrorSeverityCode;
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns an singleton instance of this class
  *
  * @param object $config
  * @param object $args
  * @return
  */
 public static function getInstance($config, $args)
 {
     if (self::$instance == null) {
         self::$instance = new OrdersManager($config, $args);
     }
     return self::$instance;
 }
Ejemplo n.º 3
0
 public function service()
 {
     $token = urlencode($_SESSION['TOKEN']);
     $ordersManager = OrdersManager::getInstance($this->config, $this->args);
     $orderBy3rdPartyToken = $ordersManager->getOrderBy3rdPartyToken($token);
     if (!isset($orderBy3rdPartyToken)) {
         $_SESSION['error_message'] = $this->getPhrase(595);
         $this->redirect('orders');
     }
     $paypalTransactionsManager = PaypalTransactionsManager::getInstance($this->config, $this->args);
     $orderId = $orderBy3rdPartyToken->getId();
     $res = $this->getPaypalShippingDetails();
     if ($res === true) {
         $res = $this->confirmOrder();
         if ($res === true) {
             $_SESSION['success_message'] = sprintf($this->getPhrase(593), $orderId);
             $ordersManager->updateNumericField($orderId, '3rd_party_payment_received', 1);
             $paypalTransactionsManager->setOrderCompleted($orderId);
         } else {
             $paypalTransactionsManager->setOrderPaymentError($orderId, $res);
             $_SESSION['error_message'] = $res;
         }
     } else {
         $paypalTransactionsManager->setOrderPaymentError($orderId, $res);
         $_SESSION['error_message'] = $res;
     }
     $this->redirect('orders');
 }
Ejemplo n.º 4
0
 public function load()
 {
     $ordersManager = OrdersManager::getInstance($this->config, $this->args);
     $orderId = $this->secure($_REQUEST['order_id']);
     $this->addParam('order_id', $orderId);
     $orderDto = $ordersManager->selectByPK($orderId);
     $this->addParam('orderDto', $orderDto);
     if (isset($orderDto)) {
         $metadataJson = $orderDto->getMetadataJson();
         $metadata = json_decode($metadataJson);
         $this->addParam('metadata', $metadata);
     }
 }
Ejemplo n.º 5
0
 public function load()
 {
     $ordersManager = OrdersManager::getInstance($this->config, $this->args);
     if ($this->getUserLevel() === UserGroups::$ADMIN) {
         $showOnlyOrdersValues = array_merge(array(-1), $ordersManager->orderStatusesValues);
         $this->addParam('showOnlyOrdersValues', $showOnlyOrdersValues);
         $orderStatusesDisplayNames = array_merge(array($this->getPhrase(153)), $ordersManager->getOrderStatusesDisplayNamesPhrases());
         $showOnlyOrdersDisplayNamesPphraseIdsArray = array_merge(array(153), $ordersManager->orderStatusesDisplayNamesIds);
         $this->addParam('showOnlyOrdersDisplayNames', $orderStatusesDisplayNames);
         $this->addParam('showOnlyOrdersDisplayNamesPphraseIdsArray', $showOnlyOrdersDisplayNamesPphraseIdsArray);
         $show_only = $showOnlyOrdersValues[1];
         if (isset($_REQUEST['show_only'])) {
             $so = $this->secure($_REQUEST['show_only']);
             if (in_array($so, $showOnlyOrdersValues)) {
                 $show_only = $so;
             }
         }
         $this->addParam('showOnlyOrdersSelected', $show_only);
         $customerOrders = $ordersManager->getAllOrdersJoinedWithDetails($show_only);
     } else {
         $customer = $this->getCustomer();
         $customerEmail = strtolower($customer->getEmail());
         $customerOrders = $ordersManager->getCustomerOrderJoinedWithDetails($customerEmail);
     }
     $groupedOrders = $this->groupCustomerOrders($customerOrders);
     $groupOrdersByOrderIdAndBundleId = $this->groupOrdersByOrderIdAndBundleId($customerOrders);
     $pv = $this->getPriceVariety($groupedOrders);
     $this->addParam('groupOrdersByOrderIdAndBundleId', $groupOrdersByOrderIdAndBundleId);
     $this->addParam('priceVariety', $pv);
     if (isset($_REQUEST['order_id'])) {
         $order_id = $_REQUEST['order_id'];
         $mess1 = $this->getPhrase(301);
         $mess2 = $this->getPhrase(329) . $order_id;
         $mess3 = $this->getPhrase(360);
         $this->addParam('customerMessages', array($mess1, $mess2, $mess3));
     }
     if (isset($_SESSION['success_message'])) {
         $this->addParam('customerMessages', array($_SESSION['success_message']));
         unset($_SESSION['success_message']);
     }
     if (isset($_SESSION['error_message'])) {
         $this->addParam('customerErrorMessages', array($_SESSION['error_message']));
         unset($_SESSION['error_message']);
     }
     $this->addParam('itemManager', ItemManager::getInstance($this->config, $this->args));
     $this->addParam('userManager', UserManager::getInstance($this->config, $this->args));
     $this->addParam('orderManager', OrdersManager::getInstance($this->config, $this->args));
     $this->addParam("orderStatusesValues", $ordersManager->orderStatusesValues);
     $this->addParam("orderStatusesDisplayNames", $ordersManager->getOrderStatusesDisplayNamesPhrases());
 }
Ejemplo n.º 6
0
 public function service()
 {
     $order_id = $this->secure($_REQUEST['order_id']);
     $ordersManager = OrdersManager::getInstance($this->config, $this->args);
     $order = $ordersManager->selectByPK($order_id);
     if (isset($order)) {
         //TODO remove order
         $jsonArr = array('status' => "ok");
         echo json_encode($jsonArr);
         return true;
     } else {
         $jsonArr = array('status' => "err", "errText" => "System Error: Order does not exist!");
         echo json_encode($jsonArr);
         return false;
     }
 }
 public function service()
 {
     $order_id = $_REQUEST['order_id'];
     $token = $_REQUEST['stripeToken'];
     $userManager = UserManager::getInstance($this->config, $this->args);
     $ordersManager = OrdersManager::getInstance($this->config, $this->args);
     $orderTotalUsdToPay = $ordersManager->getOrderTotalUsdToPay($order_id, true);
     Stripe::setApiKey($this->getCmsVar('stripe_secret_key'));
     $email = $userManager->getRealEmailAddressByUserDto($this->getCustomer());
     try {
         $charge = Stripe_Charge::create(array("card" => $token, "description" => $email . ' (order #' . $order_id . ')', 'amount' => $orderTotalUsdToPay * 100, 'currency' => 'usd'));
     } catch (Exception $e) {
         $this->error(array('message' => $e->getMessage()));
     }
     $ordersManager->updateTextField($order_id, '3rd_party_payment_token', $token);
     $ordersManager->updateTextField($order_id, '3rd_party_payment_received', 1);
     $this->ok();
 }
Ejemplo n.º 8
0
 private function initManagers()
 {
     $this->itemManager = ItemManager::getInstance($this->config, $this->args);
     $this->customerCartManager = CustomerCartManager::getInstance($this->config, $this->args);
     $this->ordersManager = OrdersManager::getInstance($this->config, $this->args);
     $this->bundleItemsManager = BundleItemsManager::getInstance($this->config, $this->args);
     $this->specialFeesManager = SpecialFeesManager::getInstance($this->config, $this->args);
     $this->orderDetailsManager = OrderDetailsManager::getInstance($this->config, $this->args);
     $this->checkoutManager = CheckoutManager::getInstance($this->config, $this->args);
 }
 public function service()
 {
     $only_refresh = $this->secure($_REQUEST["only_refresh"]);
     if ($only_refresh == 1) {
         $jsonArr = array('status' => "ok", "message" => "ok");
         echo json_encode($jsonArr);
         return true;
     }
     $this->ordersManager = OrdersManager::getInstance($this->config, $this->args);
     $this->userManager = UserManager::getInstance($this->config, $this->args);
     $orderId = $this->secure($_REQUEST["order_id"]);
     $orderDto = $this->ordersManager->selectByPK($orderId);
     $status = intval($this->secure($_REQUEST["status"]));
     if (!in_array($status, $this->ordersManager->orderStatusesValues)) {
         $jsonArr = array('status' => "err", "errText" => "unknown order status:'" . $status, "'");
         echo json_encode($jsonArr);
         return false;
     }
     $orderOldStatus = $this->ordersManager->getOrderStatus($orderId);
     $this->ordersManager->setOrderStatus($orderId, $status);
     if ($orderOldStatus == 2 && $status != 2) {
         //then used bonuses should be subtract
         $userDto = $this->getUserByUserOrderId($orderId);
         if ($userDto) {
             $userId = $userDto->getId();
             $usedPoints = $orderDto->getUsedPoints();
             $description = "Order number {$orderId} canceled. Used points restored!";
             $this->userManager->subtractUserPoints($userId, $usedPoints, $description);
         }
     }
     if ($orderOldStatus != 1 && $status == 1) {
         $parentId = $this->getUserParentIdByUserOrderId($orderId);
         $totalAmd = $orderDto->getOrderTotalAmd();
         //bonus to parent
         if ($parentId > 0) {
             $isParentVip = $this->userManager->isVip($parentId);
             if ($isParentVip) {
                 $vip_user_profit_percent_from_subuser_order = intval($this->getCmsVar('vip_user_profit_percent_from_subuser_order'));
                 $orderProfitAmd = $this->ordersManager->calcOrderProfitAmd($orderId);
                 $description = $vip_user_profit_percent_from_subuser_order . "% percent from profit of order number " . $orderId . " (" . $orderDto->getCustomerEmail() . "). special for VIP parent users. Order total profit:" . $orderProfitAmd . ' Դր.';
                 $points = intval($orderProfitAmd * $vip_user_profit_percent_from_subuser_order / 100);
                 $this->userManager->addUserPoints($parentId, $points, $description);
             } else {
                 $user_points_from_subusers_purchase_percent = intval($this->getCmsVar('user_profit_percent_from_subuser_order'));
                 $orderProfitAmd = $this->ordersManager->calcOrderProfitAmd($orderId);
                 $description = $user_points_from_subusers_purchase_percent . "% percent from profit of order number " . $orderId . " (" . $orderDto->getCustomerEmail() . "). Order total profit:" . $orderProfitAmd . ' Դր.';
                 $points = intval($orderProfitAmd * $vip_user_profit_percent_from_subuser_order / 100);
                 $this->userManager->addUserPoints($parentId, $points, $description);
                 //subuser first order pintont to parent
                 $userDto = $this->getUserByUserOrderId($orderId);
                 $ordersCount = $this->ordersManager->getCustomerTotalConfirmedOrdersCount($userDto->getEmail());
                 if ($ordersCount === 1) {
                     $user_points_from_subusers_first_order = $this->getCmsVar('user_points_from_subusers_first_order');
                     $description = $user_points_from_subusers_first_order . ' points from first order of sub user (' . $userDto->getEmail() . ')';
                     $this->userManager->addUserPoints($parentId, $user_points_from_subusers_first_order, $description);
                 }
             }
         } else {
             //TODO help children
         }
         $this->ordersManager->setOrderDeliverDateTime($orderId, date('Y-m-d H:i:s'));
     }
     if ($orderOldStatus == 1 && $status != 1) {
         //bonus to parent subtract
         $parentId = $this->getUserParentIdByUserOrderId($orderId);
         $isParentVip = $this->userManager->isVip($parentId);
         if ($parentId > 0) {
             if ($isParentVip) {
                 $vip_user_profit_percent_from_subuser_order = intval($this->getCmsVar('vip_user_profit_percent_from_subuser_order'));
                 $orderProfitAmd = $this->ordersManager->calcOrderProfitAmd($orderId);
                 $description = "Order number {$orderId} canceled. Inviter VIP user points reduced. Order total profit:" . $orderProfitAmd . ' Դր. (' . $vip_user_profit_percent_from_subuser_order . "%)";
                 $points = intval($orderProfitAmd * $vip_user_profit_percent_from_subuser_order / 100);
                 $this->userManager->subtractUserPoints($parentId, $points, $description);
             } else {
                 $user_profit_percent_from_subuser_order = intval($this->getCmsVar('user_profit_percent_from_subuser_order')) / 100;
                 $orderProfitAmd = $this->ordersManager->calcOrderProfitAmd($orderId);
                 $description = "Order number {$orderId} canceled. Inviter user points reduced. Order total profit:" . $orderProfitAmd . ' Դր. (' . $user_profit_percent_from_subuser_order . "%)";
                 $points = intval($orderProfitAmd * $user_profit_percent_from_subuser_order / 100);
                 $this->userManager->subtractUserPoints($parentId, $points, $description);
                 //subuser first order pintont to parent
                 $userDto = $this->getUserByUserOrderId($orderId);
                 $ordersCount = $this->ordersManager->getCustomerTotalConfirmedOrdersCount($userDto->getEmail());
                 if ($ordersCount === 0) {
                     $user_points_from_subusers_first_order = $this->getCmsVar('user_points_from_subusers_first_order');
                     $description = $user_points_from_subusers_first_order . ' points subtracted due to cancel first order of sub user (' . $userDto->getEmail() . ')';
                     $this->userManager->subtractUserPoints($parentId, $user_points_from_subusers_first_order, $description);
                 }
             }
         }
     }
     if ($status == 2) {
         $cencel_reason = $this->secure($_REQUEST["cencel_reason"]);
         if (!empty($cencel_reason)) {
             $this->ordersManager->setOrderCancelReasonText($orderId, $cencel_reason);
         }
         //if was NOT CENCELED now it's CENCELED
         //used bonuses should be restore
         $userDto = $this->getUserByUserOrderId($orderId);
         if ($userDto) {
             $userId = $userDto->getId();
             $usedPoints = $orderDto->getUsedPoints();
             $description = "User used bonuses restored from order number " . $orderId;
             $this->userManager->addUserPoints($userId, $usedPoints, $description);
         }
     }
     $jsonArr = array('status' => "ok", "message" => "ok");
     echo json_encode($jsonArr);
     return true;
 }