$application_login = '******';
// This is the connection ticket assigned to you during the application
//	registration process. To conform to Intuit security practices, you are
//	*required* to store this key *encrypted* and not in plain-text.
//
//	The ticket below is provided as an example, you should *not* store your
//	connection ticket in plain text as shown below. You should store it in your
//	database or in a separate file, outside of the web server document root,
//	encrypted with a crypto library such as {@link http://www.php.net/mcrypt}.
$connection_ticket = 'TGT-152-LWGj1YQUufTAlSW8DK1c6A';
// Create an instance of the MerchantService object
$MS = new QuickBooks_MerchantService($dsn, $path_to_private_key_and_certificate, $application_login, $connection_ticket);
// If you're using a Intuit QBMS development account, you must set this to true!
$MS->useTestEnvironment(true);
// If you want to see the full XML input/output, you can turn on debug mode
$MS->useDebugMode(true);
/*
There are several methods available in the QuickBooks_MerchantService class. 
The most common methods are described below: 
 - authorize() 
    This authorizes a given amount against the a credit card. It is important 
    to note that this *does not* actually charge the credit card, it just 
    "reserves" the amount on the credit card and guarentees that if you do a 
    capture() on the same credit card within X days, the funds will be 
    available. 
    
    Authorizations are used in situations where you want to ensure the money 
    will be availble, but not actually charge the card yet. For instance, if 
    you have an online shopping cart, you should authorize() the credit card 
    when the customer checks out. However, because you might not have the item 
    in stock, or there might be other problems with the order, you don't want 
 function qbmc_process()
 {
     global $event_details;
     $event_id = $event_details['ID'];
     if (is_null($event_id)) {
         return false;
     }
     $regis_id = $this->erm->get_regis_id();
     $post_ID = $this->erm->get_regis_post_id();
     $this->ecm->setup_event_details($event_id);
     $_totals = $this->erm->calculate_cart_totals();
     $gateway_info = $this->erm->get_gateway_info();
     $this->epl->load_file('libraries/gateways/qbmc/QuickBooks.php');
     $dsn = null;
     $path_to_private_key_and_certificate = null;
     $application_login = trim($gateway_info['_epl_user']);
     $connection_ticket = trim($gateway_info['_epl_pwd']);
     $MS = new QuickBooks_MerchantService($dsn, $path_to_private_key_and_certificate, $application_login, $connection_ticket);
     $test = $gateway_info['_epl_sandbox'] == 0 ? false : true;
     $MS->useTestEnvironment($test);
     $MS->useDebugMode(false);
     foreach ($_POST as $k => &$v) {
         trim(esc_attr($v));
     }
     $name = $_POST['_epl_cc_first_name'] . ' ' . $_POST['_epl_cc_last_name'];
     $number = $_POST['_epl_cc_num'];
     $expyear = $_POST['_epl_cc_exp_year'];
     $expmonth = date_i18n("m", strtotime($_POST['_epl_cc_exp_month']));
     $address = $_POST['_epl_cc_address'];
     $postalcode = $_POST['_epl_cc_zip'];
     $cvv = $_POST['_epl_cc_cvv'];
     $Card = new QuickBooks_MerchantService_CreditCard($name, $number, $expyear, $expmonth, $address, $postalcode, $cvv);
     $amount = $_totals['money_totals']['grand_total'];
     if ($Transaction = $MS->authorize($Card, $amount)) {
         $str = $Transaction->serialize();
         // Now convert it back to a transaction object
         $Transaction = QuickBooks_MerchantService_Transaction::unserialize($str);
         $arr = $Transaction->toArray();
         // ... and back again?
         $Transaction = QuickBooks_MerchantService_Transaction::fromArray($arr);
         // ... or an XML document?
         $xml = $Transaction->toXML();
         $Transaction = QuickBooks_MerchantService_Transaction::fromXML($xml);
         if ($Transaction = $MS->capture($Transaction, $amount)) {
             $arr = $Transaction->toArray();
             $transactionId = $arr['CreditCardTransID'];
             $data['post_ID'] = $post_ID;
             $data['_epl_grand_total'] = epl_get_balance_due();
             $data['_epl_payment_amount'] = $_totals['money_totals']['grand_total'];
             $data['_epl_payment_date'] = current_time('mysql');
             $data['_epl_payment_method'] = $this->erm->get_payment_profile_id();
             $data['_epl_transaction_id'] = $transactionId;
             $data['_epl_prediscount_total'] = epl_get_element('pre_discount_total', $_totals['money_totals'], 0);
             $data['_epl_discount_amount'] = epl_get_element('discount_amount', $_totals['money_totals'], 0);
             $data = apply_filters('epl_auth_net_aim_response_data', $data, $Transaction);
             $this->erm->update_payment_data($data);
             return true;
         } else {
             return '<div class="epl_error">ERROR: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . '</div>';
             // print('An error occured during capture: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . "\n" );
         }
     } else {
         return '<div class="epl_error">ERROR: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . '</div>';
         //print('An error occured during authorization: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . "\n" );
     }
 }