cancel
Showing results for 
Search instead for 
Did you mean: 

how to get an authorization/transaction number?

It looks like I've got a working script that posts to to authorize.net (with some help from a friend) but I'm not sure how to get back a confirmation number and/or transaction number to put in my database.

 

Here's the script as it stands now. ( In the AIM.class.php, the form is verfied and the array of values to send, are set)

<?php


require("AIM.class.php");
$aim = new AIM("xxxxxxx", "xxxxxxxxxxxxxxx");


// If you want to send test transactions, use the setTesting method to
// tell the class to talk to the certification server
//$aim->setTesting(1);
$expfull = $_REQUEST['expmonth'] . $_REQUEST['expyear'];
$nameoncard = $_REQUEST['cc_name'];
$final_total = $_REQUEST['final_total'];
if (!$aim->setCard($nameoncard, $_REQUEST['ccnumber'], $_REQUEST['expmonth'], $_REQUEST['expyear'], $_REQUEST['cc_code']))
	die("The credit card is invalid: " . print_r($aim->errorStack, 1));

// Sets the customer's billing information
$aim->setBuyer($_REQUEST['bfname'], $_REQUEST['blname'], $_REQUEST['badd1'], $_REQUEST['bcity'], $_REQUEST['bstate'], $_REQUEST['bzip'], $_REQUEST['phone']);

// Attempt to process the card and set $approval to the approval code
if (!$approval = $aim->processCard("Workshops for Youth", $final_total)){
	echo "<strong>Oops!</strong><br>Error proccessing credit card: " . print_r($aim->errorStack,1);
	$appcodedesc = "Error processing credit card.";
	$approval = 0;
}else{
	// If we made it this far, the card was successfully charged
	echo "<strong>Payment Approved</strong><br>Successfully charged the credit card.  Please print for your records."; // Approval code: " . $approval;
	$approval = 1;
	$appcodedesc = "Payment Approved";
}

 

turpentyne
Member
1 REPLY 1

This is a simple version of the code I use, layered on top of an unmodified version of the PHP SDK:

    $authorize = new AuthorizeNetAIM(
        $GLOBALS['_authorize_id'], $GLOBALS['_authorize_key']);
    $authorize->setSandbox(false);

    $fields = array(
        'first_name' => $_POST['first'],
        'last_name' => $_POST['last'],
        'company' => $_POST['company'],
        'address' => $_POST['address'],
        'city' => $_POST['city'],
        'state' => $_POST['state'],
        'zip' => $_POST['zip'],
        'country' => 'US',

        'phone' => $_POST['phone'],
        'email' => $_POST['email'],

        'customer_ip' => $_SERVER['REMOTE_ADDR'],

        'description' => 'removed for privacy reasons - insert yours',
        'amount' => $_POST['initial_payment'],

        'card_num' => $_POST['card_number'],
        'exp_date' => sprintf('%02d%02d', $_POST['card_exp_month'], ($_POST['card_exp_year'] % 1000)),
        'card_code' => $_POST['card_ccv']
    );

    $authorize->setFields($fields);
    $result = $authorize->authorizeAndCapture();

    if ($result->{'response_code'} != 1)
        $errors[] = "Failure - {$result->response_reason_text}";
    else
        // Do something with $result->transaction_id

Note that I do validate the fields before putting them into the transaction, and some are inserted into $_POST by me, but specific application is left up to you.

TJPride
Expert