/**
  * 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();
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 /**
  * 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());
 }