SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to write a script to send data to authorize.net and I've run into a snag.

    Here is what I have to do:

    - present the user with a form to provide personal information.
    - send that data to authorize.net
    - using the very same page that sent the data, accept the result of the data back from authorize.net (credit card accepted, declined, whatever)
    - process that data, and do one of two conditions based on whether the customer was accepted.

    this doesnt seem that hard, but having to do it with one script has me stumped...can anyone help? even very rough pseudo code
    to point out the basic concept here would be great.

    Thanks again, guys
    Luke

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I read your earlier post I was wondering because doesn't authorize.net post a query string back to your page? What is the var that holds the response code something like x_response_code I would check for the existence at the top of the page and put all the stuff that coincides with receiving the repsonse in there. Very rough example

    if ($x_response_code) {
    if ($x_repsonse_code == 1) {
    //Do some approval stuff
    }
    else {
    //Do some declined stuff
    }
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok...I follow you. Now, is this assuming that cURL that you mentioned in a previous post is implemented on the server, or would that not be needed for this?
    Luke

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No with cURL you never post anything to their site. This is the standard old post to authorize and then they post back. You know how when you have a from that posts to itself you normally check to see if some var is present in a nif statement like if ($submit) well this is all you are really doing but you are looking for a var that authorize.net has submitted to your page
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wimpypenguin, BTW, cURL is implemented on the machine you are on
    cogito, ergo sum

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, guys
    Vinay, I would have bugged you with this question too, but I figured you've already gone above and beyond the call of duty for tech support (in the form of answering my newbie questions)

    It turns out that authorize.net has a couple different methods for direct connection processing. One requires a secure connection between my site, the customers site AND authorize.net's server...the other only needs a secure connection between my site and authorize.net.

    The documentation is here: http://www.authorizenet.com/support/docs/
    Click developers guide then find "When to use which method" on that page.

    It looks like I should be able to use the ADC Relay Response implementation without needing cURL or anything like that? I just don't want to fork over my cash, then find out it's something that I can't even use.

    Thanks,
    Luke

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Luke, just to start off, cURL and OpenSSL are both free, your only purchase would be the secure cert and the authorize.net fees. The only advantage I see in using cURL is that you are not posting data through HTTP you are making a secure scoket connection with authorize.net server and apssing data to it and it then prosesses the data and sends a repsonse back that can be parsed. With the other methods you are simply posting a from to them and they post a form back to you. Do you see the difference?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew that cURL was free, I was just confused as to when it would have to be used...tech support for authorizenet told me over the phone that my script would have to accept data from a secure connection -- I was assuming that meant a "secure socket", and they even said PHP can't do that...but if it's just accepting variables from http like any other script accepts form variables, it shouldnt be a problem

    Thanks, Freddy

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See that is where everybody gets confused, it isn't like accepting vars from a http query string, and they were correct about PHP not being able to make secure socket connections. cURL runs on the server and independently from PHP. You use PHP's exec() function to make the connection. Now you can compile PHP with libcUrl I haven't done it yet, but plan to play around wit hit soon. Let me show you what I mean here is a sample script to use cURL and PHP to make a socket connection with authorize.net

    $curl = "/usr/local/bin/curl";
    $userid = "authorizenetid";
    $total = "1.00";
    $cc_number = "41111111111111";
    $cc_exp = "1002";
    $invoiceno = "4365356536";
    $billing_address = urlencode("140 West Some St Sometown, CA"_;
    $billing_zip = "999999";
    exec("$curl -d 'x_Login=$userid&x_Amount=$total&x_Card_Num=$cc_number&x_Exp_Date=$cc_exp&x_ADC_URL=FALSE&x_ADC_Delim_Data=TRUE&x_Invoice_Num=$invoiceno&x_Version=3.0&x_Address=$billing_address&x_Zip=$billing_zip' https://secure.authorize.net/gateway/transact.dll", $authorize, $ret);
    $auth_return = split("\,", $authorize[0]);
    // for debugging you can print the variables returned:
    for ($i = 0; $i < 39; ++$i) {
    echo "Code".$i + 1.": ".$auth_return[$i]."<BR>";
    }

    if($auth_return[0] == 1){
    $auth_code = $auth_return[4];
    $avs_code = $auth_return[5];
    $trans_id = $auth_return[6];
    }
    elseif($auth_return[0] == 2){
    echo "<b>Your order cannot be processed at this time, as your credit card was not accepted.</b><br>";
    }
    elseif($auth_return[0] == 3){
    echo "<b>An error has occurred and your order cannot be processed at this time.</b><br>";
    }


    Based on the first var that gets passed back we can determine whether the transaction was approved or not.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    /me notices anticipated issues and would like to get on it before the arise

    change the line which says:
    $curl = "/usr/local/bin/curl";

    to
    $curl = "curl";

    (i dont use standard locations)
    cogito, ergo sum


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •