/** * Log Message * * Writes a new log entry * * @param string $type Type of log entry (notice, warning, error, critical, or security) * @param string $module Where (in the code) this message is coming from * @param string $message Log message */ function log_message($type, $module, $message) { // Construct a LogDBO $logdbo = new LogDBO(); $logdbo->setType($type); $logdbo->setModule($module); $logdbo->setText($message); $logdbo->setUsername(!empty($_SESSION['client']['userdbo']) ? $_SESSION['client']['userdbo']->getUsername() : null); $logdbo->setRemoteIP(ip2long($_SERVER['REMOTE_ADDR'])); $logdbo->setDate(DBConnection::format_datetime(time())); // Write the log message add_LogDBO($logdbo); }
/** * Assign Product * * Create a Product Purchase DBO and add it to the database */ function assign_product() { // Create new ProductPurchase DBO $purchase_dbo = new ProductPurchaseDBO(); $purchase_dbo->setAccountID($this->get['account']->getID()); $purchase_dbo->setProductID($this->post['product']->getID()); $purchase_dbo->setTerm(isset($this->post['term']) ? $this->post['term']->getTermLength() : null); $purchase_dbo->setDate(DBConnection::format_datetime($this->post['date'])); $purchase_dbo->setNote($this->post['note']); // Save purchase add_ProductPurchaseDBO($purchase_dbo); // Success $this->setMessage(array("type" => "[PRODUCT_ASSIGNED]")); $this->gotoPage("accounts_view_account", null, "action=products&account=" . $this->get['account']->getID()); }
/** * Assign Service * * Create a HostingServicePurchaseDBO and add it to the database */ function assign_service() { // If this HostingService requires a unique IP, make sure the user selected one if ($this->post['service']->getUniqueIP() == "Required" && !isset($this->post['ipaddress'])) { throw new FieldMissingException("ipaddress"); } // If this HostingService requires a domain, make sure the user selected one if ($this->post['service']->isDomainRequired() && !isset($this->post['domainname'])) { throw new FieldMissingException("domainname"); } // Create new HostingServicePurchase DBO $serverID = isset($this->post['server']) ? $this->post['server']->getID() : null; $purchase_dbo = new HostingServicePurchaseDBO(); $purchase_dbo->setAccountID($this->get['account']->getID()); $purchase_dbo->setPurchasable($this->post['service']); $purchase_dbo->setTerm(isset($this->post['term']) ? $this->post['term']->getTermLength() : null); $purchase_dbo->setServerID($serverID); $purchase_dbo->setDate(DBConnection::format_datetime($this->post['date'])); $purchase_dbo->setDomainName($this->post['domainname']); $purchase_dbo->setNote($this->post['note']); // Save purchase add_HostingServicePurchaseDBO($purchase_dbo); // If an IP address was selected, assign that IP address to this purchase if (isset($this->post['ipaddress'])) { if ($this->post['ipaddress']->getServerID() != $serverID) { // Roll-back delete_HostingServicePurchaseDBO($purchase_dbo); throw new SWUserException("[IP_MISMATCH]"); } // Update IP Address record $this->post['ipaddress']->setPurchaseID($purchase_dbo->getID()); try { update_IPAddressDBO($this->post['ipaddress']); } catch (DBException $e) { // Roll-back delete_HostingServicePurchaseDBO($purchase_dbo); throw new SWUserException("[DB_IP_UPDATE_FAILED]"); } } // Success $this->setMessage(array("type" => "[HOSTING_ASSIGNED]")); $this->gotoPage("accounts_view_account", null, "action=services&account=" . $this->get['account']->getID()); }
/** * Add Payment * * Create a PaymentDBO and add it to the database */ function add_payment() { // If the use entered the Invoice ID directly, use that. Otherwise, use the // Invoice selected from the drop-down menu $invoice = isset($this->post['invoiceint']) ? $this->post['invoiceint'] : $this->post['invoiceselect']; // Create a new payment DBO $payment_dbo = new PaymentDBO(); $payment_dbo->setInvoiceID($invoice->getID()); $payment_dbo->setDate(DBConnection::format_datetime($this->post['date'])); $payment_dbo->setAmount($this->post['amount']); $payment_dbo->setType($this->post['type']); $payment_dbo->setTransaction1($this->post['transaction1']); $payment_dbo->setTransaction2($this->post['transaction2']); $payment_dbo->setStatus($this->post['status']); // Insert Payment into database add_PaymentDBO($payment_dbo); // Success $this->setMessage(array("type" => "[PAYMENT_ENTERED]")); $this->reload(); }
/** * Assign Domain Service * * Create a DomainServicePurchaseDBO and add it to the database */ public function assign_service() { // The domain name is required but not configured as such. This is to allow the // page to update the price dynamically if (!isset($this->post['domainname'])) { throw new FieldMissingException("domainname"); } // Create new DomainServicePurchase DBO $purchase_dbo = new DomainServicePurchaseDBO(); $purchase_dbo->setAccountID($this->get['account']->getID()); $purchase_dbo->setTLD($this->post['tld']->getTLD()); $purchase_dbo->setTerm($this->post['term'] ? $this->post['term']->getTermLength() : null); $purchase_dbo->setDate(DBConnection::format_datetime($this->post['date'])); $purchase_dbo->setDomainName($this->post['domainname']); $purchase_dbo->setNote($this->post['note']); // Save purchase add_DomainServicePurchaseDBO($purchase_dbo); // Success $this->setMessage(array("type" => "[DOMAIN_ASSIGNED]")); $this->gotoPage("accounts_view_account", null, "action=domains&account=" . $this->get['account']->getID()); }
/** * Save Changes */ function save() { // Update Payment DBO $this->get['payment']->setDate(DBConnection::format_datetime($this->post['date'])); $this->get['payment']->setAmount($this->post['amount']); $this->get['payment']->setTransaction1($this->post['transaction1']); $this->get['payment']->setTransaction2($this->post['transaction2']); $this->get['payment']->setStatus($this->post['status']); $this->get['payment']->setStatusMessage($this->post['statusmessage']); update_PaymentDBO($this->get['payment']); // Success! $this->setMessage(array("type" => "[PAYMENT_UPDATED]")); $this->reload(); }
/** * Generate Expiration Date * * Takes the registration date, and adds the registration terms to come up with * the expiration date. The expiration date can then be accessed with * getExpireDate(). */ function generateExpireDate() { // Break up the registration date $start_date = getdate(DBConnection::datetime_to_unix($this->getDate())); // Add term-years to start date $expire_date = mktime($start_date['hours'], $start_date['minutes'], $start_date['seconds'], $start_date['mon'], $start_date['mday'], $start_date['year'] + $this->getTerm() / 12); // Convert back to a datetime $this->setExpireDate(DBConnection::format_datetime($expire_date)); }
/** * Authorize, or Authorize and Capture a Credit Card Transaction * * @param ContactDBO $contactDBO Billing contact * @param string $cardNumber Credit card number (XXXXXXXXXXXXXXXXXXXX) * @param string $expireDate CC expiration date (MMYY) * @param string $cardCode CVV2/CVC2/CID code * @param PaymentDBO $paymentDBO Payment DBO for this transaction * $param boolean $authOnly When true, the transaction will be authorized only * @return boolean False when there is an error processing the transaction */ function charge($contactDBO, $cardNumber, $expireDate, $cardCode, &$paymentDBO, $authOnly) { // Build PaymentDBO $paymentDBO->setDate(DBConnection::format_datetime(time())); $paymentDBO->setType("Module"); $paymentDBO->setModule($this->getName()); /* old busted method // Construct a list of parameters to be passed to Authorize.net $message = $this->buildPOSTFields( array( "x_login" => $this->getLoginID(), "x_version" => $this->getAPIVersion(), "x_delim_char" => $this->getDelimiter(), "x_delim_data" => "TRUE", "x_type" => $authOnly ? "AUTH_ONLY" : "AUTH_CAPTURE", "x_method" => "CC", "x_tran_key" => $this->getTransactionKey(), "x_card_num" => $cardNumber, "x_exp_date" => $expireDate, "x_amount" => $paymentDBO->getAmount(), "x_card_code" => $cardCode, "x_first_name" => substr( $contactDBO->getName(), 0, 50 ), "x_address" => substr( sprintf( "%s %s", $contactDBO->getAddress1(), $contactDBO->getAddress2() ), 0, 60 ), "x_city" => substr( $contactDBO->getCity(), 0, 40 ), "x_state" => substr( $contactDBO->getState(), 0, 40 ), "x_zip" => substr( $contactDBO->getPostalCode(), 0, 20 ), "x_country" => substr( $contactDBO->getCountry(), 0, 60 ), "x_phone" => substr( $contactDBO->getPhone(), 0, 25 ), "x_fax" => substr( $contactDBO->getFax(), 0, 25 ) ) ); // Carry out the transaction $resp = $this->executeTransaction( $message ); */ // New SDK method //$transaction = new AuthorizeNetAIM($this->getLoginID(), $this->getTransactionKey()); /* $transaction->amount = $paymentDBO->getAmount(); $transaction->card_num = $cardNumber; $transaction->exp_date = $expireDate; $customerData = (object) array(); $customerData->first_name = substr( $contactDBO->getName(), 0, 50 ); $customerData->address = substr( sprintf( "%s %s", $contactDBO->getAddress1(), $contactDBO->getAddress2() ), 0, 60 ); $customerData->city = substr( $contactDBO->getCity(), 0, 40 ); $customerData->state = substr( $contactDBO->getState(), 0, 40 ); $customerData->zip = substr( $contactDBO->getPostalCode(), 0, 20 ); $transaction->setFields($customerData); */ $transaction = new AuthorizeNetAIM('95n98SqG5', '4gc88U7xV5g78TYU'); $transaction->amount = '9.99'; $transaction->card_num = '4007000000027'; $transaction->exp_date = '10/16'; $response = $transaction->authorizeAndCapture(); if ($response->approved) { echo "<h1>Success! The test credit card has been charged!</h1>"; echo "Transaction ID: " . $response->transaction_id; } else { echo $response->error_message; } // Parse the transaction response switch ($response) { case AIM_APPROVED: $paymentDBO->setStatus($authOnly ? "Authorized" : "Completed"); $paymentDBO->setTransaction1($resp[AIM_RESP_TRANSACTION_ID]); $paymentDBO->setTransaction2($resp[AIM_RESP_APPROVAL_CODE]); if (!$this->saveTransaction($resp[AIM_RESP_TRANSACTION_ID], substr($cardNumber, -1, 4))) { fatal_error("AuthorizeAIM::authorize", "Failed to save transaction data: "); } break; case AIM_DECLINED: $paymentDBO->setStatus("Declined"); $paymentDBO->setStatusMessage($resp[AIM_RESP_REASON_TEXT]); break; case AIM_ERROR: log_error("AuthorizeAIM::authorize()", "An error occured while processing an Authorize.net transaction: " . $resp[AIM_RESP_REASON_TEXT]); return false; break; } return true; }
/** * Check Out */ function checkout() { // The module must have been picked if this is not an existing customer if ($this->session['order']->getAccountType() == "New Account" && !isset($this->post['module'])) { throw new SWUserException("[YOU_MUST_SELECT_PAYMENT]"); } // If required, make sure that the TOS box was checked if ($this->conf['order']['tos_required'] && !isset($this->post['accept_tos'])) { throw new SWUserException("[YOU_MUST_ACCEPT_THE_TERMS_OF_SERVICE]"); } $this->session['order']->setRemoteIP(ip2long($_SERVER['REMOTE_ADDR'])); $this->session['order']->setDateCreated(DBConnection::format_datetime(time())); $this->session['order']->setAcceptedTOS($this->post['accept_tos'] == "true" ? "Yes" : "No"); /* if ( $this->session['order']->getAccountType() == "Existing Account" ) { // Send existing accounts off to the receipt page $this->session['order']->complete(); $this->gotoPage( "receipt" ); } */ // Register the new user if ($this->session['order']->getAccountType() == "New Account") { $order = $this->session['order']; $user_dbo = new UserDBO(); // User-defined data $user_dbo->setUsername($order->getUsername()); $user_dbo->setPassword($order->getPassword()); $user_dbo->setContactName($order->getContactName()); $user_dbo->setEmail($order->getContactEmail()); // Admin-defined data $user_dbo->setType("Client"); $user_dbo->setLanguage("english"); // could change to user-defined $user_dbo->setTheme("default"); add_UserDBO($user_dbo); // Add account info to accountDBO $account_dbo = new AccountDBO(); $account_dbo->setStatus("Active"); $account_dbo->setType("Individual Account"); $account_dbo->setBillingStatus("Bill"); $account_dbo->setBillingDay(1); $account_dbo->setBusinessName($order->getBusinessName()); $account_dbo->setContactName($order->getContactName()); $account_dbo->setContactEmail($order->getContactEmail()); $account_dbo->setAddress1($order->getAddress1()); $account_dbo->setAddress2($order->getAddress2()); $account_dbo->setCity($order->getCity()); $account_dbo->setState($order->getState()); $account_dbo->setCountry($order->getCountry()); $account_dbo->setPostalCode($order->getPostalCode()); $account_dbo->setPhone($order->getPhone()); $account_dbo->setMobilePhone($order->getMobilePhone()); $account_dbo->setFax($order->getFax()); $account_dbo->setUsername($order->getUsername()); add_AccountDBO($account_dbo); $this->session['order']->setAccountID($account_dbo->getID()); } // If the order does not have an ID already, save it to the database if ($this->session['order']->getID() == null) { add_OrderDBO($this->session['order']); } if ($this->session['review']['module'] == "Check") { // Record the promise to pay by check $checkPayment = new PaymentDBO(); $checkPayment->setOrderID($this->session['order']->getID()); $checkPayment->setAmount($this->session['order']->getTotal()); $checkPayment->setStatus("Pending"); $checkPayment->setDate(DBConnection::format_datetime(time())); $checkPayment->setType("Check"); add_PaymentDBO($checkPayment); // Goto the receipt page $this->session['order']->complete(); $this->gotoPage("receipt", null, "payByCheck=1"); } // Collect Payment $registry = ModuleRegistry::getModuleRegistry(); $paymentModule = $registry->getModule($this->post['module']); $checkoutPage = $paymentModule->getType() == "payment_processor" ? $paymentModule->getOrderCheckoutPage() : "ccpayment"; // Redirect to the module's checkout page $_SESSION['module'] = $paymentModule; $this->gotoPage($checkoutPage); }
/** * Initialize Generate Invoice Page */ function init() { parent::init(); if (!isset($this->post['periodend'])) { // Set the end of the invoice period to be 1 month ahead of today $today = getdate(time()); $newDate = DBConnection::format_datetime(mktime(null, null, null, $today['mon'] + 1)); $this->smarty->assign("nextMonth", $newDate); } }
/** * Complete Order * * Set the status to "Pending" and the data completed to now, then update DB */ public function complete() { // Set status to pending and give a timestamp $this->setStatus("Pending"); $this->setDateCompleted(DBConnection::format_datetime(time())); // Update the database record update_OrderDBO($this); // Notification e-mail $body = $this->replaceTokens($conf['order']['notification_email']); $notifyEmail = new Email(); $notifyEmail->addRecipient($conf['company']['notification_email']); $notifyEmail->setFrom($conf['company']['email'], "SolidState"); $notifyEmail->setSubject($conf['order']['notification_subject']); $notifyEmail->setBody($body); if (!$notifyEmail->send()) { log_error("OrderDBO::complete()", "Failed to send notification e-mail."); } // Confirmation e-mail $body = $this->replaceTokens($conf['order']['confirmation_email']); $confirmEmail = new Email(); $confirmEmail->addRecipient($this->getContactEmail()); $confirmEmail->setFrom($conf['company']['email'], $conf['company']['name']); $confirmEmail->setSubject($conf['order']['confirmation_subject']); $confirmEmail->setBody($body); if (!$confirmEmail->send()) { log_error("OrderDBO::complete()", "Failed to send confirmation e-mail."); } }
/** * Update NoteDBO * * @param NoteDBO &$dbo NoteDBO to update */ function update_NoteDBO(&$dbo) { $DB = DBConnection::getDBConnection(); // Build SQL $sql = $DB->build_update_sql("note", "id = " . intval($dbo->getID()), array("updated" => DBConnection::format_datetime(time()), "username" => $dbo->getUsername(), "text" => $dbo->getText())); // Run query if (!mysql_query($sql, $DB->handle())) { throw new DBException(mysql_error($DB->handle())); } }
/** * Generate Invoice * * Creates a new Invoice and adds it to the database. */ function generate_invoice() { // Determine the correct source of the account ID $account_id = isset($this->get['account']) ? $this->get['account']->getID() : $this->post['account']->getID(); // Create a new invoice DBO $invoice = new InvoiceDBO(); $invoice->setAccountID($account_id); $invoice->setDate(DBConnection::format_datetime($this->post['date'])); $invoice->setPeriodBegin(DBConnection::format_datetime($this->post['periodbegin'])); $invoice->setPeriodEnd(DBConnection::format_datetime($this->post['periodend'])); $invoice->setNote($this->post['note']); $invoice->setTerms($this->post['terms']); // Generate lineitems $invoice->generate(); // Insert invoice into database add_InvoiceDBO($invoice); // Success $this->setMessage(array("type" => "[INVOICE_CREATED]")); $this->gotoPage("billing_view_invoice", null, "invoice=" . $invoice->getID()); }
/** * Execute Domain Order * * Register or Transfer the domain and create a new Domain Service Purchase * for this order item * * @param AccountDBO $accountDBO Account object * @return boolean True for success */ function execute($accountDBO) { switch ($this->getType()) { case "Existing": // Do nothing return true; break; case "New": if (!$this->registerDomain($accountDBO)) { return false; } break; case "Transfer": if (!$this->transferDomain($accountDBO)) { return false; } break; default: fatal_error("OrderDomainDBO::execute()", "Domain order type not supported: " . $this->getType()); } // Create a new domain service purchase record $purchaseDBO = new DomainServicePurchaseDBO(); $purchaseDBO->setAccountID($accountDBO->getID()); $purchaseDBO->setTLD($this->getTLD()); $purchaseDBO->setTerm($this->getTerm()); $purchaseDBO->setDomainName($this->getDomainName()); $purchaseDBO->setDate(DBConnection::format_datetime(time())); $purchaseDBO->setPrevInvoiceID(-1); $purchaseDBO->incrementNextBillingDate(); add_DomainServicePurchaseDBO($purchaseDBO); // Fulfill this order item $this->setStatus("Fulfilled"); update_OrderDomainDBO($this); // Success return true; }
/** * Create a New Payment DBO and save it to the database * * @param string $status SolidState's Payment status (THIS IS NOT $_POST['payment_status']) */ function newPayment($status) { // Construct a new Payment DBO $this->paymentDBO = new PaymentDBO(); $this->paymentDBO->setDate(DBConnection::format_datetime(time())); $this->paymentDBO->setAmount($_POST['mc_gross']); $this->paymentDBO->setTransaction1($_POST['txn_id']); $this->paymentDBO->setTransaction2($_POST['payer_email']); $this->paymentDBO->setType("Module"); $this->paymentDBO->setModule($this->ppModule->getName()); $this->paymentDBO->setStatus($status); if (isset($_POST['custom'])) { // This IPN contains an order ID $this->paymentDBO->setOrderID(intval($_POST['custom'])); } if (isset($_POST['invoice'])) { // This IPN contains an invoice ID $this->paymentDBO->setInvoiceID(intval($_POST['invoice'])); } // Add the Payment DBO to the database add_PaymentDBO($this->paymentDBO); // Log the new payment log_notice("PSIPNPage::newPayment()", sprintf("New payment received from Paypal. Order ID=%d, TXN=%s, Customer=%s, Amount=%s, Paypal Status=%s", intval($_POST['custom']), $_POST['txn_id'], $_POST['payer_email'], $_POST['mc_gross'], $_POST['payment_status'])); }
/** * Execute Hosting Service Order * * Create a new Hosting Service Purchase for this order item * * @param AccountDBO $accountDBO Account object * @return boolean True for success */ public function execute($accountDBO) { // Create a hosting service purchase record $purchaseDBO = new HostingServicePurchaseDBO(); $purchaseDBO->setAccountID($accountDBO->getID()); $purchaseDBO->setHostingServiceID($this->getServiceID()); $purchaseDBO->setTerm($this->getTerm()); $purchaseDBO->setDate(DBConnection::format_datetime(time())); $purchaseDBO->setDomainName($this->getDomainName()); $purchaseDBO->setPrevInvoiceID(-1); $purchaseDBO->incrementNextBillingDate(); add_HostingServicePurchaseDBO($purchaseDBO); // Fulfill the order and return $this->setStatus("Fulfilled"); update_OrderHostingDBO($this); // Success return true; }
/** * Add Payment * * Create a new PaymentDBO and add it to the database */ function add_payment() { // Create a new payment DBO $invoice_id = isset($this->get['invoice']) ? $this->get['invoice']->getID() : $this->session['new_payment']['invoice']->getID(); $payment_dbo = new PaymentDBO(); $payment_dbo->setInvoiceID($invoice_id); $payment_dbo->setDate(DBConnection::format_datetime($this->post['date'])); $payment_dbo->setAmount($this->post['amount']); $payment_dbo->setType($this->post['type']); $payment_dbo->setStatus("Completed"); $payment_dbo->setTransaction1($this->post['transaction1']); $payment_dbo->setTransaction2($this->post['transaction2']); // Insert Payment into database add_PaymentDBO($payment_dbo); // Success $this->setMessage(array("type" => "[PAYMENT_ENTERED]")); $this->gotoPage("billing_view_invoice", null, "invoice=" . $payment_dbo->getInvoiceID()); }
/** * Execute Registration */ function executeRegistration() { // Load the registrar module and verify that it is enabled $this->serviceDBO = load_DomainServiceDBO($this->purchaseDBO->getTLD()); $registry = ModuleRegistry::getModuleRegistry(); $module = $registry->getModule($this->purchaseDBO->getModuleName()); // Set the time of purchase $this->purchaseDBO->setDate(DBConnection::format_datetime(time())); // Prepare contact info $contacts['admin'] = new ContactDBO($this->accountDBO->getContactName(), $this->accountDBO->getBusinessName(), $this->accountDBO->getContactEmail(), $this->accountDBO->getAddress1(), $this->accountDBO->getAddress2(), null, $this->accountDBO->getCity(), $this->accountDBO->getState(), $this->accountDBO->getPostalCode(), $this->accountDBO->getCountry(), $this->accountDBO->getPhone(), null, $this->accountDBO->getFax()); $contacts['tech'] = $contacts['admin']; $contacts['billing'] = $contacts['admin']; // Execute the registration at the Registrar $module->registerNewDomain($this->purchaseDBO->getDomainName(), $this->purchaseDBO->getTLD(), intval($this->purchaseDBO->getTerm() / 12), $contacts, $this->accountDBO); // Store the purchase in database add_DomainServicePurchaseDBO($this->purchaseDBO); // Registration complete $this->setMessage(array("type" => "[DOMAIN_REGISTERED]", "args" => array($this->purchaseDBO->getFullDomainName()))); $this->gotoPage("domains_browse", null, null); }
/** * Renew Domain * * Set the DomainServucePurchase date to the date provided in the form, then update * the DomainServicePurchaseDBO in the database */ function renew_domain() { $registry = ModuleRegistry::getModuleRegistry(); if (!($module = $registry->getModule($this->get['dpurchase']->getModuleName()))) { throw new SWException("Failed to load registrar module: " . $this->get['dpurchase']->getModuleName()); } // Update DBO $this->get['dpurchase']->setDate(DBConnection::format_datetime($this->post['date'])); $this->get['dpurchase']->setTerm($this->post['term'] ? $this->post['term']->getTermLength() : null); update_DomainServicePurchaseDBO($this->get['dpurchase']); // Update Registrar (but only if the "contact registrar" box was checked) if ($this->post['registrar']) { $module->renewDomain($this->get['dpurchase'], $this->get['dpurchase']->getTerm()); } // Success! $this->setMessage(array("type" => "[DOMAIN_RENEWED]")); $this->goback(); }