saberworks has asked for the wisdom of the Perl Monks concerning the following question:

After reading on another node that I should be using Business::OnlinePayment::AuthorizeNet, I decided to try it out. It seems to me that the package is completely broken, so I'm looking for people that are successfully using it with AIM (advanced integration method) 3.1 of Authorize.net.

First, this line:
$post_data{'ENCAPSULATE'} = "TRUE";
makes every field of the server response surrounded by the string "TRUE", for example:

'server_response' => 'TRUE3TRUE,TRUE2TRUE,TRUE33TRUE,TRUECredit card number is required.TRUE,...

Commenting that out in the module itself fixes that problem, but I think there is more wrong that just that.

First, it requires the "name" field which is not required by the specifications. Second, I specify card_number as it says in the documentation, but as you can see above, I keep getting "Credit card number is required." as an error message. So for some reason the mappings of field names isn't happening correctly. I'm a bit stumped, because the manual says every field should be prefixed with an
x_
, but nowhere in OnlinePayment.pm or Authorizenet.pm can I find anything like that. Perhaps I am brain-dead, but here is my code anyway:
use Business::OnlinePayment; my $tx = new Business::OnlinePayment("AuthorizeNet"); $tx->content( type => 'VISA', login => $login, transaction_key => 'omitted', password => 'omitted', action => 'Normal Authorization', description => 'Purchase', amount => $amount, customer_id => $customer_id, first_name => $billto_fname, last_name => $billto_lname, address => $billto_address, city => $billto_city, state => $billto_state, zip => $billto_zip, card_number => '4007000000027', expiration => $exp_date, cvv2 => $cv2, name => 'Test Name' ); $tx->submit(); if($tx->is_success()) { print "Card processed successfully: ".$tx->authorization()."\n"; } else { print STDERR "Card was rejected: ".$tx->error_message()."\n"; }
My account is in test mode, which is supposed to return a success for any credit card number.

Replies are listed 'Best First'.
Re: Business::OnlinePayment::AuthorizeNet Problems
by cfreak (Chaplain) on Jul 08, 2004 at 14:28 UTC

    Yes this module does have some problems. I haven't seen the encapsulate problem, that should encapsulate the info in whatever you set it to. I also don't see this line in AuthorizeNet 3.13 (latest version), perhaps you have a different version of it?

    Also I don't see where the name field is required, and the module adds the x_ and the proper name for AuthorizeNet for you (since adding a x_ to all the params is annoying and seems unnessicary). They also don't exactly coorispond, I think the idea is to make all the OnlinePayment modules similar.

    Anyway, with the newest version, I had some problems with a missing parameter and sometimes AuthorizeNet was returning '*' characters around the fields along with the encapsulation. I wrote a small patch that fixed these problems and sent it to the authors. I don't believe they have released a new version since however.

    Make sure you have the newest version and put in the patch see if it works for you :)

    --- AuthorizeNet.pm.org 2003-08-28 14:56:03.000000000 -0500 +++ AuthorizeNet.pm 2003-08-28 14:52:51.000000000 -0500 @@ -83,6 +83,7 @@ type => 'x_Method', login => 'x_Login', password => 'x_Password', + merchant_email => 'x_Merchant_Email', transaction_key => 'x_Tran_Key', action => 'x_Type', description => 'x_Description', @@ -179,6 +180,10 @@ my $csv = new Text::CSV_XS({ 'binary'=>1 }); $csv->parse($page); my @col = $csv->fields(); + + # AuthorizeNet seems to be returning * * around + # the fields + foreach(@col) { s/(?:^\*|\*$)//g } $self->server_response($page); $self->avs_code($col[5]);
      Thanks a lot. I'm sure there's some way to apply a patch easily, could you give me a quick tip? Okay, I just checked my version. It's 2.01! No wonder it's not working! Gah I'm such an idiot, you wouldn't believe how much time I spent on this. Thanks a lot for your help. UGH.

        if you're on unix just copy my patch into a file, find where the AuthorizeNet.pm is located and do patch Authorize.pm copied_patch_file should do the trick (backup first though!)

        If you're on Windows, I don't how to patch there, I'm sure there's a utiltity for it out there somewhere, if you don't figure it out just /msg me with your email and I'll send you a copy that's been patched.