public function execute() { $templateProcessor = SJB_System::getTemplateProcessor(); $errors = array(); $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; $gateway_id = isset($_REQUEST['gateway']) ? $_REQUEST['gateway'] : null; $formSubmitted = SJB_Request::getVar('submit'); $gateway_sid = SJB_PaymentGatewayManager::getSIDByID($gateway_id); if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($action)) { if ($action == 'deactivate') { SJB_PaymentGatewayManager::deactivateByID($gateway_id); } elseif ($action == 'activate') { SJB_PaymentGatewayManager::activateByID($gateway_id); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $gateway = SJB_PaymentGatewayManager::createObjectByID($gateway_id, $_REQUEST); $gateway->dontSaveProperty('id'); $gateway->dontSaveProperty('caption'); $gateway->setSID($gateway_sid); if ($gateway->isValid()) { if (SJB_PaymentGatewayManager::saveGateway($gateway) !== false) { $templateProcessor->assign('gatewaySaved', true); if ($formSubmitted == 'save_gateway') { $siteUrl = SJB_System::getSystemsettings('SITE_URL') . '/system/payment/gateways/?gatewaySaved=1'; SJB_HelperFunctions::redirect($siteUrl); } } else { $errors['SETTINGS_SAVED_WITH_PROBLEMS'] = 1; } } else { $errors = $gateway->getErrors(); } } $gateway = SJB_PaymentGatewayManager::getObjectByID($gateway_id); $gateway_form = new SJB_Form($gateway); $gateway_form->registerTags($templateProcessor); $gateway_form->makeDisabled('id'); $gateway_form->makeDisabled('caption'); $countryCode = $gateway->getPropertyValue('country'); if (empty($countryCode)) { $countryValue = SJB_CountriesManager::getCountrySIDByCountryCode('US'); $gateway->setPropertyValue('country', $countryValue); } if (empty($gateway)) { $errors['GATEWAY_NOT_FOUND'] = 1; $templateProcessor->assign('errors', $errors); $templateProcessor->display('configure_gateway.tpl'); return; } $gateway_info = SJB_PaymentGatewayManager::getInfoBySID($gateway_sid); $form_fields = $gateway_form->getFormFieldsInfo(); $templateProcessor->assign('gateway', $gateway_info); $templateProcessor->assign('form_fields', $form_fields); $templateProcessor->assign('errors', $errors); $templateProcessor->display('configure_gateway.tpl'); }
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); }
public static function getPaymentGatewaysList() { $gateways_info = array(); $gateways = SJB_DB::query('SELECT `sid` FROM `payment_gateways`'); foreach ($gateways as $gateway) { $gateways_info[$gateway['sid']] = SJB_PaymentGatewayManager::getInfoBySID($gateway['sid']); } return $gateways_info; }