Stuck on Payment Processor for USAePay (similar to authorize.net)

Posts: 77
Joined: 01/18/2008

I'm stuck on the payment processor.
I'm using the defacto authorize.net and made modifications to work with the USAePay.com details.

Basically, I can entered my details and send them to the payment processor (through curl), the receipts look perfect.

But it's not validating on the ubercart site.

I can go the the ubercart orders (ex:11) and it will show the information presented in there with card details, user information, etc. But, the comments I'm entered are not showing as well.

Here is a snippet from USAePay's php api:

//get the result and parse it for the response line.
if(!strlen($result))
{
$this->result="Error";
$this->resultcode="E";
$this->error="Error reading from card processing gateway.";
$this->errorcode=10132;
$this->blank=1;
$this->curlerror=curl_error($ch);
curl_close ($ch);
return false;
}
curl_close ($ch);
$this->rawresult=$result;

if(!$result) {
$this->result="Error";
$this->resultcode="E";
$this->error="Blank response from card processing gateway.";
$this->errorcode=10132;
return false;
}

// result will be on the last line of the return
$tmp=split("\n",$result);
$result=$tmp[count($tmp)-1];

// result is in urlencoded format, parse into an array
parse_str($result,$tmp);

// check to make sure we received the correct fields
if(!isset($tmp["UMversion"]) || !isset($tmp["UMstatus"]))
{
$this->result="Error";
$this->resultcode="E";
$this->error="Error parsing data from card processing gateway.";
$this->errorcode=10132;
return false;
}

// Store results
$this->result=(isset($tmp["UMstatus"])?$tmp["UMstatus"]:"Error");
$this->resultcode=(isset($tmp["UMresult"])?$tmp["UMresult"]:"E");
$this->authcode=(isset($tmp["UMauthCode"])?$tmp["UMauthCode"]:"");
$this->refnum=(isset($tmp["UMrefNum"])?$tmp["UMrefNum"]:"");
$this->batch=(isset($tmp["UMbatch"])?$tmp["UMbatch"]:"");
$this->avs_result=(isset($tmp["UMavsResult"])?$tmp["UMavsResult"]:"");
$this->avs_result_code=(isset($tmp["UMavsResultCode"])?$tmp["UMavsResultCode"]:"");
$this->cvv2_result=(isset($tmp["UMcvv2Result"])?$tmp["UMcvv2Result"]:"");
$this->cvv2_result_code=(isset($tmp["UMcvv2ResultCode"])?$tmp["UMcvv2ResultCode"]:"");
$this->vpas_result_code=(isset($tmp["UMvpasResultCode"])?$tmp["UMvpasResultCode"]:"");
$this->convertedamount=(isset($tmp["UMconvertedAmount"])?$tmp["UMconvertedAmount"]:"");
$this->convertedamountcurrency=(isset($tmp["UMconvertedAmountCurrency"])?$tmp["UMconvertedAmountCurrency"]:"");
$this->conversionrate=(isset($tmp["UMconversionRate"])?$tmp["UMconversionRate"]:"");
$this->error=(isset($tmp["UMerror"])?$tmp["UMerror"]:"");
$this->errorcode=(isset($tmp["UMerrorcode"])?$tmp["UMerrorcode"]:"10132");
$this->custnum=(isset($tmp["UMcustnum"])?$tmp["UMcustnum"]:"");

// Obsolete variable (for backward compatibility) At some point they will no longer be set.
$this->avs=(isset($tmp["UMavsResult"])?$tmp["UMavsResult"]:"");
$this->cvv2=(isset($tmp["UMcvv2Result"])?$tmp["UMcvv2Result"]:"");


if(isset($tmp["UMcctransid"])) $this->cctransid=$tmp["UMcctransid"];
if(isset($tmp["UMacsurl"])) $this->acsurl=$tmp["UMacsurl"];
if(isset($tmp["UMpayload"])) $this->pareq=$tmp["UMpayload"];

if($this->resultcode == "A") return true;
return false;

The code above is using class information from a file that I'm not pulling in.
The below code is what I'm using for validation. It's quite screwy.

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
  $authorize = curl_exec($ch);
  if ($error = curl_error($ch)) {
    watchdog('uc_usaepaycom', $error, WATCHDOG_ERROR);
  }
  curl_close($ch);

  $response = explode(variable_get('authnet_aim_delimiter', ','), $authorize);
  $UMresult = $response[0];
  $UMstatus = $response[3];
  $UMauthCode = $response[4];

  if ($UMresult != '1') {
    $message = t('Credit card declined: !amount', array('!amount' => uc_currency_format($amount)));
    $result = array(
      'success' => FALSE,
      'comment' => t('Credit card payment declined: @text', array('@text' => $UMstatus)),
      'message' => t('Credit card payment declined: @text', array('@text' => $UMstatus)),
      'uid' => $user->uid,
    );
  }
  else {
    $message = t('Credit card charged: !amount', array('!amount' => uc_currency_format($amount)));
    $result = array(
      'success' => TRUE,
      'comment' => t('Credit card payment processed successfully.<br/>Approval code: @code', array('@code' => $UMauthCode)),
      'message' => t('Credit card payment processed successfully.<br/>Approval code: @code', array('@code' => $UMauthCode)),
      'uid' => $user->uid,
    );
  }
  uc_order_comment_save($order_id, $user->uid, $message . t('<br />Response code: @code - @text', array('@code' => $UMresult, '@text' => $UMstatus)), 'admin');

  return $result;

If it would help speed things up, I can move this to bounty.

I've also attached the usaepay.php file itself, just because.

AttachmentSize
usaepay.php_.txt27.89 KB
Posts: 4686
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Yeah, it looks like your code to parse the result from their processor is almost identical to Auth.net's, but they're two different APIs. As such, I'd expect you'll have to port the example code into the Drupal module version for it to work and strip out the Auth.net logic for parsing the result.

Posts: 77
Joined: 01/18/2008

I was being kind of lazy about it, but for someone who has done ubercart and multiple payment processors, do you think it would be easier to build off (and use) the api they provided with all the classes, or based off the code, do you think its a matter of getting the final responses after curl has sent my info?

Like I mentioned, everything is being sent correctly, its just not coming home.

Posts: 4686
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

I'm not really sure... if they have an API, it's at least worth looking into, but it seems to be some crazy class that I don't know all the details about. Sticking out tongue I generally do just like doing things manually in the module itself to avoid the extra dependency or licensing issues. I guess I'd just say do whatever works for you in this situatio, though...

Posts: 25
Joined: 12/19/2007

Just an update for any following the thread that there is now a module for USAePay at http://www.ubercart.org/contrib/6269