Now that that card has been authorized, let's actually capture the funds. 
    
    You can just pass in the transaction if you want to capture for the same 
    amount as the authorization. Alternatively, you can pass in a different 
    amount *less than* the authorization amount to only capture a portion of 
    the authorization. 
    
    If you want to capture more than the authorization was for, use charge(). 
    */
    // Only capture $50.00
    // $amount = 50.0;
    if ($Transaction = $MS->capture($Transaction, $amount)) {
        print 'Card captured!' . "\n";
        print_r($Transaction);
    } else {
        print 'An error occured during capture: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . "\n";
    }
} else {
    print 'An error occured during authorization: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . "\n";
}
//exit;
// If you didn't want to
if ($Transaction = $MS->charge($Card, $amount)) {
    print 'Card charged!' . "\n";
    print_r($Transaction);
} else {
    print 'An error occured during charge: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . "\n";
}
exit;
// We can issue refunds too...
if ($Transaction = $MS->refund($Card, $amount)) {
Esempio n. 2
0
<?php

/**
 * 
 * 
 * 
 * 
 * @package QuickBooks
 * @subpackage Documentation
 */
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/Users/kpalmer/Projects/QuickBooks/');
require_once 'QuickBooks.php';
require_once 'QuickBooks/MerchantService.php';
$MS = new QuickBooks_MerchantService(null, '/Users/kpalmer/Projects/QuickBooks/QuickBooks/dev/test_qbms.pem', 'test.www.academickeys.com', 'TGT-152-LWGj1YQUufTAlSW8DK1c6A');
$MS->useTestEnvironment(true);
$name = 'Keith Palmer';
$number = '5105105105105100';
$expyear = date('Y');
$expmonth = date('m');
$address = '56 Cowles Road';
$postalcode = '06279';
$cvv = null;
$Card = new QuickBooks_MerchantService_CreditCard($name, $number, $expyear, $expmonth, $address, $postalcode, $cvv);
//if ($Transaction = $MS->authorize($Card, 295))
if ($Transaction = $MS->charge($Card, 295)) {
    print 'Card authorized!';
} else {
    print 'An error occured: ' . $MS->errorNumber() . ': ' . $MS->errorMessage();
}
$name = 'Keith Palmer';
$number = '5105105105105100';
$expyear = date('Y');
$expmonth = date('m');
$address = '56 Cowles Road';
$postalcode = '06279';
$cvv = '349';
// Create the CreditCard object
$Card = new QuickBooks_MerchantService_CreditCard($name, $number, $expyear, $expmonth, $address, $postalcode, $cvv);
// Our customer #
$customerID = '1234ABCD';
// Add this credit card to the wallet
if ($walletID = $MS->addWallet($customerID, $Card)) {
    print 'New wallet ID created: ' . $walletID . "\n";
} else {
    print 'An error occurred: [' . $MS->errorNumber() . ': ' . $MS->errorMessage() . ']' . "\n";
}
exit;
// Now, let's update it
$Card->setName('Keith R. Palmer Jr.');
if ($MS->updateWallet($customerID, $walletID, $Card)) {
    print 'Wallet updated!' . "\n";
} else {
    print 'An error occurred: [' . $MS->errorNumber() . ': ' . $MS->errorMessage() . ']' . "\n";
}
// Fetch it
if ($CreditCard = $MS->getWallet($customerID, $walletID)) {
    print_r($CreditCard);
} else {
    print 'An error occurred: [' . $MS->errorNumber() . ': ' . $MS->errorMessage() . ']' . "\n";
}
 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" );
     }
 }
// Include the QuickBooks files
require_once '../QuickBooks.php';
// $dsn = 'mysql://root:@localhost/quickbooks_merchantservice';
$dsn = null;
//$path_to_private_key_and_certificate = null;							// If you're using the DESKTOP model
$path_to_private_key_and_certificate = null;
//$application_login = '******';
$application_login = '******';
//$connection_ticket = 'TGT-152-LWGj1YQUufTAlSW8DK1c6A';
$connection_ticket = 'TGT-157-p3PyZPoH3DtieLSh4ykp6Q';
// 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);
$routing = '211170282';
$account = '414074882';
$info = QuickBooks_MerchantService_CheckingAccount::INFO_PERSONAL;
$type = QuickBooks_MerchantService_CheckingAccount::TYPE_CHECKING;
$first_name = 'Keith';
$last_name = 'Palmer';
$phone = '+1 (860) 634-1602';
$Check = new QuickBooks_MerchantService_CheckingAccount($routing, $account, $info, $type, $first_name, $last_name, $phone);
// We're going to transfer $295 out of their checking account
$amount = 295.0;
if ($Transaction = $MS->debitCheck($Check, $amount, QuickBooks_MerchantService::MODE_INTERNET)) {
    print_r($Transaction);
} else {
    print 'An error occured during refund: ' . $MS->errorNumber() . ': ' . $MS->errorMessage() . "\n";
}