Пример #1
0
 public function execute()
 {
     $this->tp = SJB_System::getTemplateProcessor();
     $passedParametersViaUri = SJB_UrlParamProvider::getParams();
     $promotionSID = array_shift($passedParametersViaUri);
     $promotionCodeInfo = SJB_PromotionsManager::getCodeInfoBySID($promotionSID);
     $this->tp->assign('promotionInfo', $promotionCodeInfo);
     if (!$promotionCodeInfo) {
         array_push($this->errors, 'INVALID_ID');
     }
     $page = SJB_Request::getInt('page', 1);
     $itemsPerPage = SJB_Request::getInt('items_per_page', 50);
     $itemsCount = SJB_PromotionsManager::getHistoryCountBySID($promotionSID);
     $this->assignParametersForPagination($page, $itemsPerPage, $itemsCount);
     $promotions = SJB_PromotionsManager::getHistoryBySID($promotionSID, $page, $itemsPerPage);
     SJB_PromotionsManager::preparePromotionsInfoForLog($promotions);
     $currency = SJB_CurrencyManager::getDefaultCurrency();
     $this->tp->assign('currency', $currency);
     $this->tp->assign('promotions', $promotions);
     $this->tp->assign('errors', $this->errors);
     $this->tp->display('promotions_log.tpl');
 }
Пример #2
0
 private function applyPromoCodesToProduct($promotionCode, &$productInfo)
 {
     $allowShoppingItems = array();
     if (!isset($productInfo['code_info'])) {
         if (isset($productInfo['custom_info'])) {
             $allowShoppingItems[] = $productInfo['custom_info']['productSid'];
         } else {
             $allowShoppingItems[] = $productInfo['sid'];
         }
     }
     if ($codeInfo = SJB_PromotionsManager::checkCode($promotionCode, $allowShoppingItems)) {
         $productSIDs = $codeInfo['product_sid'] ? explode(',', $codeInfo['product_sid']) : false;
         if ($productInfo['sid'] != '-1') {
             $productSid = $productInfo['sid'];
         } else {
             $productSid = $productInfo['custom_info']['productSid'];
         }
         if ($productSIDs && in_array($productSid, $productSIDs)) {
             $currentUsesCount = SJB_PromotionsManager::getUsesCodeBySID($codeInfo['sid']);
             if ($codeInfo['maximum_uses'] != 0 && $codeInfo['maximum_uses'] > $currentUsesCount || $codeInfo['maximum_uses'] == 0) {
                 SJB_PromotionsManager::applyPromoCodeToProduct($productInfo, $codeInfo);
             }
         }
     }
 }
Пример #3
0
 /**
  * Recurring notification handlign function
  * @param array|null $callback_data Notification data
  */
 function handleRecurringNotification($callback_data)
 {
     if (SJB_Array::get($callback_data, 'txn_type') == 'subscr_cancel' || SJB_Array::get($callback_data, 'txn_type') == 'subscr_eot') {
         SJB_ContractManager::removeSubscriptionId(SJB_Array::get($callback_data, 'subscr_id'));
         return;
     }
     if (SJB_Array::get($callback_data, 'txn_type') != 'subscr_payment') {
         return;
     }
     $invoice_sid = isset($callback_data['item_number']) ? $callback_data['item_number'] : null;
     if (is_null($invoice_sid)) {
         return;
     }
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     if (is_null($invoice)) {
         return null;
     }
     $reactivation = false;
     $status = $invoice->getStatus();
     if ($invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) {
         // Пришёл рекьюринг платёж
         $invoice->setSID(null);
         $invoice->setDate(null);
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
         $reactivation = true;
     }
     $invoice->setCallbackData($callback_data);
     if ($this->isPaymentVerified($invoice) && in_array($callback_data['payment_status'], array('Completed', 'Processed'))) {
         $items = $invoice->getPropertyValue('items');
         $user_sid = $invoice->getUserSID();
         $subscriptionSID = $callback_data['custom'];
         if (!empty($items['products'])) {
             $recurringProductsInfo = array();
             foreach ($items['products'] as $key => $product) {
                 if ($product != -1) {
                     $productInfo = $invoice->getItemValue($key);
                     if ($status == SJB_Invoice::INVOICE_STATUS_PAID && $subscriptionSID == $product) {
                         $listingNumber = $productInfo['qty'];
                         $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $callback_data['subscr_id'], 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         $contract->setUserSID($user_sid);
                         $contractSID = SJB_ContractManager::getContractSIDByRecurringId($callback_data['subscr_id']);
                         SJB_ContractManager::deleteAllContractsByRecurringId($callback_data['subscr_id']);
                         $contract->setPrice($productInfo['amount']);
                         if ($contract->saveInDB()) {
                             SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                             $bannerInfo = $productInfo['banner_info'];
                             if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) {
                                 $bannersObj = new SJB_Banners();
                                 if (isset($contractSID)) {
                                     $bannerID = $bannersObj->getBannerIDByContract($contractSID);
                                     if ($bannerID) {
                                         $bannersObj->updateBannerContract($contract->getID(), $bannerID);
                                     }
                                 } else {
                                     $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                                     $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                     SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                                 }
                             }
                             if ($contract->isFeaturedProfile()) {
                                 SJB_UserManager::makeFeaturedBySID($user_sid);
                             }
                             SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                             if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                 SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo, $reactivation);
                             }
                         }
                         $recurringProductsInfo[$key] = $productInfo;
                     } elseif ($status != SJB_Invoice::INVOICE_STATUS_PAID) {
                         $listingNumber = $productInfo['qty'];
                         if ($subscriptionSID == $product) {
                             $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $callback_data['subscr_id'], 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         } else {
                             $contract = new SJB_Contract(array('product_sid' => $product, 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         }
                         $contract->setUserSID($user_sid);
                         $contract->setPrice($productInfo['amount']);
                         if ($contract->saveInDB()) {
                             SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                             $bannerInfo = $productInfo['banner_info'];
                             if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo) && $contractSID) {
                                 $bannersObj = new SJB_Banners();
                                 $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                                 $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                 SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                             }
                             if ($contract->isFeaturedProfile()) {
                                 SJB_UserManager::makeFeaturedBySID($user_sid);
                             }
                             SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                             if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                 SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo);
                             }
                         }
                     }
                 }
             }
             if ($reactivation) {
                 $invoice->setNewPropertiesToInvoice($recurringProductsInfo);
             }
             $price = isset($callback_data['payment_gross']) ? $callback_data['payment_gross'] : $invoice->getPropertyValue('total');
             $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
             $id = $this->details->getProperty('id');
             $invoice->setPropertyValue('payment_method', $id->getValue());
             SJB_InvoiceManager::saveInvoice($invoice);
             SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             $transactionID = $callback_data['txn_id'];
             $transactionInfo = array('transaction_id' => $transactionID, 'invoice_sid' => $invoice->getSID(), 'amount' => $price, 'payment_method' => $invoice->getPropertyValue('payment_method'), 'user_sid' => $invoice->getPropertyValue('user_sid'));
             $transaction = new SJB_Transaction($transactionInfo);
             SJB_TransactionManager::saveTransaction($transaction);
         }
     } else {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
         SJB_InvoiceManager::saveInvoice($invoice);
     }
 }
Пример #4
0
 public function execute()
 {
     $invoiceSID = SJB_Request::getVar('invoice_sid', null, 'default', 'int');
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $checkPaymentErrors = array();
     $currentUser = SJB_UserManager::getCurrentUser();
     if ($action == 'pay_for_products') {
         $subscribe = SJB_Request::getVar('subscribe', false);
         $subTotalPrice = SJB_Request::getVar('sub_total_price', 0);
         $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
         $codeInfo = array();
         $index = 1;
         $items = array();
         foreach ($products as $product) {
             $product_info = unserialize($product['product_info']);
             $items['products'][$index] = $product_info['sid'];
             $qty = !empty($product_info['number_of_listings']) ? $product_info['number_of_listings'] : null;
             if ($qty > 0) {
                 $items['price'][$index] = round($product_info['price'] / $qty, 2);
             } else {
                 $items['price'][$index] = round($product_info['price'], 2);
             }
             $items['amount'][$index] = $product_info['price'];
             $items['custom_item'][$index] = "";
             $items['qty'][$index] = $qty;
             $items['custom_info'][$index]['shoppingCartRecord'] = $product['sid'];
             if ($product_info['product_type'] == 'banners' && !empty($product_info['banner_info'])) {
                 $items['custom_info'][$index]['banner_info'] = $product_info['banner_info'];
             }
             $index++;
             SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product_info, $codeInfo);
         }
         $userSID = $currentUser->getSID();
         $invoiceSID = SJB_InvoiceManager::generateInvoice($items, $userSID, $subTotalPrice, SJB_System::getSystemSettings('SITE_URL') . "/create-contract/", (bool) $subscribe);
         SJB_PromotionsManager::addCodeToHistory($codeInfo, $invoiceSID, $userSID);
     }
     $gatewayId = SJB_Request::getVar('gw', false);
     if (SJB_Request::$method == SJB_Request::METHOD_POST && !$action && $gatewayId == 'authnet_sim') {
         if (isset($_REQUEST['submit'])) {
             $gateway = SJB_PaymentGatewayManager::getObjectByID($gatewayId, true);
             $subscriptionResult = $gateway->createSubscription($_REQUEST);
             if ($subscriptionResult !== true) {
                 $tp->assign('form_submit_url', $_SERVER['REQUEST_URI']);
                 $tp->assign('form_data_source', $_REQUEST);
                 $tp->assign('errors', $subscriptionResult);
                 $tp->display('recurring_payment_page.tpl');
             } else {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=true');
             }
         } else {
             $tp->assign('form_submit_url', $_SERVER['REQUEST_URI']);
             $tp->assign('form_data_source', $_REQUEST);
             $tp->display('recurring_payment_page.tpl');
         }
     } else {
         if (!is_null($invoiceSID)) {
             $invoice_info = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSID);
             $invoice = new SJB_Invoice($invoice_info);
             if (SJB_PromotionsManager::isPromoCodeExpired($invoiceSID)) {
                 $checkPaymentErrors['PROMOTION_TOO_MANY_USES'] = true;
             } else {
                 $invoice->setSID($invoiceSID);
                 if (count($invoice->isValid($invoiceSID)) == 0) {
                     $invoiceUserSID = $invoice->getPropertyValue('user_sid');
                     $currentUserSID = SJB_UserManager::getCurrentUserSID();
                     if ($invoiceUserSID === $currentUserSID) {
                         $payment_gateway_forms = SJB_InvoiceManager::getPaymentForms($invoice);
                         $tp->assign('productsNames', $invoice->getProductNames());
                         $tp->assign('gateways', $payment_gateway_forms);
                         $tp->assign('invoice_info', $invoice_info);
                     } else {
                         $checkPaymentErrors['NOT_OWNER'] = true;
                     }
                 } else {
                     $checkPaymentErrors['WRONG_INVOICE_PARAMETERS'] = true;
                 }
             }
             $tp->assign('checkPaymentErrors', $checkPaymentErrors);
             $tp->display('invoice_payment_page.tpl');
         } else {
             $tp->display('recurring_payment_page.tpl');
         }
     }
 }
Пример #5
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $invoice_sid = SJB_Request::getVar('invoice_sid', null, false, 'int');
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     $user = null;
     $errors = null;
     $userHasContract = false;
     if (!is_null($invoice)) {
         $status = $invoice->getStatus();
         if ($status == SJB_Invoice::INVOICE_STATUS_VERIFIED) {
             $userSID = $invoice->getPropertyValue('user_sid');
             $items = $invoice->getPropertyValue('items');
             $products = $items['products'];
             $user = SJB_UserManager::getObjectBySID($userSID);
             $userHasContract = $user->hasContract();
             $paymentStatus = false;
             foreach ($products as $key => $productSID) {
                 if ($productSID != -1) {
                     $product_info = $invoice->getItemValue($key);
                     $products[$key] = $product_info;
                     if (!empty($product_info['listing_type_sid'])) {
                         $listingTypeID = SJB_ListingTypeDBManager::getListingTypeIDBySID($product_info['listing_type_sid']);
                         $listingTypeName = SJB_ListingTypeManager::getListingTypeNameBySID($product_info['listing_type_sid']);
                         if (!in_array($listingTypeID, array('Job', 'Resume'))) {
                             $listingTypeName .= ' Listing';
                         }
                         $listingTypes[] = array('ID' => $listingTypeID, 'name' => $listingTypeName);
                     }
                     $listingNumber = $product_info['qty'];
                     $contract = new SJB_Contract(array('product_sid' => $productSID, 'numberOfListings' => $listingNumber, 'is_recurring' => $invoice->isRecurring()));
                     $contract->setUserSID($userSID);
                     $contract->setPrice($items['amount'][$key]);
                     if ($contract->saveInDB()) {
                         SJB_ListingManager::activateListingsAfterPaid($userSID, $productSID, $contract->getID(), $listingNumber);
                         SJB_ShoppingCart::deleteItemFromCartBySID($product_info['shoppingCartRecord'], $userSID);
                         $bannerInfo = $product_info['banner_info'];
                         $paymentStatus = true;
                         if ($product_info['product_type'] == 'banners' && !empty($bannerInfo)) {
                             $bannersObj = new SJB_Banners();
                             $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $userSID, $contract->getID());
                             $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                             SJB_AdminNotifications::sendAdminBannerAddedLetter($userSID, $bannerGroup);
                         }
                         if ($contract->isFeaturedProfile()) {
                             SJB_UserManager::makeFeaturedBySID($userSID);
                         }
                         if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($userSID)) {
                             SJB_Notifications::sendSubscriptionActivationLetter($userSID, $product_info);
                         }
                     }
                 } else {
                     if (isset($items['custom_info'][$key]['type'])) {
                         $products[$key] = $this->updateListing($items['custom_info'][$key]['type'], $key, $items, $userSID);
                     } else {
                         $products[$key] = array('name' => $items['custom_item'][$key]);
                     }
                     $paymentStatus = true;
                 }
             }
             if ($paymentStatus) {
                 $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
                 SJB_InvoiceManager::saveInvoice($invoice);
                 SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             }
             if (isset($listingTypes)) {
                 $tp->assign('listingTypes', $listingTypes);
             }
             $tp->assign('products', $products);
         } else {
             $errors['INVOICE_IS_NOT_VERIFIED'] = 1;
         }
     } else {
         $errors['INVALID_INVOICE_ID'] = 1;
     }
     if (!$errors) {
         $subTotal = $invoice->getPropertyValue('sub_total');
         if (empty($subTotal)) {
             SJB_Statistics::addStatisticsFromInvoice($invoice);
         }
         $isUserJustRegistered = SJB_UserManager::isCurrentUserJustRegistered();
         if (isset($items['products']) && count($items['products']) == 1 && $isUserJustRegistered && !$userHasContract) {
             $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user->getUserGroupSID());
             $pageId = !empty($userGroupInfo['after_registration_redirect_to']) ? $userGroupInfo['after_registration_redirect_to'] : '';
             $redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
             SJB_HelperFunctions::redirect($redirectUrl);
         }
     }
     $tp->assign('errors', $errors);
     $tp->display('create_contract.tpl');
 }
Пример #6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('template', 'manage_invoices.tpl');
     $searchTemplate = SJB_Request::getVar('search_template', 'invoice_search_form.tpl');
     $action = SJB_Request::getVar('action_name');
     if (!empty($action)) {
         $invoicesSIDs = SJB_Request::getVar('invoices', array());
         $_REQUEST['restore'] = 1;
         switch ($action) {
             case 'paid':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     $invoice = SJB_InvoiceManager::getObjectBySID($invoiceSID);
                     $userSID = $invoice->getPropertyValue('user_sid');
                     if (SJB_UserManager::isUserExistsByUserSid($userSID)) {
                         $items = $invoice->getPropertyValue('items');
                         $productSIDs = $items['products'];
                         foreach ($productSIDs as $key => $productSID) {
                             if ($productSID != -1) {
                                 if (SJB_ProductsManager::isProductExists($productSID)) {
                                     $productInfo = $invoice->getItemValue($key);
                                     $listingNumber = $productInfo['qty'];
                                     $contract = new SJB_Contract(array('product_sid' => $productSID, 'numberOfListings' => $listingNumber, 'is_recurring' => $invoice->isRecurring()));
                                     $contract->setUserSID($userSID);
                                     $contract->setPrice($items['amount'][$key]);
                                     if ($contract->saveInDB()) {
                                         SJB_ListingManager::activateListingsAfterPaid($userSID, $productSID, $contract->getID(), $listingNumber);
                                         SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $userSID);
                                         $bannerInfo = $productInfo['banner_info'];
                                         if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) {
                                             $bannersObj = new SJB_Banners();
                                             $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $userSID, $contract->getID());
                                             $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                             SJB_AdminNotifications::sendAdminBannerAddedLetter($userSID, $bannerGroup);
                                         }
                                         if ($contract->isFeaturedProfile()) {
                                             SJB_UserManager::makeFeaturedBySID($userSID);
                                         }
                                         if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($userSID)) {
                                             SJB_Notifications::sendSubscriptionActivationLetter($userSID, $productInfo);
                                         }
                                     }
                                 }
                             } else {
                                 $type = SJB_Array::getPath($items, 'custom_info/' . $key . '/type');
                                 switch ($type) {
                                     case 'featuredListing':
                                         $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id');
                                         SJB_ListingManager::makeFeaturedBySID($listingId);
                                         break;
                                     case 'priorityListing':
                                         $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id');
                                         SJB_ListingManager::makePriorityBySID($listingId);
                                         break;
                                     case 'activateListing':
                                         $listingsIds = explode(",", SJB_Array::getPath($items, 'custom_info/' . $key . '/listings_ids'));
                                         foreach ($listingsIds as $listingId) {
                                             SJB_ListingManager::activateListingBySID($listingId);
                                         }
                                         break;
                                 }
                             }
                         }
                         SJB_Statistics::addStatisticsFromInvoice($invoice);
                     }
                     $total = $invoice->getPropertyValue('total');
                     if ($total > 0) {
                         $gatewayID = $invoice->getPropertyValue('payment_method');
                         $gatewayID = isset($gatewayID) ? $gatewayID : 'cash_payment';
                         $transactionId = md5($invoiceSID . $gatewayID);
                         $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoiceSID, 'amount' => $total, 'payment_method' => $gatewayID, 'user_sid' => $invoice->getPropertyValue('user_sid'));
                         $transaction = new SJB_Transaction($transactionInfo);
                         SJB_TransactionManager::saveTransaction($transaction);
                     }
                     SJB_InvoiceManager::markPaidInvoiceBySID($invoiceSID);
                     SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-invoices/");
                 break;
             case 'unpaid':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     SJB_InvoiceManager::markUnPaidInvoiceBySID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/');
                 break;
             case 'delete':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     SJB_InvoiceManager::deleteInvoiceBySID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/');
                 break;
             default:
                 unset($_REQUEST['restore']);
                 break;
         }
     }
     /***************************************************************/
     $_REQUEST['action'] = 'search';
     $invoice = new SJB_Invoice(array());
     $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserDBManager::getUserSIDsLikeSearchString'));
     $searchFormBuilder = new SJB_SearchFormBuilder($invoice);
     $criteriaSaver = new SJB_InvoiceCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria());
     }
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice);
     $searchFormBuilder->setCriteria($criteria);
     $searchFormBuilder->registerTags($tp);
     $tp->display($searchTemplate);
     /********************** S O R T I N G *********************/
     $paginator = new SJB_InvoicePagination();
     $innerJoin = false;
     if ($paginator->sortingField == 'username') {
         $innerJoin = array('users' => array('sort_field' => array(36 => array('FirstName', 'LastName'), 41 => 'CompanyName'), 'join_field' => 'sid', 'join_field2' => 'user_sid', 'main_table' => 'invoices', 'join' => 'LEFT JOIN'));
     }
     $searcher = new SJB_InvoiceSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder, $innerJoin);
     $foundInvoices = array();
     $foundInvoicesInfo = array();
     if (SJB_Request::getVar('action', '') == 'search') {
         $foundInvoices = $searcher->getObjectsByCriteria($criteria, $aliases);
         if (empty($foundInvoices) && $paginator->currentPage != 1) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/?page=1');
         }
         $criteriaSaver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $foundInvoices = $criteriaSaver->getObjectsFromSession();
     }
     foreach ($foundInvoices as $id => $invoice) {
         $subUserSID = $invoice->getPropertyValue('subuser_sid');
         if ($subUserSID) {
             $subUserInfo = SJB_UserManager::getUserInfoBySID($subUserSID);
             $parentInfo = SJB_UserManager::getUserInfoBySID($subUserInfo['parent_sid']);
             $username = $parentInfo['CompanyName'];
         } else {
             $userSID = $invoice->getPropertyValue('user_sid');
             $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
             if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'Employer') {
                 $username = $userInfo['CompanyName'];
             } else {
                 if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'JobSeeker') {
                     $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'];
                 } else {
                     $username = $userInfo['username'];
                 }
             }
         }
         $invoice->addProperty(array('id' => 'sid', 'type' => 'string', 'value' => $invoice->getSID()));
         $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => $username));
         $foundInvoices[$id] = $invoice;
         $foundInvoicesInfo[$invoice->getSID()] = SJB_InvoiceManager::getInvoiceInfoBySID($invoice->getSID());
         $foundInvoicesInfo[$invoice->getSID()]['userExists'] = !empty($username) ? 1 : 0;
     }
     /****************************************************************/
     $paginator->setItemsCount($searcher->getAffectedRows());
     $form_collection = new SJB_FormCollection($foundInvoices);
     $form_collection->registerTags($tp);
     $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     $tp->assign("found_invoices", $foundInvoicesInfo);
     $tp->display($template);
 }
Пример #7
0
 function handleRecurringNotification($callback_data)
 {
     if (!isset($callback_data['sale_id']) || !isset($callback_data['vendor_id']) || !isset($callback_data['invoice_id'])) {
         return;
     }
     $properties = $this->getProperties();
     $secret_word = $properties['secret_word']->getValue();
     $expected_md5 = strtoupper(md5($callback_data['sale_id'] . $callback_data['vendor_id'] . $callback_data['invoice_id'] . $secret_word));
     if (!isset($callback_data['md5_hash']) || $callback_data['md5_hash'] != $expected_md5) {
         return;
         //платеж не от 2Checkout
     }
     $invoice_sid = null;
     if (isset($callback_data['vendor_order_id'])) {
         $invoice_sid = $callback_data['vendor_order_id'];
     }
     if (is_null($invoice_sid)) {
         return;
     }
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     if (is_null($invoice)) {
         return null;
     }
     switch ($callback_data['message_type']) {
         case 'RECURRING_INSTALLMENT_SUCCESS':
             if (empty($callback_data['sale_id'])) {
                 return null;
             }
             $vendorApi = $this->initAPI();
             if (!($saleDetails = $this->getSaleDetails($vendorApi, $callback_data['sale_id']))) {
                 return null;
             }
             $itemCount = $callback_data['item_count'];
             $userSid = $invoice->getUserSID();
             $paymentHandler = new SJB_PaymentHandler($invoice->getSID(), '2checkout');
             $items = $invoice->getPropertyValue('items');
             if (!empty($items['products'])) {
                 $recurringProductsInfo = array();
                 for ($i = 1; $i < $itemCount + 1; $i++) {
                     if (!empty($callback_data['item_id_' . $i])) {
                         $invoice->setSID(null);
                         $invoice->setDate(null);
                         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
                         $reactivation = true;
                         foreach ($items['products'] as $key => $product) {
                             if ($product == $callback_data['item_id_' . $i]) {
                                 $productInfo = $invoice->getItemValue($key);
                                 $recurringID = !empty($callback_data['sale_id']) ? $callback_data['sale_id'] : false;
                                 $recurringProductsInfo[$key] = $productInfo;
                                 $paymentHandler->setProduct($productInfo);
                                 $paymentHandler->setRecurringID($recurringID);
                                 $invoiceID = 0;
                                 if ($saleDetails && is_array($saleDetails)) {
                                     foreach ($saleDetails as $lineitems) {
                                         if ($product == $lineitems->vendor_product_id) {
                                             $invoiceID = $lineitems->invoice_id;
                                         }
                                     }
                                 }
                                 $paymentHandler->createContract($userSid, $invoiceID, $reactivation, 'active');
                             }
                         }
                     }
                 }
                 $invoice->setNewPropertiesToInvoice($recurringProductsInfo);
                 $invoice->setCallbackData($callback_data);
                 $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
                 $id = $this->details->getProperty('id');
                 $invoice->setPropertyValue('payment_method', $id->getValue());
                 SJB_InvoiceManager::saveInvoice($invoice);
                 SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
                 $this->processTransaction($callback_data, $invoice);
             }
             break;
         case 'ORDER_CREATED':
         case 'FRAUD_STATUS_CHANGED':
             if (empty($callback_data['fraud_status']) || !in_array($callback_data['fraud_status'], array('pass', 'wait'))) {
                 return;
             } else {
                 $fraudStatus = $callback_data['fraud_status'];
             }
             $saleDetails = false;
             if ($callback_data['sale_id']) {
                 $vendorApi = $this->initAPI();
                 if (!($saleDetails = $this->getSaleDetails($vendorApi, $callback_data['sale_id']))) {
                     return null;
                 }
             }
             $itemCount = $callback_data['item_count'];
             $user_sid = $invoice->getUserSID();
             $paymentHandler = new SJB_PaymentHandler($invoice->getSID(), '2checkout');
             $items = $invoice->getPropertyValue('items');
             if (!empty($items['products'])) {
                 $reactivation = false;
                 for ($i = 1; $i < $itemCount + 1; $i++) {
                     if (!empty($callback_data['item_id_' . $i])) {
                         foreach ($items['products'] as $key => $product) {
                             $recurring = !empty($callback_data['item_rec_install_billed_' . $i]) ? true : false;
                             if ($product == $callback_data['item_id_' . $i]) {
                                 $productInfo = $invoice->getItemValue($key);
                                 $recurringID = false;
                                 if ($recurring) {
                                     $recurringID = !empty($callback_data['sale_id']) ? $callback_data['sale_id'] : false;
                                     $recurringProductsInfo[$key] = $productInfo;
                                 }
                                 $paymentHandler->setProduct($productInfo);
                                 $paymentHandler->setRecurringID($recurringID);
                                 $invoiceID = 0;
                                 if ($saleDetails && is_array($saleDetails)) {
                                     foreach ($saleDetails as $lineitems) {
                                         if ($product == $lineitems->vendor_product_id) {
                                             $invoiceID = $lineitems->invoice_id;
                                         }
                                     }
                                 }
                                 $status = 'active';
                                 if ($fraudStatus != 'pass') {
                                     $status = 'pending';
                                 }
                                 $paymentHandler->createContract($user_sid, $invoiceID, $reactivation, $status);
                             }
                         }
                     } else {
                         foreach ($items['products'] as $product) {
                             if ($product == -1) {
                                 $type = $items['custom_info'][1]['type'];
                                 $paymentHandler->setProduct($items['custom_info'][1]);
                                 switch ($type) {
                                     case 'featuredListing':
                                         $paymentHandler->makeFeatured($invoice);
                                         break;
                                     case 'priorityListing':
                                         $paymentHandler->makePriority($invoice);
                                         break;
                                     case 'activateListing':
                                         $paymentHandler->activateListing($invoice);
                                         break;
                                 }
                             }
                         }
                     }
                 }
             } else {
                 if (empty($fraudStatus) || $fraudStatus != 'pass') {
                     return;
                 }
             }
             $invoice->setCallbackData($callback_data);
             if ($fraudStatus == 'pass') {
                 $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
             }
             $id = $this->details->getProperty('id');
             $invoice->setPropertyValue('payment_method', $id->getValue());
             SJB_InvoiceManager::saveInvoice($invoice);
             if ($fraudStatus != 'pass') {
                 return;
             }
             SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             $this->processTransaction($callback_data, $invoice);
             break;
         case 'RECURRING_INSTALLMENT_FAILED':
             $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
             SJB_InvoiceManager::saveInvoice($invoice);
             break;
         case 'REFUND_ISSUED':
             $itemCount = $callback_data['item_count'];
             $user_sid = $invoice->getUserSID();
             $paymentHandler = new SJB_PaymentHandler($invoice->getSID(), '2checkout');
             $items = $invoice->getPropertyValue('items');
             if (!empty($items['products'])) {
                 for ($i = 1; $i <= $itemCount; $i++) {
                     if (!empty($callback_data['item_id_' . $i])) {
                         $paymentHandler->setProduct($callback_data['item_id_' . $i]);
                         $paymentHandler->deleteContract($callback_data['invoice_id'], $callback_data['item_id_' . $i], $user_sid);
                     }
                 }
                 foreach ($items['products'] as $product) {
                     if ($product == -1) {
                         $type = $items['custom_info'][1]['type'];
                         $paymentHandler->setProduct($items['custom_info'][1]);
                         switch ($type) {
                             case 'featured_listing':
                                 $paymentHandler->unmakeFeatured($user_sid, $invoice->getPropertyValue('total'));
                                 break;
                             case 'priority_listing':
                                 $paymentHandler->unmakePriority($user_sid, $invoice->getPropertyValue('total'));
                                 break;
                             case 'activate_listing':
                                 $paymentHandler->deactivateListing($user_sid, $invoice->getPropertyValue('total'));
                                 break;
                             default:
                                 break;
                         }
                     }
                 }
             }
             $invoice->setCallbackData($callback_data);
             $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
             SJB_InvoiceManager::saveInvoice($invoice);
             break;
         case 'RECURRING_STOPPED':
         case 'RECURRING_COMPLETE':
         default:
             break;
     }
 }
Пример #8
0
 function createSubscription($payment_data)
 {
     $validation_result = $this->validatePayment($payment_data);
     if ($validation_result !== true) {
         return $validation_result;
     }
     $properties = $this->details->getProperties();
     $api_login_id = $properties['authnet_api_login_id']->getValue();
     $transaction_key = $properties['authnet_api_transaction_key']->getValue();
     $use_test_account = $properties['authnet_use_test_account']->getValue();
     $invoice = SJB_InvoiceManager::getObjectBySID($payment_data['item_number']);
     if (empty($invoice)) {
         return;
     }
     $items = $invoice->getPropertyValue('items');
     $taxInfo = $invoice->getPropertyValue('tax_info');
     if (!empty($items['products'])) {
         foreach ($items['products'] as $key => $product) {
             if ($product != -1) {
                 $product_info = $invoice->getItemValue($key);
                 $payment_data['item_number'] = $invoice->getSID();
                 $payment_data['item_name'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_description'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_amount'] = $product_info['amount'];
                 if ($taxInfo && !$taxInfo['price_includes_tax']) {
                     $payment_data['x_amount'] += SJB_TaxesManager::getTaxAmount($payment_data['x_amount'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
                 }
                 $aimProcessor = new AuthnetAIMProcessor($api_login_id, $transaction_key, $use_test_account);
                 $aimProcessor->setTransactionType('AUTH_CAPTURE');
                 $aimProcessor->setParameter('x_login', $api_login_id);
                 $aimProcessor->setParameter('x_tran_key', $transaction_key);
                 $aimProcessor->setParameter('x_card_num', $payment_data['x_card_num']);
                 $aimProcessor->setParameter('x_amount', $payment_data['x_amount']);
                 $aimProcessor->setParameter('x_exp_date', $payment_data['x_exp_date']);
                 $aimProcessor->process();
                 if (!$aimProcessor->isApproved()) {
                     return array($aimProcessor->getResponseMessage());
                 }
                 $recurringID = null;
                 if (!empty($product_info['recurring'])) {
                     $product = new SJB_Product($product_info, $product_info['product_type']);
                     $expiration_period = $product->getExpirationPeriod();
                     $arbProcessor = new AuthnetARBProcessor($api_login_id, $transaction_key, $use_test_account);
                     $arbProcessor->setParameter('refID', $payment_data['item_number']);
                     $arbProcessor->setParameter('subscrName', $payment_data['x_description']);
                     $arbProcessor->setParameter('interval_length', $expiration_period);
                     $arbProcessor->setParameter('interval_unit', 'days');
                     $arbProcessor->setParameter('startDate', date("Y-m-d", strtotime("+ {$expiration_period} days")));
                     $arbProcessor->setParameter('totalOccurrences', 9999);
                     $arbProcessor->setParameter('trialOccurrences', 0);
                     $arbProcessor->setParameter('amount', $payment_data['x_amount']);
                     $arbProcessor->setParameter('trialAmount', 0.0);
                     $arbProcessor->setParameter('cardNumber', $payment_data['x_card_num']);
                     $arbProcessor->setParameter('expirationDate', $payment_data['x_exp_date']);
                     $arbProcessor->setParameter('orderInvoiceNumber', $payment_data['item_number']);
                     $arbProcessor->setParameter('orderDescription', $payment_data['x_description']);
                     $arbProcessor->setParameter('firstName', $payment_data['x_first_name']);
                     $arbProcessor->setParameter('lastName', $payment_data['x_last_name']);
                     $arbProcessor->setParameter('company', $payment_data['x_company']);
                     $arbProcessor->setParameter('address', $payment_data['x_address']);
                     $arbProcessor->setParameter('city', $payment_data['x_city']);
                     $arbProcessor->setParameter('state', $payment_data['x_state']);
                     $arbProcessor->setParameter('zip', $payment_data['x_zip']);
                     $arbProcessor->createAccount();
                     if (!$arbProcessor->isSuccessful()) {
                         return array($arbProcessor->getResponse());
                     }
                     $recurringID = $arbProcessor->getSubscriberID();
                 }
                 $user_sid = $invoice->getUserSID();
                 $listingNumber = $product_info['qty'];
                 $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $recurringID, 'gateway_id' => 'authnet_sim', 'numberOfListings' => $listingNumber));
                 $contract->setUserSID($user_sid);
                 $contract->setPrice($product_info['amount']);
                 if ($contract->saveInDB()) {
                     SJB_ShoppingCart::deleteItemFromCartBySID($product_info['shoppingCartRecord'], $user_sid);
                     $bannerInfo = $product_info['banner_info'];
                     if ($product_info['product_type'] == 'banners' && !empty($bannerInfo)) {
                         $bannersObj = new SJB_Banners();
                         $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                         $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                         SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                     }
                     if ($contract->isFeaturedProfile()) {
                         SJB_UserManager::makeFeaturedBySID($user_sid);
                     }
                     if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                         SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $product_info);
                     }
                 }
             }
         }
         $invoice->setCallbackData($payment_data);
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
         SJB_InvoiceManager::saveInvoice($invoice);
         SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
     }
     return true;
 }
Пример #9
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $template = 'manage_promotions.tpl';
     $errors = array();
     switch ($action) {
         case 'add':
             $promotionCodeInfo = $_REQUEST;
             $formSubmitted = SJB_Request::getVar('event', false);
             $formSubmitted = $formSubmitted == 'save_code' ? true : false;
             $template = 'add_promotion.tpl';
             if (!isset($promotionCodeInfo['active'])) {
                 $promotionCodeInfo['active'] = 1;
             }
             $promotionCode = new SJB_Promotions($promotionCodeInfo);
             $addCodeForm = new SJB_Form($promotionCode);
             $addCodeForm->registerTags($tp);
             if ($formSubmitted && $addCodeForm->isDataValid($errors)) {
                 SJB_PromotionsManager::savePromotionCode($promotionCode);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/promotions/");
             }
             $formFields = $addCodeForm->getFormFieldsInfo();
             $tp->assign("form_fields", $formFields);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             break;
         case 'edit':
             $template = 'edit_promotion.tpl';
             $promotionSID = SJB_Request::getVar('sid', false);
             $formSubmitted = SJB_Request::getVar('event', false);
             $formSubmitted = $formSubmitted == 'save_code' ? true : false;
             $promotionCodeInfo = SJB_PromotionsManager::getCodeInfoBySID($promotionSID);
             if ($promotionCodeInfo) {
                 $promotionCodeInfo = array_merge($promotionCodeInfo, $_REQUEST);
                 $promotionCode = new SJB_Promotions($promotionCodeInfo);
                 $addCodeForm = new SJB_Form($promotionCode);
                 $addCodeForm->registerTags($tp);
                 $promotionCode->setSID($promotionCodeInfo['sid']);
                 $i18n = SJB_I18N::getInstance();
                 $endDate = !empty($promotionCodeInfo['end_date']) ? $i18n->getInput('date', $promotionCodeInfo['end_date']) : '';
                 if ($formSubmitted && $addCodeForm->isDataValid($errors) && (empty($endDate) || $endDate >= date('Y-m-d') || !$promotionCodeInfo['active'])) {
                     SJB_PromotionsManager::savePromotionCode($promotionCode);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/promotions/");
                 } elseif ($formSubmitted && $promotionCodeInfo['active'] == 1 && $endDate < date('Y-m-d')) {
                     $errors["'Active'"] = 'Please change the expiration date first';
                 }
                 $formFields = $addCodeForm->getFormFieldsInfo();
                 $tp->assign("form_fields", $formFields);
                 $tp->assign("sid", $promotionSID);
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             } else {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/promotions/");
             }
             break;
         case 'delete':
             $promotionSID = SJB_Request::getVar('sid', 0);
             SJB_PromotionsManager::deleteCodeBySID($promotionSID);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/promotions/");
             break;
         case 'deactivate':
             $promotionSID = SJB_Request::getVar('sid', false);
             SJB_PromotionsManager::deactivateCodeBySID($promotionSID);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/promotions/");
             break;
         case 'setting':
             $enablePromotionCodes = SJB_Request::getVar('enable_promotion_codes', 0);
             SJB_Settings::updateSetting('enable_promotion_codes', $enablePromotionCodes);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/promotions/");
             break;
         case 'activate':
             $promotionSID = SJB_Request::getVar('sid', false);
             $promotionCodeInfo = SJB_PromotionsManager::getCodeInfoBySID($promotionSID);
             if (empty($promotionCodeInfo['end_date']) || $promotionCodeInfo['end_date'] > date('Y-m-d')) {
                 $currentUses = SJB_PromotionsManager::getUsesCodeBySID($promotionSID);
                 $maxUses = $promotionCodeInfo['maximum_uses'];
                 if (!$maxUses || $maxUses > $currentUses) {
                     SJB_PromotionsManager::activateCodeBySID($promotionSID);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/promotions/");
                 } else {
                     $errors['MAX_USES_ACHIEVED'] = true;
                 }
             } else {
                 $errors['DATE_IS_NOT_VALID'] = true;
                 $tp->assign('errors', $errors);
             }
         default:
             $promotions = SJB_PromotionsManager::getAllPromotionsInfo();
             foreach ($promotions as $key => $promotion) {
                 $promotions[$key]['uses'] = SJB_PromotionsManager::getUsesCodeBySID($promotion['sid']);
                 if ($promotions[$key]['uses'] >= $promotions[$key]['maximum_uses'] && $promotions[$key]['maximum_uses'] != 0) {
                     $promotions[$key]['active'] = 'used';
                 }
             }
             $currency = SJB_CurrencyManager::getDefaultCurrency();
             $tp->assign('currency', $currency);
             $tp->assign('promotions', $promotions);
             break;
     }
     $tp->assign('errors', $errors);
     $tp->display($template);
 }
Пример #10
0
 /**
  * @param $invoiceSid
  * @return bool
  */
 public static function isPromoCodeExpired($invoiceSid)
 {
     $codeId = SJB_PromotionsManager::getCodeSidByInvoiceSID($invoiceSid);
     $codeInfo = SJB_PromotionsManager::getCodeInfoBySID($codeId);
     if (isset($codeInfo)) {
         $currentUsesCount = SJB_PromotionsManager::getUsesCodeBySID($codeInfo['sid']);
         return $codeInfo['maximum_uses'] != 0 && $codeInfo['maximum_uses'] <= $currentUsesCount;
     }
     return false;
 }