interfacing to Authorize.net using AIM method and cURL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GluedToTheScreen

    interfacing to Authorize.net using AIM method and cURL

    I have a small PHP ecommerce site set up using Authorize.net's SIM (simple)
    interface. Working fine, but... I'd like to implement their AIM interface
    (so visitor's will never see the gateway's URL).

    I found a script that does this but requires cURL... and my hosting provider
    doesn't support it.

    Here is the snippet of the code that uses cURL functions ($data values are
    set before this from the purchase form):


    $curl_handle = curl_init ();
    curl_setopt ($curl_handle, CURLOPT_URL,
    "https://secure.authoriz e.net/gateway/transact.dll");
    curl_setopt ($curl_handle, CURLOPT_FOLLOWL OCATION, 1);
    curl_setopt ($curl_handle, CURLOPT_RETURNT RANSFER, 1);
    curl_setopt ($curl_handle, CURLOPT_POST, 1);
    curl_setopt ($curl_handle, CURLOPT_POSTFIE LDS, $data);
    $response = curl_exec ($curl_handle) or die ("There has been an error
    connecting to Authorize.net." );
    curl_close ($curl_handle);


    It appears that data is being posted to the gateway and information returned
    (credit card accepted/declined) and then processed without actual web pages
    being displayed.

    What is cURL actually doing and can it be done some other way?

    Is there any way I can accomplish the same thing without curl libraries...
    maybe write my own lower level code? I can certainly post data to the
    gateway... and, if I knew how to accept the returned data, can perform the
    necessary steps from there. My big blank spot seems to be how to receive
    that data response.

    Thanks.

    Rick


  • Appletalk
    New Member
    • Aug 2005
    • 1

    #2
    Check out this function

    # $host includes host and path and filename
    # ex: "myserver.c om/this/is/path/to/file.php"
    # $query is the POST query data
    # ex: "a=thisstring&n umber=46&string =thatstring
    # $others is any extra headers you want to send
    # ex: "Accept-Encoding: compress, gzip\r\n"
    function post($host,$que ry,$others=''){
    $path=explode('/',$host);
    $host=$path[0];
    unset($path[0]);
    $path='/'.(implode('/',$path));
    $post="POST $path HTTP/1.1\r\nHost: $host\r\nConten t-type: application/x-www-form-urlencoded\r\n$ {others}User-Agent: Mozilla 4.0\r\nContent-length: ".strlen($query )."\r\nConnecti on: close\r\n\r\n$q uery";
    $h=fsockopen($h ost,80);
    fwrite($h,$post );
    for($a=0,$r=''; !$a;){
    $b=fread($h,819 2);
    $r.=$b;
    $a=(($b=='')?1: 0);
    }
    fclose($h);
    return $r;
    }

    Posted on http://uk.php.net/fsockopen

    I'm sure this will help you out.

    Comment

    Working...