Integration and Testing

Authorize.Net API questions and help with your payment integration.

Reply
Member
Posts: 2
Registered: ‎08-17-2011

Php IPN example

I need help.  Looking for a php example where I can get the response codes, that I then can enter into my mysql tables.

example : customer name, amount they sent, timestamp.

 

Do not care about seeing on screen, I need to enter automatically into table

 

The amount is not fixed, the customer is sending a payment ( each amount might be different)

 

Please help, 

 

Thanks

Posts: 1,609
Topics: 15
Kudos: 209
Solutions: 121
Registered: ‎06-23-2011

Re: Php IPN example

What I did was first generate a transaction and then log the output to a text file using the callback page:

 

$logfile = "{$_SERVER['DOCUMENT_ROOT']}/mylogfolder/log.txt";
$handle = fopen($logfile, 'a');
fwrite($handle, print_r($_POST, true));

This is with some of the field data modified or the fields removed entirely for security reasons, but it will give you an idea of what the output looks like:

 

Array
(
    [x_response_code] => 1
    [x_response_reason_code] => 1
    [x_response_reason_text] => This transaction has been approved.
    [x_avs_code] => Y
    [x_auth_code] => 012335
    [x_trans_id] => 12345678
    [x_card_type] => Visa
    [x_first_name] => Theodore
    [x_last_name] => Pride
    [x_company] => Fenton Web Design Firm.
    [x_address] => 1731 Smizer Mill Rd.
    [x_city] => Fenton
    [x_state] => MO
    [x_zip] => 63026
    [x_country] => US
    [x_description] => My transaction description
    [x_cust_id] => 1234
    [x_amount] => 19.95
    [x_MD5_Hash] => X5C2BA75F23E5666AD9D3A3B693E584X
)

 

From there it was simple - I knew what the field names were and what the data looked like, just had to test for success (I'm using x_response_code == 1) and if successful, store the transaction record in the database. I'll leave the database storage part up to you.

Member
Posts: 2
Registered: ‎08-17-2011

Re: Php IPN example

Thanks,

 

That helped but I really need more. 

 

What I am used to is :  our customer login to my website, enters how much they are paying and press the "buy now" button.  I then send along their userid and the payment amount to be processed.  The return, goes to an IPN and then posts to my mysql tables.

 

Do you by chance have a more complete script I might be able to cannibalize?

Posts: 1,609
Topics: 15
Kudos: 209
Solutions: 121
Registered: ‎06-23-2011

Re: Php IPN example

The data is all there in a simple associative array in $_POST. Just go into your Authorize.net control panel, set the callback URL to the page you want logging the transactions (https://), then have the callback page take the $_POST variables and store them in the database. Not sure what part you need code for - is it the initial charge, the logging, the database interaction, what? I can certainly try to help, but you have to have some amount of experience with PHP and databases - I'm not writing the entire system for free. Might be fun, but I have paying work I have to do.