Beispiel #1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $gatewayId = SJB_Request::getVar('gatewayId', 'cash_gateway');
     $gateway = SJB_PaymentGatewayManager::getObjectByID($gatewayId);
     if (isset($gateway) && in_array($gatewayId, array('cash_gateway', 'wire_transfer'))) {
         $invoiceSid = SJB_Request::getVar('invoice_sid');
         $invoice = SJB_InvoiceManager::getObjectBySID($invoiceSid);
         if (isset($invoice)) {
             $currentUser = SJB_UserManager::getCurrentUserInfo();
             if ($currentUser['sid'] == $invoice->getPropertyValue('user_sid')) {
                 if ($invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_UNPAID) {
                     $tp->assign('invoice_sid', $invoiceSid);
                     $tp->assign('item_name', $invoice->getProductNames());
                     $tp->assign('amount', $invoice->getPropertyValue('total'));
                     $tp->assign('user', $currentUser);
                     SJB_InvoiceManager::saveInvoice($invoice);
                     SJB_ShoppingCart::deleteItemsFromCartByUserSID($currentUser['sid']);
                 } else {
                     $errors['INVOICE_IS_NOT_UNPAID'] = true;
                 }
             } else {
                 $errors['NOT_OWNER'] = true;
             }
         } else {
             $errors['INVALID_INVOICE_ID'] = true;
         }
         $template = $gateway->getTemplate();
         $tp->assign('errors', $errors);
     } else {
         $errors['INVALID_GATEWAY'] = true;
         $tp->assign('ERRORS', $errors);
         $template = 'errors.tpl';
     }
     $tp->display($template);
 }
Beispiel #2
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);
 }
Beispiel #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);
     }
 }
Beispiel #4
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');
 }
Beispiel #5
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;
     }
 }
Beispiel #6
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;
 }
Beispiel #7
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);
 }
Beispiel #8
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;
 }
Beispiel #9
0
 function getPaymentFromCallbackData($callback_data)
 {
     $invoice_sid = isset($callback_data['item_number']) ? $callback_data['item_number'] : null;
     if (is_null($invoice_sid)) {
         $this->errors['INVOICE_ID_IS_NOT_SET'] = 1;
         return null;
     }
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     if (is_null($invoice)) {
         $this->errors['NONEXISTED_INVOICE_ID_SPECIFIED'] = 1;
         return null;
     }
     if ($invoice->getStatus() != SJB_Invoice::INVOICE_STATUS_UNPAID) {
         $this->errors['INVOICE_IS_NOT_UNPAID'] = $invoice->getStatus();
         return null;
     }
     $invoice->setCallbackData($callback_data);
     if ($this->isPaymentVerified($invoice)) {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_VERIFIED);
     } else {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
     }
     if (!$this->checkPaymentAmount($invoice)) {
         return null;
     }
     $id = $this->details->getProperty('id');
     $invoice->setPropertyValue('payment_method', $id->getValue());
     SJB_InvoiceManager::saveInvoice($invoice);
     if (isset($callback_data['x_trans_id'])) {
         $transactionId = $callback_data['x_trans_id'];
         $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoice->getSID(), 'amount' => $invoice->getPropertyValue('total'), 'payment_method' => $invoice->getPropertyValue('payment_method'), 'user_sid' => $invoice->getPropertyValue('user_sid'));
         $transaction = new SJB_Transaction($transactionInfo);
         SJB_TransactionManager::saveTransaction($transaction);
     }
     return $invoice;
 }
Beispiel #10
0
 private function redirectToMyProductsPage($callbackData)
 {
     $invoice_sid = isset($callbackData['item_number']) ? $callbackData['item_number'] : null;
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     $paymentStatus = $invoice->getStatus();
     $invoice->setCallbackData($callbackData);
     $items = $invoice->getPropertyValue('items');
     $countOfProducts = 0;
     $gatewayId = $this->details->getProperty('id');
     $invoice->setPropertyValue('payment_method', $gatewayId->getValue());
     $userSid = $invoice->getUserSID();
     if ($paymentStatus == SJB_Invoice::INVOICE_STATUS_PENDING) {
         foreach ($items['products'] as $key => $product) {
             if ("SUCCESS" == strtoupper($callbackData['http_post_response'][$countOfProducts]["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($callbackData['http_post_response'][$countOfProducts]["ACK"])) {
                 $product_info = $invoice->getItemValue($key);
                 $countOfProducts += 1;
                 SJB_ShoppingCart::deleteItemFromCartBySID($product_info['shoppingCartRecord'], $userSid);
             } else {
                 $productInfo = SJB_ProductsManager::getProductInfoBySID($product);
                 $this->failedProducts = $this->failedProducts . $productInfo['name'] . ',';
                 $countOfProducts += 1;
             }
         }
         SJB_InvoiceManager::saveInvoice($invoice);
         $this->failedProducts = substr($this->failedProducts, 0, -1);
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=true&failedProducts=' . $this->failedProducts);
     } else {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
         SJB_InvoiceManager::saveInvoice($invoice);
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=false');
     }
 }