Пример #1
0
 public static function addStatisticsFromInvoice(SJB_Invoice $invoice)
 {
     $items = $invoice->getItemsInfo();
     if (empty($items)) {
         $items = $invoice->getPropertyValue('items');
     }
     foreach ($items['products'] as $key => $productSID) {
         $featured = 0;
         $priority = 0;
         $activate = 0;
         $type = 'product';
         if ($productSID == -1) {
             $productSID = isset($items['custom_info'][$key]['productSid']) ? $items['custom_info'][$key]['productSid'] : $invoice->getSID();
             $customType = $items['custom_info'][$key]['type'];
             switch ($customType) {
                 case 'activateListing':
                     $activate = 1;
                     break;
                 case 'priorityListing':
                     $priority = 1;
                     break;
                 case 'featuredListing':
                     $featured = 1;
                     break;
                 default:
                     $type = $customType;
             }
         }
         self::addStatistics('payment', $type, $productSID, false, $featured, $priority, $invoice->getUserSID(), $items['amount'][$key], 0, $activate);
     }
 }
 private function assignInvoiceInfo()
 {
     $invoiceInfo['invoiceNumber'] = $this->invoice->getSID();
     $invoiceInfo['description'] = $this->invoice->getProductNames();
     $invoiceInfo['totalPrice'] = $this->invoice->getPropertyValue('total');
     $invoiceInfo['currencyCode'] = SJB_Payment_PaypalProFillPaymentCard::getCurrencyCode();
     $this->getTemplateProcessor()->assign('invoiceInfo', $invoiceInfo);
 }
Пример #3
0
 /**
  * @param SJB_Invoice $invoice
  * @return bool
  */
 public function checkPaymentAmount(SJB_Invoice $invoice)
 {
     $priceFromCallbackData = SJB_Request::getVar($this->amountField);
     //verifying that the item amounts match the amounts that you charge
     if ($invoice->getPropertyValue('total') != $priceFromCallbackData) {
         $this->errors['AMOUNT_IS_NOT_MATCH'] = 1;
         return false;
     }
     return true;
 }
Пример #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();
     $template = 'edit_invoice.tpl';
     $errors = array();
     $invoiceErrors = array();
     $invoiceSID = SJB_Request::getVar('sid', false);
     $action = SJB_Request::getVar('action', false);
     $tcpdfError = SJB_Request::getVar('error', false);
     if ($tcpdfError) {
         $invoiceErrors[] = $tcpdfError;
     }
     $invoiceInfo = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSID);
     $user_structure = null;
     if ($invoiceInfo) {
         $product_info = array();
         if (array_key_exists('custom_info', $invoiceInfo['items'])) {
             $product_info = $invoiceInfo['items']['custom_info'];
         }
         $invoiceInfo = array_merge($invoiceInfo, $_REQUEST);
         $invoiceInfo['items']['custom_info'] = $product_info;
         $includeTax = $invoiceInfo['include_tax'];
         $invoice = new SJB_Invoice($invoiceInfo);
         $invoice->setSID($invoiceSID);
         $userSID = $invoice->getPropertyValue('user_sid');
         $userExists = SJB_UserManager::isUserExistsByUserSid($userSID);
         $subUserSID = $invoice->getPropertyValue('subuser_sid');
         if (!empty($subUserSID)) {
             $userInfo = SJB_UserManager::getUserInfoBySID($subUserSID);
             $username = $userInfo['username'] . '/' . $userInfo['email'];
         } else {
             $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
             $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'] . ' ' . $userInfo['ContactName'] . ' ' . $userInfo['CompanyName'] . '/' . $userInfo['email'];
         }
         $taxInfo = $invoice->getPropertyValue('tax_info');
         $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userInfo['user_group_sid']);
         $products = array();
         foreach ($productsSIDs as $key => $productSID) {
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             if (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 $volumeBasedPricing = $productInfo['volume_based_pricing'];
                 $minListings = min($volumeBasedPricing['listings_range_from']);
                 $maxListings = max($volumeBasedPricing['listings_range_to']);
                 $countListings = array();
                 for ($i = $minListings; $i <= $maxListings; $i++) {
                     $countListings[$i]['number_of_listings'] = $i;
                     for ($j = 1; $j <= count($volumeBasedPricing['listings_range_from']); $j++) {
                         if ($i >= $volumeBasedPricing['listings_range_from'][$j] && $i <= $volumeBasedPricing['listings_range_to'][$j]) {
                             $countListings[$i]['price'] = $volumeBasedPricing['price_per_unit'][$j];
                         }
                     }
                 }
                 $productInfo['count_listings'] = $countListings;
             }
             $products[$key] = $productInfo;
         }
         $addForm = new SJB_Form($invoice);
         $addForm->registerTags($tp);
         $tp->assign('userExists', $userExists);
         $tp->assign('products', $products);
         $tp->assign('invoice_sid', $invoiceSID);
         $tp->assign('include_tax', $includeTax);
         $tp->assign('username', trim($username));
         if ($action) {
             switch ($action) {
                 case 'save':
                 case 'apply':
                     $invoiceErrors = $invoice->isValid();
                     if (empty($invoiceErrors) && $addForm->isDataValid($errors)) {
                         $invoice->setFloatNumbersIntoValidFormat();
                         SJB_InvoiceManager::saveInvoice($invoice);
                         if ($action == 'save') {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/manage-invoices/');
                         }
                     } else {
                         $invoiceDate = SJB_I18N::getInstance()->getInput('date', $invoice->getPropertyValue('date'));
                         $invoice->setPropertyValue('date', $invoiceDate);
                     }
                     $invoice->setFloatNumbersIntoValidFormat();
                     $taxInfo['tax_amount'] = SJB_I18N::getInstance()->getInput('float', $taxInfo['tax_amount']);
                     break;
                 case 'print':
                 case 'download_pdf_version':
                     $user = SJB_UserManager::getObjectBySID($userSID);
                     $user_structure = SJB_UserManager::createTemplateStructureForUser($user);
                     $template = 'print_invoice.tpl';
                     $username = SJB_Array::get($user_structure, 'CompanyName') . ' ' . SJB_Array::get($user_structure, 'FirstName') . ' ' . SJB_Array::get($user_structure, 'LastName');
                     $tp->assign('username', trim($username));
                     $tp->assign('user', $user_structure);
                     $tp->assign('tax', $taxInfo);
                     if ($action == 'download_pdf_version') {
                         $template = 'invoice_to_pdf.tpl';
                         $filename = 'invoice_' . $invoiceSID . '.pdf';
                         try {
                             SJB_HelperFunctions::html2pdf($tp->fetch($template), $filename);
                             exit;
                         } catch (Exception $e) {
                             SJB_Error::writeToLog($e->getMessage());
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/edit-invoice/?sid=' . $invoiceSID . '&error=TCPDF_ERROR');
                         }
                     }
                     break;
                 case 'send_invoice':
                     $result = SJB_Notifications::sendInvoiceToCustomer($invoiceSID, $userSID);
                     if ($result) {
                         echo SJB_I18N::getInstance()->gettext("Backend", "Invoice successfully sent");
                     } else {
                         echo SJB_I18N::getInstance()->gettext("Backend", "Invoice not sent");
                     }
                     exit;
                     break;
             }
         }
         $transactions = SJB_TransactionManager::getTransactionsByInvoice($invoiceSID);
         $tp->assign('tax', $taxInfo);
         $tp->assign('transactions', $transactions);
     } else {
         $tp->assign('action', 'edit');
         $errors[] = 'WRONG_INVOICE_ID_SPECIFIED';
         $template = 'errors.tpl';
     }
     $tp->assign("errors", array_merge($errors, $invoiceErrors));
     $tp->display($template);
 }