function authorizepayment($REQUEST)
{
    if (!checkCreditCard($REQUEST['x_card_num'], $REQUEST['card_type'], $ccerror, $ccerrortext)) {
        $_SESSION['donate_msg'] = 'Please enter a valid credit card number.';
        return false;
    } else {
        $transaction = new AuthorizeNetAIM();
        $transaction->setSandbox(AUTHORIZENET_SANDBOX);
        $transaction->setFields(array('amount' => $REQUEST['amount'], 'card_num' => $REQUEST['x_card_num'], 'exp_date' => $REQUEST['exp_month'] . '/' . $REQUEST['exp_year'], 'first_name' => $REQUEST['first_name'], 'last_name' => $REQUEST['last_name'], 'address' => $REQUEST['address'], 'city' => $REQUEST['city'], 'state' => $REQUEST['state'], 'country' => $REQUEST['country'], 'zip' => $REQUEST['zip'], 'email' => $REQUEST['email']));
        $transaction->setCustomField("Donation Form", $REQUEST["form_id"]);
        $transaction->setCustomField("Donation Type", $REQUEST["donation_type"]);
        $transaction->addLineItem("Donation", "Donation to '" . get_bloginfo("name") . "'", "Donation to '" . get_bloginfo("name") . "' using the form: " . $REQUEST["form_id"], 1, $REQUEST['amount'], false);
        $response = $transaction->authorizeAndCapture();
        if ($response->approved) {
            $_SESSION['donate_msg'] = $response->response_reason_text;
            return true;
        } else {
            $_SESSION['donate_msg'] = $response->response_reason_text;
            return false;
        }
    }
}
 public function testMultipleLineItems()
 {
     $merchant = (object) array();
     $merchant->login = AUTHORIZENET_API_LOGIN_ID;
     $merchant->tran_key = AUTHORIZENET_TRANSACTION_KEY;
     $merchant->allow_partial_auth = "false";
     $creditCard = array('exp_date' => '02/2012', 'card_num' => '6011000000000012', 'card_code' => '452');
     $transaction = array('amount' => rand(100, 1000), 'duplicate_window' => '10', 'footer_email_receipt' => 'thank you for your business!', 'header_email_receipt' => 'a copy of your receipt is below');
     $order = array('description' => 'Johns Bday Gift', 'invoice_num' => '3123', 'line_item' => 'item1<|>golf balls<|><|>2<|>18.95<|>Y');
     $customer = (object) array();
     $customer->first_name = "Jane";
     $customer->last_name = "Smith";
     $customer->company = "Jane Smith Enterprises Inc.";
     $customer->address = "20 Main Street";
     $customer->city = "San Francisco";
     $customer->state = "CA";
     $customer->zip = "94110";
     $customer->country = "US";
     $customer->phone = "415-555-5557";
     $customer->fax = "415-555-5556";
     $customer->email = "*****@*****.**";
     $customer->cust_id = "55";
     $customer->customer_ip = "98.5.5.5";
     $shipping_info = (object) array();
     $shipping_info->ship_to_first_name = "John";
     $shipping_info->ship_to_last_name = "Smith";
     $shipping_info->ship_to_company = "Smith Enterprises Inc.";
     $shipping_info->ship_to_address = "10 Main Street";
     $shipping_info->ship_to_city = "San Francisco";
     $shipping_info->ship_to_state = "CA";
     $shipping_info->ship_to_zip = "94110";
     $shipping_info->ship_to_country = "US";
     $shipping_info->tax = "CA";
     $shipping_info->freight = "Freight<|>ground overnight<|>12.95";
     $shipping_info->duty = "Duty1<|>export<|>15.00";
     $shipping_info->tax_exempt = "false";
     $shipping_info->po_num = "12";
     $sale = new AuthorizeNetAIM();
     $sale->setFields($creditCard);
     $sale->setFields($shipping_info);
     $sale->setFields($customer);
     $sale->setFields($order);
     $sale->setFields($merchant);
     $sale->setFields($transaction);
     $sale->addLineItem('item2', 'golf tees', 'titanium tees', '2', '2.95', 'Y');
     $sale->addLineItem('item3', 'golf shirt', 'red, large', '2', '3.95', 'Y');
     $response = $sale->authorizeAndCapture();
     $this->assertTrue($response->approved);
 }
Exemple #3
0
function espresso_process_aim($payment_data)
{
    extract($payment_data);
    global $wpdb, $org_options;
    require_once 'AuthorizeNet.php';
    $authnet_aim_settings = get_option('event_espresso_authnet_aim_settings');
    $authnet_aim_login_id = $authnet_aim_settings['authnet_aim_login_id'];
    $authnet_aim_transaction_key = $authnet_aim_settings['authnet_aim_transaction_key'];
    // Enable test mode if needed
    //4007000000027  <-- test successful visa
    //4222222222222  <-- test failure card number
    if ($authnet_aim_settings['use_sandbox']) {
        define("AUTHORIZENET_SANDBOX", true);
        define("AUTHORIZENET_LOG_FILE", true);
    } else {
        define("AUTHORIZENET_SANDBOX", false);
    }
    //start transaction
    $transaction = new AuthorizeNetAIM($authnet_aim_login_id, $authnet_aim_transaction_key);
    echo '<!--Event Espresso Authorize.net AIM Gateway Version ' . $transaction->gateway_version . '-->';
    $transaction->amount = $_POST['amount'];
    $transaction->card_num = $_POST['card_num'];
    $transaction->exp_date = $_POST['exp_date'];
    $transaction->card_code = $_POST['ccv_code'];
    $transaction->first_name = $_POST['first_name'];
    $transaction->last_name = $_POST['last_name'];
    $transaction->email = $_POST['email'];
    $transaction->address = $_POST['address'];
    $transaction->city = $_POST['city'];
    $transaction->state = $_POST['state'];
    $transaction->zip = $_POST['zip'];
    $transaction->cust_id = $_POST['x_cust_id'];
    $transaction->invoice_num = $_POST['invoice_num'];
    if ($authnet_aim_settings['test_transactions']) {
        $transaction->test_request = "true";
    }
    $sql = "SELECT attendee_session FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id='" . $attendee_id . "'";
    $session_id = $wpdb->get_var($sql);
    $sql = "SELECT a.final_price, a.quantity, ed.event_name, a.price_option, a.fname, a.lname FROM " . EVENTS_ATTENDEE_TABLE . " a JOIN " . EVENTS_DETAIL_TABLE . " ed ON a.event_id=ed.id ";
    $sql .= " WHERE attendee_session='" . $session_id . "' ORDER BY a.id ASC";
    $items = $wpdb->get_results($sql);
    foreach ($items as $key => $item) {
        $item_num = $key + 1;
        $transaction->addLineItem($item_num, substr_replace($item->event_name, '...', 28), substr($item->price_option . ' for ' . $item->event_name . '. Attendee: ' . $item->fname . ' ' . $item->lname, 0, 255), $item->quantity, $item->final_price, FALSE);
    }
    $payment_data['txn_type'] = 'authorize.net AIM';
    $payment_data['payment_status'] = 'Incomplete';
    $payment_data['txn_id'] = 0;
    $payment_data['txn_details'] = 'No response from authorize.net';
    $payment_data = apply_filters('filter_hook_espresso_prepare_event_link', $payment_data);
    $payment_data = apply_filters('filter_hook_espresso_get_total_cost', $payment_data);
    //Capture response
    $response = $transaction->authorizeAndCapture();
    if (!empty($response)) {
        if ($authnet_aim_settings['use_sandbox']) {
            $payment_data['txn_id'] = $response->invoice_number;
        } else {
            $payment_data['txn_id'] = $response->transaction_id;
        }
        $payment_data['txn_details'] = serialize(get_object_vars($response));
        if ($response->approved) {
            $payment_data['payment_status'] = 'Completed';
            ?>
			<h2><?php 
            _e('Thank You!', 'event_espresso');
            ?>
</h2>
			<p><?php 
            _e('Your transaction has been processed.', 'event_espresso');
            ?>
</p>
			<p><?php 
            __('Transaction ID:', 'event_espresso') . $response->transaction_id;
            ?>
</p>
			<?php 
        } else {
            print $response->error_message;
            $payment_data['payment_status'] = 'Payment Declined';
        }
    } else {
        ?>
		<p><?php 
        _e('There was no response from Authorize.net.', 'event_espresso');
        ?>
</p>
		<?php 
    }
    add_action('action_hook_espresso_email_after_payment', 'espresso_email_after_payment');
    return $payment_data;
}