/**
  * Process Credit Card Payment
  */
 function processCard()
 {
     // Update contact information
     $billingContact = new ContactDBO($this->post['contactname'], null, null, $this->post['address1'], $this->post['address2'], $this->post['city'], $this->post['state'], $this->post['postalcode'], $this->post['country'], $this->post['phone'], null, null);
     // Format the expire date
     $expireDate = date("my", $this->post['cardexpire']);
     // Create a new Payment DBO and process the payment
     $paymentDBO = new PaymentDBO();
     $paymentDBO->setType("Module");
     $paymentDBO->setModule($_SESSION['module']->getName());
     $paymentDBO->setOrderID($this->session['order']->getID());
     $paymentDBO->setAmount($this->session['order']->getTotal());
     $paymentDBO->setStatus("Pending");
     if (!$paymentDBO->processCreditCard($billingContact, $this->post['cardnumber'], $expireDate, $this->post['cardcode'], $this->conf['payment_gateway']['order_method'])) {
         print "card error";
         $this->setError(array("type" => "[CC_PROCESSING_ERROR]"));
         $this->reload();
     }
     // Card processed, save the payment DBO
     add_PaymentDBO($paymentDBO);
     // Complete the order
     $_SESSION['order']->complete();
     // Show receipt
     $this->gotoPage("receipt");
 }
 /**
  * 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();
 }
 /**
  * Void an Authorized Transaction
  *
  * @param PaymentDBO $paymentDBO Previously authorized payment DBO
  * @return boolean False on a processing error
  */
 function void(&$paymentDBO)
 {
     $message = $this->buildPOSTFields(array("x_login" => $this->getLoginID(), "x_version" => $this->getAPIVersion(), "x_delim_char" => $this->getDelimiter(), "x_delim_data" => "TRUE", "x_type" => "VOID", "x_method" => "CC", "x_tran_key" => $this->getTransactionKey(), "x_trans_id" => $paymentDBO->getTransaction1()));
     // Carry out the transaction
     $resp = $this->executeTransaction($message);
     // Parse the transaction response
     switch ($resp[AIM_RESP_CODE]) {
         case AIM_APPROVED:
             $paymentDBO->setStatus("Voided");
             $paymentDBO->setTransaction1($resp[AIM_RESP_TRANSACTION_ID]);
             $paymentDBO->setTransaction2($resp[AIM_RESP_APPROVAL_CODE]);
             break;
         case AIM_DECLINED:
             $paymentDBO->setStatus("Declined");
             $paymentDBO->setStatusMessage(substr($resp[AIM_RESP_REASON_TEXT], 0, 255));
             break;
         case AIM_ERROR:
         default:
             log_error("AuthorizeAIM::void()", "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);
 }
 /**
  * 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());
 }
/**
 * Load multiple PaymentDBO's from database
 *
 * @param string $filter A WHERE clause
 * @param string $sortby Field name to sort results by
 * @param string $sortdir Direction to sort in (ASEC or DESC)
 * @param int $limit Limit the number of results
 * @param int $start Record number to start the results at
 * @return array Array of PaymentDBO's
 */
function &load_array_PaymentDBO($filter = null, $sortby = null, $sortdir = null, $limit = null, $start = null)
{
    $DB = DBConnection::getDBConnection();
    // Build query
    $sql = $DB->build_select_sql("payment", "*", $filter, $sortby, $sortdir, $limit, $start);
    // Run query
    if (!($result = @mysql_query($sql, $DB->handle()))) {
        // Query error
        throw new DBException(mysql_error($DB->handle()));
    }
    if (mysql_num_rows($result) == 0) {
        // No services found
        throw new DBNoRowsFoundException();
    }
    // Build an array of DBOs from the result set
    $dbo_array = array();
    while ($data = mysql_fetch_array($result)) {
        // Create and initialize a new DBO with the data from the DB
        $dbo = new PaymentDBO();
        $dbo->load($data);
        // Add HostingServiceDBO to array
        $dbo_array[] = $dbo;
    }
    return $dbo_array;
}