示例#1
0
 /**
  * @param  $invoice SJB_Invoice
  * @return array
  */
 function getFormFields($invoice)
 {
     $form_fields = array();
     $properties = $this->details->getProperties();
     $id = $properties['id']->getValue();
     if ($invoice->isRecurring()) {
         // hard-coded fields
         $form_fields['cmd'] = '_xclick-subscriptions';
         $form_fields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/notifications/{$id}/";
         $form_fields['return'] = SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=true';
         $form_fields['src'] = '1';
         $recurringProduct = array();
         $products = array();
         $items = $invoice->getPropertyValue('items');
         if (!empty($items['products'])) {
             foreach ($items['products'] as $key => $product) {
                 if ($product != -1) {
                     $productInfo = $invoice->getItemValue($key);
                     if (!empty($productInfo['recurring']) && !$recurringProduct) {
                         $recurringProduct = $productInfo;
                     }
                     $products[] = $productInfo;
                 }
             }
         }
         $taxInfo = $invoice->getPropertyValue('tax_info');
         if ($taxInfo && !$taxInfo['price_includes_tax']) {
             $recurringProduct['price'] += SJB_TaxesManager::getTaxAmount($recurringProduct['price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
         }
         $product = new SJB_Product($recurringProduct, $recurringProduct['product_type']);
         if (count($products) > 1) {
             $form_fields['a1'] = $invoice->getPropertyValue('total');
             $form_fields['p1'] = $product->getExpirationPeriod();
             $form_fields['t1'] = 'D';
         }
         $form_fields['a3'] = $recurringProduct['price'];
         $form_fields['p3'] = $product->getExpirationPeriod();
         $form_fields['t3'] = 'D';
         $form_fields['custom'] = $recurringProduct['sid'];
         $form_fields['no_note'] = '1';
         $form_fields['no_shipping'] = '1';
     } else {
         // hard-coded fields
         $form_fields['cmd'] = '_xclick';
         $form_fields['amount'] = $invoice->getPropertyValue('total');
         $form_fields['return'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
         $form_fields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
     }
     $form_fields['cancel_return'] = SJB_System::getSystemSettings('SITE_URL') . "/my-account/";
     $form_fields['rm'] = 2;
     // POST method for call back
     // configuration fields
     $form_fields['business'] = $properties['paypal_account_email']->getValue();
     $form_fields['currency_code'] = $properties['currency_code']->getValue();
     // payment-related fields
     $form_fields['item_name'] = $invoice->getProductNames();
     $form_fields['item_number'] = $invoice->getSID();
     return $form_fields;
 }
示例#2
0
 function getFormFields($invoice)
 {
     $form_fields = array();
     $properties = $this->details->getProperties();
     $id = $properties['id']->getValue();
     $form_fields['sid'] = $properties['2co_account_id']->getValue();
     $form_fields['mode'] = '2CO';
     $form_fields['merchant_order_id'] = $invoice->getSID();
     $i = 1;
     $items = $invoice->getPropertyValue('items');
     $taxInfo = $invoice->getPropertyValue('tax_info');
     foreach ($items['products'] as $key => $product) {
         if ($product == -1) {
             $form_fields['li_' . $i . '_name'] = $items['custom_item'][$key];
         } else {
             $productInfo = $invoice->getItemValue($key);
             $form_fields['li_' . $i . '_name'] = $productInfo['name'];
             $form_fields['li_' . $i . '_product_id'] = $product;
             if ($invoice->isRecurring() && !empty($productInfo['recurring'])) {
                 $form_fields['li_' . $i . '_duration'] = 'Forever';
                 if (!empty($productInfo['period_name']) && $productInfo['period_name'] != 'unlimited') {
                     $period = $productInfo['period'] . " " . ucwords($productInfo['period_name']);
                     $form_fields['li_' . $i . '_recurrence'] = $period;
                 } else {
                     $form_fields['li_' . $i . '_recurrence'] = " Week";
                 }
             }
         }
         $form_fields['li_' . $i . '_type'] = 'product';
         if ($items['qty'][$key] > 0) {
             $form_fields['li_' . $i . '_quantity'] = 1;
             $form_fields['li_' . $i . '_price'] = sprintf('%.02f', $items['amount'][$key]);
             if ($taxInfo && !$taxInfo['price_includes_tax']) {
                 $form_fields['li_' . $i . '_price'] += SJB_TaxesManager::getTaxAmount($form_fields['li_' . $i . '_price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
             }
         } else {
             $form_fields['li_' . $i . '_quantity'] = $items['qty'][$key];
             $form_fields['li_' . $i . '_price'] = sprintf('%.02f', $items['price'][$key]);
             if ($taxInfo && !$taxInfo['price_includes_tax']) {
                 $form_fields['li_' . $i . '_price'] += SJB_TaxesManager::getTaxAmount($form_fields['li_' . $i . '_price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
             }
         }
         $form_fields['li_' . $i . '_tangible'] = 'N';
         $i++;
     }
     $user = SJB_UserManager::createTemplateStructureForCurrentUser();
     $form_fields['first_name'] = isset($user['FirstName']) ? $user['FirstName'] : '';
     $form_fields['last_name'] = isset($user['LastName']) ? $user['LastName'] : '';
     $form_fields['street_address'] = isset($user['Location']['Address']) ? $user['Location']['Address'] : '';
     $form_fields['city'] = isset($user['Location']['City']) ? $user['Location']['City'] : '';
     $form_fields['state'] = isset($user['Location']['State']) ? $user['Location']['State'] : '';
     $form_fields['zip'] = isset($user['Location']['ZipCode']) ? $user['Location']['ZipCode'] : '';
     $form_fields['country'] = isset($user['Location']['Country']) ? $user['Location']['Country'] : '';
     $form_fields['email'] = isset($user['email']) ? $user['email'] : '';
     $form_fields['phone'] = isset($user['PhoneNumber']) ? $user['PhoneNumber'] : '';
     $form_fields['x_receipt_link_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
     return $form_fields;
 }
 public function getFormFields()
 {
     if (is_null($this->formFields)) {
         $this->formFields = array();
         $items = $this->invoice->getPropertyValue('items');
         $taxInfo = $this->invoice->getPropertyValue('tax_info');
         if ($this->invoice->isRecurring()) {
             $i = 0;
             $this->formFields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . '/system/payment/notifications/' . self::GATEWAY_ID . '/';
             if (!empty($items['products'])) {
                 foreach ($items['products'] as $key => $product) {
                     $productInfo = $this->invoice->getItemValue($key);
                     if ($taxInfo) {
                         $productInfo['price'] += SJB_TaxesManager::getTaxAmount($productInfo['price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
                     }
                     if (!empty($productInfo['recurring'])) {
                         $this->formFields['recurring'][$i] = $productInfo;
                     } else {
                         $this->formFields['products'][$i] = $productInfo;
                     }
                     $i += 1;
                 }
             }
         }
         $this->formFields['address'] = SJB_Request::getVar('address', false);
         $this->formFields['zip'] = SJB_Request::getVar('zip', false);
         $this->formFields['country'] = SJB_Request::getVar('country', false);
         $this->formFields['city'] = SJB_Request::getVar('city', false);
         $this->formFields['state'] = SJB_Request::getVar('state', false);
         $this->formFields['email'] = SJB_Request::getVar('email', false);
         $this->formFields['phone'] = SJB_Request::getVar('phone', false);
         $this->formFields['amount'] = SJB_Request::getVar('amount', false);
         $this->formFields['item_name'] = SJB_Request::getVar('item_name', false);
         $this->formFields['item_number'] = SJB_Request::getVar('item_number', false);
         $this->formFields['card_number'] = SJB_Request::getVar('card_number', false);
         $this->formFields['exp_date_mm'] = SJB_Request::getVar('exp_date_mm', false);
         $this->formFields['exp_date_yy'] = SJB_Request::getVar('exp_date_yy', false);
         $this->formFields['csc_value'] = SJB_Request::getVar('csc_value', false);
         $this->formFields['first_name'] = SJB_Request::getVar('first_name', false);
         $this->formFields['last_name'] = SJB_Request::getVar('last_name', false);
         $this->formFields['currency_code'] = SJB_Payment_PaypalProFillPaymentCard::getCurrencyCode();
     }
     return $this->formFields;
 }
示例#4
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $currentUser = SJB_UserManager::getCurrentUser();
     $action = SJB_Request::getVar('action', false);
     $error = SJB_Request::getVar('error', false);
     $applyPromoCode = SJB_Request::getVar('applyPromoCode', false);
     $action = $applyPromoCode ? 'applyPromoCode' : $action;
     $numberOfListings = SJB_Request::getVar('number_of_listings');
     $productInfo = null;
     $errors = array();
     switch ($action) {
         case 'delete':
             $itemSID = SJB_Request::getVar('item_sid', 0, false, 'int');
             if (SJB_UserManager::isUserLoggedIn()) {
                 if (SJB_Settings::getSettingByName('allow_to_post_before_checkout') == true) {
                     $this->findCheckoutedListingsByProduct($itemSID, $currentUser->getSID());
                 }
                 SJB_ShoppingCart::deleteItemFromCartBySID($itemSID, $currentUser->getSID());
             } else {
                 $products = SJB_Session::getValue('products');
                 if (!empty($products[$itemSID])) {
                     unset($products[$itemSID]);
                     SJB_Session::setValue('products', $products);
                 }
             }
             break;
         case 'checkout':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $products = SJB_Session::getValue('products');
                 $products = $products ? $products : array();
                 $trialProduct = false;
                 foreach ($products as $product) {
                     if (!empty($product['product_info'])) {
                         $productInfo = unserialize($product['product_info']);
                         if ($currentUser->getUserGroupSID() != $productInfo['user_group_sid']) {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=user_group");
                         } elseif (in_array($productInfo['sid'], $currentUser->getTrialProductSIDByUserSID())) {
                             $trialProduct = true;
                         } else {
                             $product = new SJB_Product($productInfo, $productInfo['product_type']);
                             $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
                             $product->setNumberOfListings($number_of_listings);
                             $productInfo['price'] = $product->getPrice();
                             SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUser->getSID());
                         }
                     }
                 }
                 SJB_Session::unsetValue('products');
                 if ($trialProduct) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=trial_product");
                 } elseif ($products) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/");
                 }
                 $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
                 if (empty($products)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/my-account/");
                 }
                 $isRecurring = false;
                 $subTotal = 0;
                 foreach ($products as $key => $product) {
                     $productInfo = unserialize($product['product_info']);
                     if (!empty($productInfo['recurring'])) {
                         $isRecurring = true;
                     }
                     if (!empty($productInfo['pricing_type']) == 'volume_based' && isset($numberOfListings[$productInfo['sid']][$product['sid']])) {
                         $productInfo['number_of_listings'] = $numberOfListings[$productInfo['sid']][$product['sid']];
                         $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                         $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
                         $productObj->setNumberOfListings($number_of_listings);
                         $productInfo['price'] = $productObj->getPrice();
                         if (!empty($productInfo['code_info'])) {
                             SJB_PromotionsManager::applyPromoCodeToProduct($productInfo, $productInfo['code_info']);
                         }
                         SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                     }
                     $subTotal += $productInfo['price'];
                     $products[$key] = $productInfo;
                     $products[$key]['item_sid'] = $product['sid'];
                     $products[$key]['product_info'] = serialize($productInfo);
                 }
                 $index = 1;
                 $items = array();
                 $codeInfo = array();
                 if ($isRecurring) {
                     $tp->assign('confirmation', 1);
                     $tp->assign('sub_total_price', $subTotal);
                 } else {
                     foreach ($products as $product) {
                         $product_info = unserialize($product['product_info']);
                         SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product, $product['code_info']);
                         $qty = !empty($product_info['number_of_listings']) ? $product_info['number_of_listings'] : null;
                         $items['products'][$index] = $product_info['sid'];
                         if ($qty > 0) {
                             $items['price'][$index] = round($product['price'] / $qty, 2);
                         } else {
                             $items['price'][$index] = round($product['price'], 2);
                         }
                         $items['amount'][$index] = $product['price'];
                         $items['qty'][$index] = $qty;
                         if (isset($product['custom_item'])) {
                             $items['custom_item'][$index] = $product['custom_item'];
                         } else {
                             $items['custom_item'][$index] = "";
                         }
                         if (isset($product['custom_info'])) {
                             $items['custom_info'][$index] = $product['custom_info'];
                         } else {
                             $items['custom_info'][$index]['shoppingCartRecord'] = $product['item_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);
                     }
                     $subUserInfo = $currentUser->getSubuserInfo();
                     $userSID = isset($subUserInfo['sid']) ? $subUserInfo['sid'] : $currentUser->getSID();
                     $invoiceSID = SJB_InvoiceManager::generateInvoice($items, $userSID, $subTotal, SJB_System::getSystemSettings('SITE_URL') . "/create-contract/");
                     SJB_PromotionsManager::addCodeToHistory($codeInfo, $invoiceSID, $userSID);
                     if ($subTotal <= 0) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/create-contract/?invoice_sid=' . $invoiceSID);
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/payment-page/?invoice_sid=" . $invoiceSID);
                     }
                 }
             }
             break;
         case 'applyPromoCode':
             $promotionCode = SJB_Request::getVar('promotion_code', false);
             if ($promotionCode) {
                 if (SJB_UserManager::isUserLoggedIn()) {
                     $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
                 } else {
                     $products = SJB_Session::getValue('products');
                     $products = $products ? $products : array();
                     krsort($products);
                 }
                 $allowShoppingItems = array();
                 $productSIDs = array();
                 foreach ($products as $product) {
                     $productInfo = unserialize($product['product_info']);
                     if (!isset($productInfo['code_info'])) {
                         if (isset($productInfo['custom_info'])) {
                             $allowShoppingItems[] = $product['sid'];
                             $productSIDs[] = $productInfo['custom_info']['productSid'];
                         } else {
                             $allowShoppingItems[] = $product['sid'];
                             $productSIDs[] = $productInfo['sid'];
                         }
                     } else {
                         $appliedPromoCode = $productInfo['code_info'];
                     }
                 }
                 if ($codeInfo = SJB_PromotionsManager::checkCode($promotionCode, $productSIDs)) {
                     $productSIDs = $codeInfo['product_sid'] ? explode(',', $codeInfo['product_sid']) : false;
                     $appliedProducts = array();
                     $codeValid = false;
                     foreach ($products as $key => $product) {
                         $productInfo = unserialize($product['product_info']);
                         if ($productInfo['sid'] != '-1') {
                             $productSid = $productInfo['sid'];
                         } else {
                             $productSid = $productInfo['custom_info']['productSid'];
                         }
                         if ($productSIDs && in_array($productSid, $productSIDs) && $allowShoppingItems && in_array($product['sid'], $allowShoppingItems)) {
                             $currentUsesCount = SJB_PromotionsManager::getUsesCodeBySID($codeInfo['sid']);
                             if ($codeInfo['maximum_uses'] != 0 && $codeInfo['maximum_uses'] > $currentUsesCount || $codeInfo['maximum_uses'] == 0) {
                                 $codeValid = true;
                                 SJB_PromotionsManager::applyPromoCodeToProduct($productInfo, $codeInfo);
                                 $appliedProducts[] = $productInfo;
                                 if (SJB_UserManager::isUserLoggedIn()) {
                                     SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                                 } else {
                                     $products[$key]['product_info'] = serialize($productInfo);
                                     SJB_Session::setValue('products', $products);
                                 }
                             }
                         }
                     }
                     if (!$codeValid) {
                         $errors['NOT_VALID'] = 'Invalid promotion code';
                         unset($promotionCode);
                     }
                     $tp->assign('applied_products', $appliedProducts);
                     $tp->assign('code_info', $codeInfo);
                 } else {
                     $errors['NOT_VALID'] = 'Invalid promotion code';
                 }
                 if (isset($promotionCode) && isset($appliedPromoCode)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/');
                 }
             } else {
                 $errors['EMPTY_VALUE'] = 'Promotion code';
             }
             break;
         case 'deletePromoCode':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
             } else {
                 $products = SJB_Session::getValue('products');
                 $products = $products ? $products : array();
                 krsort($products);
             }
             foreach ($products as $key => $product) {
                 $productInfo = unserialize($product['product_info']);
                 SJB_PromotionsManager::removePromoCodeFromProduct($productInfo);
                 if (SJB_UserManager::isUserLoggedIn()) {
                     $numberOfListings = is_array($numberOfListings) ? array_pop($numberOfListings) : false;
                     if (is_array($numberOfListings)) {
                         foreach ($numberOfListings as $listingSid => $listingsCount) {
                             if ($listingSid == $product['sid']) {
                                 $productInfo['number_of_listings'] = $listingsCount;
                             }
                         }
                     }
                     SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                 } else {
                     $products[$key]['product_info'] = serialize($productInfo);
                     SJB_Session::setValue('products', $products);
                 }
             }
             break;
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
         // To display products in shopping cart after user has been registered from shopping cart page
         if (empty($products)) {
             $products = SJB_Session::getValue('products');
             $products = $products ? $products : array();
         }
     } else {
         $products = SJB_Session::getValue('products');
         $products = $products ? $products : array();
         krsort($products);
     }
     $allowShoppingItems = array();
     foreach ($products as $product) {
         $productInfo = unserialize($product['product_info']);
         if (!empty($productInfo['code_info'])) {
             $promotionCode = $productInfo['code_info']['code'];
             $promotionCodeInfo = $productInfo['code_info'];
         } else {
             $allowShoppingItems[] = $product['sid'];
         }
     }
     $promotionCode = isset($promotionCode) ? $promotionCode : '';
     $totalPrice = 0;
     $discountTotalAmount = 0;
     $numberOfListings = SJB_Request::getVar('number_of_listings', false);
     foreach ($products as $key => $product) {
         $productInfo = unserialize($product['product_info']);
         if ($allowShoppingItems && in_array($product['sid'], $allowShoppingItems)) {
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             if (SJB_UserManager::isUserLoggedIn()) {
                 SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
             } else {
                 $products[$key]['product_info'] = serialize($productInfo);
             }
         }
         if ($numberOfListings && array_key_exists('number_of_listings', $productInfo) && array_key_exists($productInfo['sid'], $numberOfListings)) {
             $productInfo['number_of_listings'] = $numberOfListings[$productInfo['sid']][$product['sid']];
         }
         $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
         $productExtraInfo = unserialize($productInfo['serialized_extra_info']);
         if (!empty($productInfo['expiration_period']) && !is_numeric($productInfo['expiration_period'])) {
             $productInfo['primaryPrice'] = $productExtraInfo['price'];
             $productInfo['period'] = ucwords($productInfo['expiration_period']);
         } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
             $volumeBasedPricing = $productInfo['volume_based_pricing'];
             $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
             $productObj->setNumberOfListings($number_of_listings);
             $productInfo['price'] = $productObj->getPrice();
             $productInfo['primaryPrice'] = $productObj->getPrice();
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             $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] * $i;
                         $countListings[$i]['primaryPrice'] = $volumeBasedPricing['price_per_unit'][$j] * $i;
                         if (!empty($productInfo['code_info']['type'])) {
                             switch ($productInfo['code_info']['type']) {
                                 case 'percentage':
                                     $countListings[$i]['price'] = round($countListings[$i]['price'] - $countListings[$i]['primaryPrice'] / 100 * $productInfo['code_info']['discount'], 2);
                                     $countListings[$i]['percentPromoAmount'] = round($countListings[$i]['primaryPrice'] - $countListings[$i]['price'], 2);
                                     $countListings[$i]['percentPromoCode'] = $productInfo['code_info']['code'];
                                     break;
                                 case 'fixed':
                                     $countListings[$i]['price'] = round($countListings[$i]['price'] - $productInfo['code_info']['discount'], 2);
                                     break;
                             }
                         }
                     }
                 }
             }
             $productInfo['count_listings'] = $countListings;
         } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
             $productInfo['primaryPrice'] = $productObj->getPrice();
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             unset($productInfo['volume_based_pricing']);
         }
         if (isset($productInfo['code_info'])) {
             if ($productInfo['code_info']['type'] != 'fixed' && isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 $discountTotalAmount += (double) $productInfo['count_listings'][$productInfo['number_of_listings']]['percentPromoAmount'];
             } else {
                 $discountTotalAmount += (double) $productInfo['code_info']['promoAmount'];
             }
         }
         if (empty($productInfo['volume_based_pricing'])) {
             $productInfo['primaryPrice'] = $productExtraInfo['price'];
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             $totalPrice += (double) $productInfo['price'];
         }
         $products[$key] = $productInfo;
         $products[$key]['item_sid'] = $product['sid'];
     }
     if ($currentUser) {
         $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($currentUser->getSID(), $totalPrice);
         $tp->assign('tax', $taxInfo);
     }
     $userGroupID = $productInfo ? SJB_UserGroupDBManager::getUserGroupIDBySID($productInfo['user_group_sid']) : false;
     $tp->assign('promotionCodeAlreadyUsed', $promotionCode && empty($errors));
     if (isset($promotionCodeInfo)) {
         $tp->assign('promotionCodeInfo', $promotionCodeInfo);
     }
     $tp->assign('error', $error);
     $tp->assign('errors', $errors);
     $tp->assign('total_price', $totalPrice);
     $tp->assign('discountTotalAmount', $discountTotalAmount);
     $tp->assign('products', $products);
     $tp->assign('userGroupID', $userGroupID);
     $tp->assign('account_activated', SJB_Request::getVar('account_activated', ''));
     $tp->display('shopping_cart.tpl');
 }
示例#5
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $userSID = SJB_Request::getVar('user_sid', false);
     $includeTax = SJB_Request::getVar('include_tax', SJB_Settings::getSettingByName('enable_taxes'));
     $errors = array();
     $invoiceErrors = array();
     $template = 'add_invoice.tpl';
     $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
     if ($userInfo) {
         if (!empty($userInfo['parent_sid'])) {
             $parent_sid = $userInfo['parent_sid'];
             $username = $userInfo['username'] . '/' . $userInfo['email'];
         } else {
             $parent_sid = $userSID;
             $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'] . ' ' . $userInfo['ContactName'] . ' ' . $userInfo['CompanyName'] . '/' . $userInfo['email'];
         }
         $formSubmitted = SJB_Request::getVar('action', '') == 'save';
         $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;
             } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                 unset($productInfo['volume_based_pricing']);
             }
             $products[$key] = $productInfo;
         }
         $total = SJB_I18N::getInstance()->getInput('float', SJB_Request::getVar('total', 0));
         $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($parent_sid, $total);
         $invoice = new SJB_Invoice($_REQUEST);
         $addForm = new SJB_Form($invoice);
         $addForm->registerTags($tp);
         if ($formSubmitted) {
             $invoiceErrors = $invoice->isValid();
             if (empty($invoiceErrors) && $addForm->isDataValid($errors)) {
                 $invoice->setFloatNumbersIntoValidFormat();
                 $invoice->setPropertyValue('success_page_url', SJB_System::getSystemSettings('USER_SITE_URL') . '/create-contract/');
                 SJB_InvoiceManager::saveInvoice($invoice);
                 if (SJB_Request::getVar('send_invoice', false)) {
                     SJB_Notifications::sendInvoiceToCustomer($invoice->getSID(), $userSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/manage-invoices/');
             } else {
                 $invoiceDate = SJB_I18N::getInstance()->getInput('date', $invoice->getPropertyValue('date'));
                 $invoice->setPropertyValue('date', $invoiceDate);
             }
         } else {
             $invoice->setPropertyValue('date', date('Y-m-d'));
             $invoice->setPropertyValue('status', SJB_Invoice::INVOICE_STATUS_UNPAID);
         }
         $invoice->setFloatNumbersIntoValidFormat();
         $tp->assign('username', $username);
         $tp->assign('user_sid', $userSID);
         $tp->assign('products', $products);
         $tp->assign('tax', $taxInfo);
         $tp->assign('include_tax', $includeTax);
     } else {
         $errors[] = 'CUSTOMER_NOT_SELECTED';
         $tp->assign('action', 'add');
         $template = 'errors.tpl';
     }
     $tp->assign("errors", array_merge($errors, $invoiceErrors));
     $tp->display($template);
 }
示例#6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $displayForm = new SJB_Form();
     $displayForm->registerTags($tp);
     $invoiceSid = SJB_Request::getVar('sid', false);
     if (SJB_Request::getVar('error', false)) {
         SJB_FlashMessages::getInstance()->addWarning('TCPDF_ERROR');
     }
     $action = SJB_Request::getVar('action', false);
     $paymentGateway = SJB_Request::getVar('payment_gateway', false);
     $template = 'print_invoice.tpl';
     $currentUserSID = SJB_UserManager::getCurrentUserSID();
     $invoiceInfo = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSid);
     if ($invoiceInfo) {
         if ($currentUserSID == $invoiceInfo['user_sid']) {
             $taxInfo = SJB_TaxesManager::getTaxInfoBySID($invoiceInfo['tax_info']['sid']);
             $invoiceInfo = array_merge($invoiceInfo, $_REQUEST);
             if (is_array($taxInfo)) {
                 $taxInfo = array_merge($invoiceInfo['tax_info'], $taxInfo);
             } else {
                 $taxInfo = $invoiceInfo['tax_info'];
             }
             $invoice = new SJB_Invoice($invoiceInfo);
             $invoice->setSID($invoiceSid);
             $userInfo = SJB_UserManager::getUserInfoBySID($currentUserSID);
             $username = $userInfo['CompanyName'] . ' ' . $userInfo['FirstName'] . ' ' . $userInfo['LastName'];
             $user = SJB_UserManager::getObjectBySID($currentUserSID);
             $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userInfo['user_group_sid']);
             $products = array();
             foreach ($productsSIDs as $key => $productSID) {
                 $product = SJB_ProductsManager::getProductInfoBySID($productSID);
                 $products[$key] = $product;
             }
             $displayForm = new SJB_Form($invoice);
             $displayForm->registerTags($tp);
             $show = true;
             if ($action == 'download_pdf_version' || $action == 'print') {
                 $show = false;
             }
             $tp->assign('show', $show);
             $tp->assign('products', $products);
             $tp->assign('invoice_sid', $invoiceSid);
             $tp->assign('invoice_status', $invoiceInfo['status']);
             $tp->assign('username', trim($username));
             $tp->assign('user_sid', $currentUserSID);
             $tp->assign('tax', $taxInfo);
             $userStructure = SJB_UserManager::createTemplateStructureForUser($user);
             $tp->assign('user', $userStructure);
             $tp->assign('include_tax', $invoiceInfo['include_tax']);
             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") . '/print-invoice/?sid=' . $invoiceSid . '&action=print&error=TCPDF_ERROR');
                 }
             }
         } else {
             SJB_FlashMessages::getInstance()->addError('NOT_OWNER');
         }
     } else {
         SJB_FlashMessages::getInstance()->addError('WRONG_INVOICE_ID_SPECIFIED');
     }
     if ($paymentGateway) {
         $gatewaySID = SJB_PaymentGatewayManager::getSIDByID($paymentGateway);
         $gatewayInfo = SJB_PaymentGatewayManager::getInfoBySID($gatewaySID);
         $tp->assign('gatewayInfo', $gatewayInfo);
     }
     $tp->assign('paymentError', SJB_Request::getVar('payment_error', false));
     $tp->display($template);
 }
示例#7
0
 public function setNewPropertiesToInvoice($productsInfo)
 {
     $subTotal = 0;
     $items = array();
     foreach ($productsInfo as $key => $productInfo) {
         $items['products'][$key] = $productInfo['sid'];
         $items['qty'][$key] = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : null;
         $items['price'][$key] = $productInfo['price'];
         $items['amount'][$key] = $productInfo['amount'];
         $items['custom_item'][$key] = "";
         if ($productInfo['product_type'] == 'banners' && !empty($productInfo['banner_info'])) {
             $items['custom_info'][$key]['banner_info'] = $productInfo['banner_info'];
         }
         $subTotal += $productInfo['amount'];
     }
     $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($this->getUserSID(), $subTotal);
     $totalPrice = SJB_InvoiceManager::getTotalPrice($subTotal, $taxInfo['tax_amount'], $taxInfo['price_includes_tax']);
     $this->setPropertyValue('total', $totalPrice);
     $this->setPropertyValue('sub_total', $subTotal);
     $this->setPropertyValue('tax_info', $taxInfo);
     $this->setPropertyValue('items', $items);
 }
示例#8
0
 public static function getTaxInfoByUserSidAndPrice($user_sid, $price)
 {
     $user = SJB_UserManager::getObjectBySID($user_sid);
     $location = $user->getPropertyValue('Location');
     $tax_info = SJB_TaxesManager::getTaxInfoByCountryAndState(SJB_Array::get($location, 'Country'), SJB_Array::get($location, 'State'));
     $empty_tax_info = array('sid' => '', 'tax_name' => '', 'price_includes_tax' => 0, 'tax_rate' => 0);
     $tax_info = array_merge($empty_tax_info, $tax_info);
     $tax_info['tax_amount'] = SJB_TaxesManager::getTaxAmount($price, $tax_info['tax_rate'], $tax_info['price_includes_tax']);
     return $tax_info;
 }
示例#9
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;
 }
示例#10
0
 public static function generateInvoice($items, $userSID, $subTotalPrice, $successPageUrl, $isRecurring = false)
 {
     $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($userSID, $subTotalPrice);
     $totalPrice = SJB_InvoiceManager::getTotalPrice($subTotalPrice, $taxInfo['tax_amount'], $taxInfo['price_includes_tax']);
     $invoiceSID = null;
     if ($totalPrice > 0) {
         $invoiceSID = SJB_InvoiceManager::getExistingInvoiceSID($userSID, $items, $taxInfo, SJB_Invoice::INVOICE_STATUS_UNPAID, $isRecurring);
     }
     if (!$invoiceSID) {
         $invoiceInfo = array('user_sid' => $userSID, 'include_tax' => !empty($taxInfo['sid']) ? 1 : 0, 'total' => $totalPrice, 'sub_total' => $subTotalPrice, 'success_page_url' => $successPageUrl, 'status' => $totalPrice == 0 ? SJB_Invoice::INVOICE_STATUS_VERIFIED : SJB_Invoice::INVOICE_STATUS_UNPAID, 'tax_info' => $taxInfo, 'items' => $items, 'is_recurring' => $isRecurring);
         $invoice = new SJB_Invoice($invoiceInfo);
         SJB_InvoiceManager::saveInvoice($invoice);
         $invoiceSID = $invoice->getSID();
     }
     return $invoiceSID;
 }
示例#11
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $template = 'manage_taxes.tpl';
     $formSubmitted = SJB_Request::getVar('event', false);
     $field_errors = array();
     switch ($action) {
         case 'add':
             $taxInfo = $_REQUEST;
             $template = 'add_tax.tpl';
             $country = SJB_Request::getVar('Country', false);
             $state = SJB_Request::getVar('State', false);
             if (!isset($taxInfo['active'])) {
                 $taxInfo['active'] = 1;
             }
             $tax = new SJB_Taxes($taxInfo);
             $addTaxForm = new SJB_Form($tax);
             $addTaxForm->registerTags($tp);
             if ($formSubmitted) {
                 $addTaxForm->isDataValid($field_errors);
                 if (SJB_TaxesManager::isTaxExistByCountryAndState($country, $state)) {
                     $field_errors[] = 'NOT_UNIQUE_COUNTRY_AND_STATE';
                 }
                 if (!$field_errors) {
                     SJB_TaxesManager::saveTax($tax);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-taxes/");
                 }
             }
             $formFields = $addTaxForm->getFormFieldsInfo();
             $tp->assign("state_sid", intval($state));
             $tp->assign("form_fields", $formFields);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             break;
         case 'edit':
             $template = 'edit_tax.tpl';
             $taxSID = SJB_Request::getVar('sid', false);
             $taxInfo = SJB_TaxesManager::getTaxInfoBySID($taxSID);
             if ($taxInfo) {
                 $taxInfo = array_merge($taxInfo, $_REQUEST);
                 $country = $taxInfo['Country'];
                 $state = $taxInfo['State'];
                 $tax = new SJB_Taxes($taxInfo);
                 $editTaxForm = new SJB_Form($tax);
                 $editTaxForm->registerTags($tp);
                 $tax->setSID($taxSID);
                 if ($formSubmitted) {
                     $editTaxForm->isDataValid($field_errors);
                     if (SJB_TaxesManager::isTaxExistByCountryAndState($country, $state, $taxSID)) {
                         $field_errors[] = 'NOT_UNIQUE_COUNTRY_AND_STATE';
                     }
                     if (!$field_errors) {
                         SJB_TaxesManager::saveTax($tax);
                         if ($formSubmitted == 'save') {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-taxes/");
                         } else {
                             $tax->setFloatNumbersIntoValidFormat();
                         }
                     }
                 }
                 $formFields = $editTaxForm->getFormFieldsInfo();
                 $tp->assign("form_fields", $formFields);
                 $tp->assign("sid", $taxSID);
                 $tp->assign("state_sid", intval($state));
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             } else {
                 $tp->assign('action', 'edit');
                 $field_errors[] = 'WRONG_TAX_ID_SPECIFIED';
                 $template = 'errors.tpl';
             }
             break;
         case 'delete':
             $taxSID = SJB_Request::getVar('sid', 0);
             SJB_TaxesManager::deleteTaxBySID($taxSID);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-taxes/");
             break;
         case 'deactivate':
             $taxSID = SJB_Request::getVar('sid', 0);
             SJB_TaxesManager::deactivateTaxBySID($taxSID);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-taxes/");
             break;
         case 'setting':
             $enableTaxes = SJB_Request::getVar('enable_taxes', 0);
             SJB_Settings::updateSetting('enable_taxes', $enableTaxes);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-taxes/");
             break;
         case 'activate':
             $taxSID = SJB_Request::getVar('sid', 0);
             SJB_TaxesManager::activateTaxBySID($taxSID);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-taxes/");
             break;
         default:
             $taxes_structure = array();
             $taxes = SJB_TaxesManager::getAllTaxesInfo();
             foreach ($taxes as $tax_info) {
                 $taxes_structure[$tax_info['sid']] = SJB_TaxesManager::createTemplateStructureForTax($tax_info);
             }
             $tp->assign('taxes', $taxes_structure);
             break;
     }
     $tp->assign('errors', $field_errors);
     $tp->display($template);
 }