cancel
Showing results for 
Search instead for 
Did you mean: 

PHP Authorize.net SIM Integration Help?

I need some help to understand how can I track the data to insert into the db after the payment has been processed on authorize.net using SIM method. I'm storing all data in to session array and after hitting "Confirm and pay now Button" it goes to authorize.net transaction detail page and upon click the button for the URL to go back to my website it comes there with no values of my session I need to store after the payment has been processed.

Please see my form values below

 

<FORM action="<? echo $url ?>" method="POST" id="phormy" name="phormy">

<input type='hidden' name='x_relay_url' value='http://example.com/confirm.php'>
<INPUT TYPE='hidden' NAME="x_relay_response" VALUE="false">
<input type='hidden' name='x_email_customer' value='TRUE'>
<input type="hidden" name="x_url" value="http://example.com/confirm.php" />
<input type='hidden' name='x_login' value='<?php echo $loginID; ?>' />
<input type='hidden' name='x_amount' value='<?php echo $total_cost;?>'>
<input type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' />
<input type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
<input type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' />
<input type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' />
<input type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' />
<input type='hidden' name='x_card_num' value='<?php echo $_SESSION['confirmstep2']['Creditcartnumber'];?>'>
<input type='hidden' name='x_exp_date' value='<?php echo $_SESSION['confirmstep2']['Creditcartmonth'].substr($_SESSION['confirmstep2']['Creditcartyear'],-2);?>'>
<input type='hidden' name='x_first_name' value='<?php echo $_SESSION['confirmstep2']['firstname'];?>'>
<input type='hidden' name='x_last_name' value='<?php echo $_SESSION['confirmstep2']['lastname'];?>'>
<input type='hidden' name='x_address' value='<?php echo $_SESSION['confirmstep2']['address'];?>'>
<input type='hidden' name='x_city' value='<?php echo $_SESSION['confirmstep2']['city'];?>'>
<input type='hidden' name='x_state' value='<?php echo $_SESSION['confirmstep2']['state'];?>'>
<input type='hidden' name='x_zip' value='<?php echo $_SESSION['confirmstep2']['zip'];?>'>
<input type='hidden' name='x_email' value='<?php echo $_SESSION['confirmstep2']['email'];?>'>
<input type='hidden' name='x_description' value='Your account is now setup. Thank you for using '>
<input type='hidden' name='subscription_start' value='<?php echo date('m-d-yyyy');?>'>
<input type='hidden' name='renew' value='F'>
<input type='hidden' name='on_length' value='52'>
<!-- POST VARS -->
<input type='hidden' name='checkSession' value='<?php echo $_SESSION['checkSession'];?>'>
<input type='hidden' name='check' value='<?php echo $_SESSION['check'];?>'>

 

 

Please let me know how can I manage sessions using this form or what should be the process to get all session data after payment has been made?

 

Thanks in Advance

markqrm
Member
6 REPLIES 6

See Section 4 - Receipt Options:

http://www.authorize.net/support/SIM_guide.pdf

 

Probably the best way to update your database is with a relay response page. You configure a relay response URL in your control panel, then this page is posted all the transaction data every time a transaction runs through (including transactions you do manually) and you can update your database based on customer ID or transaction ID, depending on which you're passing through. Something like this (partially untested):

 

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/library/mysql.php');

$logfile = "{$_SERVER['DOCUMENT_ROOT']}/log_folder/log.txt";
$handle = fopen($logfile, 'a');

// Removing some fields I don't want to log before logging
// Edit this list as necessary
foreach (array('x_method', 'x_phone', 'x_fax', 'x_email', 'x_type', 'x_ship_to_first_name', 'x_ship_to_last_name', 'x_ship_to_company', 'x_ship_to_address', 'x_ship_to_city', 'x_ship_to_state', 'x_ship_to_zip', 'x_ship_to_country', 'x_tax', 'x_duty', 'x_freight', 'x_tax_exempt', 'x_po_num', 'x_cvv2_resp_code', 'x_cavv_response', 'x_test_request') as $key)
    unset($_POST[$key]);

fwrite($handle, print_r($_POST, true));

// --------------------------------------------

// Change this if you have a different field you're looking for
if ($_POST['x_invoice_num']) {
    if (!$link = db_connect())
        fwrite($handle, "Unable to connect to database.\n");

    elseif ($_POST['x_response_code'] == 1) {
        $query = queryMysql("
        UPDATE invoices SET paid = 1 WHERE idn = {idn}",
        array(
            idn => $_POST['x_invoice_num']
        ));

        if (!$result = mysql_query($query, $link))
            fwrite($handle, "ERROR: Unable to update invoice status in database.\n");
        else
            fwrite($handle, "Invoice updated in database.\n");
    }

    else fwrite($handle, "ERROR: Bad response code.\n");
}
else fwrite($handle, "SKIPPED: No invoice number, perhaps manually-entered transaction.\n");
?>

 

TJPride
Expert

Thank you for your response, but I have a question:

 

The documentation in Section 4 says: " Relay Response does not redirect the end user back to your server, but relays your specified Relay URL to the end user through our receipt page".  This being the case, and since I'm developing in server-side PHP, I cannot access my session variables that are stored on my server.  As a result, I can't write the details that I'd like to into my database, I can only write what's being returned from the payment gateway (x_invoice_num, etc.)

 

Is there any way for me to be able to write my own SESSION data into my database after getting a respose from Authorize.net?

When I posted before, I should have said silent post and not relay response. A silent post page gets a $_POST of transaction data every time a transaction goes through, no matter what API you're using (AIM, SIM, ARB, etc.), so you can easily update your database. It will receive all the data filled out on the SIM form. Go into your control panel and specify a silent post URL, then try out the code I posted before. The page should log when a transaction goes through from your SIM.

I appreciate that very much, thank you.

 

But let's say before checkout, I collected a bunch of information that I stored in my own SESSION variables.  I'd prefer to put my own "custom" information into the database instead of the silent posted data that comes from the SIM form.  Is there a way to do that or is it unsupported?

 

Thanks for your time and help!

Oh, I see one way to do it.  The page that I have that passes information to the payment gateway can write the information to the database with a 'paid' flag set to false.  If a success message comes back from the payment gateway, I can then go in and flip the 'paid' flag to true, indicating that the payment was cleared.  This will work for my purposes, but I am still curious to know if I can get access to my SESSION data after getting a response from the payment gateway, thanks!

You can submit a customer ID or invoice ID to Authorize.net along with the amount and so on. Just add the info to your database, get back the record ID, then pass that in one of the fields. When it comes out the other end, use it to update the flag in the database.

 

x_invoice_num

x_cust_id