public function execute() { $request_uri = $_SERVER['REQUEST_URI']; $template_processor = SJB_System::getTemplateProcessor(); $callback_page_uri = ''; preg_match('#.*/system/payment/callback/([^/?]+)#', $request_uri, $mm); if (!empty($mm)) { $gateway_id = $mm[1]; $redirectPage = $callback_page_uri . $gateway_id . "/"; preg_match("(.*{$redirectPage}([^/]*)/?)", $request_uri, $invoice_sid); $invoice_sid = !empty($invoice_sid[1]) ? $invoice_sid[1] : ''; $redirectPage = $callback_page_uri . $gateway_id . "/" . $invoice_sid; preg_match("(.*{$redirectPage}([^/]*)/?)", $request_uri, $tt); $redirectPage = !empty($tt[1]) ? $tt[1] : ''; $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid); if (!empty($invoice) && $invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/payment-completed/"); } $gateway = SJB_PaymentGatewayManager::getObjectByID($gateway_id); $gateway_caption = $gateway->getPropertyValue('caption'); $invoice = $gateway->getPaymentFromCallbackData($_REQUEST); SJB_PaymentLogManager::recordPaymentLog($gateway->getPaymentStatusFromCallbackData($_REQUEST), $gateway_caption, $_REQUEST); if (is_null($invoice)) { $errors = $gateway->getErrors(); $template_processor->assign('errors', $errors); $template_processor->display('callback_payment_page.tpl'); } else { $status = $invoice->getStatus(); if ($status == SJB_Invoice::INVOICE_STATUS_VERIFIED) { SJB_Statistics::addStatisticsFromInvoice($invoice); $success_url = $invoice->getSuccessPageURL(); $page = empty($redirectPage) ? '' : '&' . $redirectPage; SJB_HelperFunctions::redirect($success_url . '?invoice_sid=' . $invoice->getSID() . $page); } elseif ($status == SJB_Invoice::INVOICE_STATUS_PENDING) { $template_processor->assign('message', 'INVOICE_WAITING'); $template_processor->display('callback_payment_page.tpl'); } else { SJB_InvoiceManager::markUnPaidInvoiceBySID($invoice_sid); $payment_error = 1; if ($gateway_id == 'paypal_pro') { $httpPostResponse = SJB_Request::getVar('http_post_response', false); if (!empty($httpPostResponse['L_SHORTMESSAGE0']) && urldecode($httpPostResponse['L_SHORTMESSAGE0']) == 'Authentication/Authorization Failed') { $payment_error = 2; } } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/view-invoice/?sid=" . $invoice_sid . "&payment_error=" . $payment_error . "&payment_gateway=" . $gateway_id); } } } else { $errors['INVOICE_ID_IS_NOT_SET'] = 1; $template_processor->assign('errors', $errors); $template_processor->display('callback_payment_page.tpl'); } }
public function execute() { if (SJB_Request::isAjax()) { die(json_encode($this->getPayPalStateList())); } $getInvoiceId = SJB_Request::getInt('payment_id', 0, 'GET'); $this->invoice = SJB_InvoiceManager::getObjectBySID($getInvoiceId); if ($this->invoiceValidation($this->invoice)) { if ($this->isPayNowButtonPressed()) { $this->processPayNowButtonClick(); } else { $this->displayForm(); } } }
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); }
/** * 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); } }
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'); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $template = SJB_Request::getVar('template', 'manage_invoices.tpl'); $searchTemplate = SJB_Request::getVar('search_template', 'invoice_search_form.tpl'); $action = SJB_Request::getVar('action_name'); if (!empty($action)) { $invoicesSIDs = SJB_Request::getVar('invoices', array()); $_REQUEST['restore'] = 1; switch ($action) { case 'paid': foreach (array_keys($invoicesSIDs) as $invoiceSID) { $invoice = SJB_InvoiceManager::getObjectBySID($invoiceSID); $userSID = $invoice->getPropertyValue('user_sid'); if (SJB_UserManager::isUserExistsByUserSid($userSID)) { $items = $invoice->getPropertyValue('items'); $productSIDs = $items['products']; foreach ($productSIDs as $key => $productSID) { if ($productSID != -1) { if (SJB_ProductsManager::isProductExists($productSID)) { $productInfo = $invoice->getItemValue($key); $listingNumber = $productInfo['qty']; $contract = new SJB_Contract(array('product_sid' => $productSID, 'numberOfListings' => $listingNumber, 'is_recurring' => $invoice->isRecurring())); $contract->setUserSID($userSID); $contract->setPrice($items['amount'][$key]); if ($contract->saveInDB()) { SJB_ListingManager::activateListingsAfterPaid($userSID, $productSID, $contract->getID(), $listingNumber); SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $userSID); $bannerInfo = $productInfo['banner_info']; if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) { $bannersObj = new SJB_Banners(); $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $userSID, $contract->getID()); $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']); SJB_AdminNotifications::sendAdminBannerAddedLetter($userSID, $bannerGroup); } if ($contract->isFeaturedProfile()) { SJB_UserManager::makeFeaturedBySID($userSID); } if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($userSID)) { SJB_Notifications::sendSubscriptionActivationLetter($userSID, $productInfo); } } } } else { $type = SJB_Array::getPath($items, 'custom_info/' . $key . '/type'); switch ($type) { case 'featuredListing': $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id'); SJB_ListingManager::makeFeaturedBySID($listingId); break; case 'priorityListing': $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id'); SJB_ListingManager::makePriorityBySID($listingId); break; case 'activateListing': $listingsIds = explode(",", SJB_Array::getPath($items, 'custom_info/' . $key . '/listings_ids')); foreach ($listingsIds as $listingId) { SJB_ListingManager::activateListingBySID($listingId); } break; } } } SJB_Statistics::addStatisticsFromInvoice($invoice); } $total = $invoice->getPropertyValue('total'); if ($total > 0) { $gatewayID = $invoice->getPropertyValue('payment_method'); $gatewayID = isset($gatewayID) ? $gatewayID : 'cash_payment'; $transactionId = md5($invoiceSID . $gatewayID); $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoiceSID, 'amount' => $total, 'payment_method' => $gatewayID, 'user_sid' => $invoice->getPropertyValue('user_sid')); $transaction = new SJB_Transaction($transactionInfo); SJB_TransactionManager::saveTransaction($transaction); } SJB_InvoiceManager::markPaidInvoiceBySID($invoiceSID); SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoiceSID); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-invoices/"); break; case 'unpaid': foreach (array_keys($invoicesSIDs) as $invoiceSID) { SJB_InvoiceManager::markUnPaidInvoiceBySID($invoiceSID); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/'); break; case 'delete': foreach (array_keys($invoicesSIDs) as $invoiceSID) { SJB_InvoiceManager::deleteInvoiceBySID($invoiceSID); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/'); break; default: unset($_REQUEST['restore']); break; } } /***************************************************************/ $_REQUEST['action'] = 'search'; $invoice = new SJB_Invoice(array()); $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true)); $aliases = new SJB_PropertyAliases(); $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserDBManager::getUserSIDsLikeSearchString')); $searchFormBuilder = new SJB_SearchFormBuilder($invoice); $criteriaSaver = new SJB_InvoiceCriteriaSaver(); if (isset($_REQUEST['restore'])) { $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria()); } $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice); $searchFormBuilder->setCriteria($criteria); $searchFormBuilder->registerTags($tp); $tp->display($searchTemplate); /********************** S O R T I N G *********************/ $paginator = new SJB_InvoicePagination(); $innerJoin = false; if ($paginator->sortingField == 'username') { $innerJoin = array('users' => array('sort_field' => array(36 => array('FirstName', 'LastName'), 41 => 'CompanyName'), 'join_field' => 'sid', 'join_field2' => 'user_sid', 'main_table' => 'invoices', 'join' => 'LEFT JOIN')); } $searcher = new SJB_InvoiceSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder, $innerJoin); $foundInvoices = array(); $foundInvoicesInfo = array(); if (SJB_Request::getVar('action', '') == 'search') { $foundInvoices = $searcher->getObjectsByCriteria($criteria, $aliases); if (empty($foundInvoices) && $paginator->currentPage != 1) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/?page=1'); } $criteriaSaver->setSession($_REQUEST, $searcher->getFoundObjectSIDs()); } elseif (isset($_REQUEST['restore'])) { $foundInvoices = $criteriaSaver->getObjectsFromSession(); } foreach ($foundInvoices as $id => $invoice) { $subUserSID = $invoice->getPropertyValue('subuser_sid'); if ($subUserSID) { $subUserInfo = SJB_UserManager::getUserInfoBySID($subUserSID); $parentInfo = SJB_UserManager::getUserInfoBySID($subUserInfo['parent_sid']); $username = $parentInfo['CompanyName']; } else { $userSID = $invoice->getPropertyValue('user_sid'); $userInfo = SJB_UserManager::getUserInfoBySID($userSID); if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'Employer') { $username = $userInfo['CompanyName']; } else { if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'JobSeeker') { $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName']; } else { $username = $userInfo['username']; } } } $invoice->addProperty(array('id' => 'sid', 'type' => 'string', 'value' => $invoice->getSID())); $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => $username)); $foundInvoices[$id] = $invoice; $foundInvoicesInfo[$invoice->getSID()] = SJB_InvoiceManager::getInvoiceInfoBySID($invoice->getSID()); $foundInvoicesInfo[$invoice->getSID()]['userExists'] = !empty($username) ? 1 : 0; } /****************************************************************/ $paginator->setItemsCount($searcher->getAffectedRows()); $form_collection = new SJB_FormCollection($foundInvoices); $form_collection->registerTags($tp); $tp->assign('paginationInfo', $paginator->getPaginationInfo()); $tp->assign("found_invoices", $foundInvoicesInfo); $tp->display($template); }
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; } }
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; }
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; }
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'); } }