Page 1 of 1

Connect to TransUnion using PHP?

Posted: Sat Mar 03, 2007 2:44 pm
by dsdintn
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello I am trying to connect to TransUnion to generate a report.  The transunion site requires a certificate.
I am trying to connect but always receive no result from them.  It appears the connection is being refused or the certificate is not being found.  TransUnion has no support but they assure me I can connect using PHP!  I converted the certificate to pem format using openssl and put it in C:/certs/TUNA.pem.
Any help would be appreciated.

Damon Doran

Below is how I try to connect:

Code: Select all

$HOST = 'test.transunionnetaccess.com';
$LOCAL_CERT_PATH = 'C:/certs/TUNA.pem';
$LOCAL_CERT_PASSPHRASE = 'CARBONIFEROUS';

// REQUEST MESSAGE
$REQUEST  = "TU4I0011 CREDIT REPORT  BABS-03 0622Z 00005206XXX1N";
$REQUEST .= "CD0105BARBARA'S TEST                 ";
$REQUEST .= "SH011";
$REQUEST .= "NM011ABSOLUTE                 CRANBERRY                           ";
$REQUEST .= "PI01587382123            ";
$REQUEST .= "AD01122          PARK                                FANTASY ISLAND             IL60750          ";
$REQUEST .= "RP0107000N    I";
$REQUEST .= "OR01YBNYN";
$REQUEST .= "AI01  000000000";
$REQUEST .= "OD010201001                                                   01";
$REQUEST .= "OD010104001                                                   01";
$REQUEST .= "ENDS012";


// HTTP REQUEST HEADER
$header  = "Host: $HOST\r\n";
$header .= "Content-Length: ".strlen($REQUEST)."\r\n";
$header .= "Connection: close";

//  array with the options to create stream context
//  define context options for HTTP request
// (use 'http' index, NOT 'httpS')
//  define context options for SSL transport
$opts = Array();
$opts['http']['method']    = "GET";
$opts['http']['header']    = $header;
$opts['http']['content']   = $REQUEST;
$opts['ssl']['local_cert'] = $LOCAL_CERT_PATH;
$opts['ssl']['passphrase'] = $LOCAL_CERT_PASSPHRASE;

//  create stream context, GET request and retrive POSTED response
//$filename = 'https://test.TransUnionNetAccess.com:3018/?ping';
$context  = stream_context_create($opts);
$filename = 'https://test.TransUnionNetAccess.com:3018/';
$content  = fopen($filename, 'r', false, $context);
$type     = get_resource_type($content);
echo "got a <b>$type</b> resource<br>\n";
fpassthru($content);
fclose($content);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Mar 03, 2007 4:50 pm
by Weirdan
I would suggest using curl instead.

Posted: Wed Mar 07, 2007 11:59 am
by dsdintn
I tried curl but get the following

Error 7: couldn't connect to host

Is the host denying the certificate? Does the certificate reside on the the machine I am sitting on or the machine or server the script is running on?
Any help would be appreciated.

Damon Doran

Posted: Wed Mar 07, 2007 2:45 pm
by Weirdan
Does the certificate reside on the the machine I am sitting on or the machine or server the script is running on?
It must be on the server running the script and you should specify where exactly it's located using curl_setopt()

Posted: Thu Mar 08, 2007 4:01 pm
by dsdintn
Yeah thought so. I still get no reponse from the server.
I have tried the certificate in different formats:
include all certificates in path
just the certificate and key
all in different orders in the pem file

Should I try using them in a .crt and key file?
Thank You

Damon Doran

Posted: Mon Apr 09, 2007 6:18 pm
by fredo67
dsdintn wrote:Yeah thought so. I still get no reponse from the server.
I have tried the certificate in different formats:
include all certificates in path
just the certificate and key
all in different orders in the pem file

Should I try using them in a .crt and key file?
Thank You

Damon Doran

Damon,
Did you find the solution here? We are encountering the same implementation with PHP and Tuna, and would like to know what you did to make it work.

Thanks
fredo67

any luck?

Posted: Fri Apr 27, 2007 2:15 pm
by hforbess
im using php and curl for tuna. It seems to connect and post just fine, seems like I only get a blank page though.

I got mine to work

Posted: Mon Apr 30, 2007 5:32 pm
by hforbess
:P
did this number
openssl pkcs12 -in host.domain.p12 -clcerts -nokeys -out host.domain.cert.pem
openssl pkcs12 -in host.domain.p12 -nocerts -nodes -out host.domain.key.pem

Posted: Sat May 05, 2007 3:35 pm
by dsdintn
Wow...awesome.
Is it the host and domain of the server that the certificate resides or the TransUnion server or you just literally named the files or it is irrelevant what you name them? I have been working on this a while and have had no luck. I am interested if you used curl, if you combined the two files into one pem file, etc.


Damon Doran

Posted: Sun May 06, 2007 10:47 am
by hforbess
well, theres the cert and the key file.
so yah, just substitute the TUNA.p12 in the above and call your cert and key pems whatever. Im really no expert on that stuff. I guess I just got lucky on google.

There is only like 5 or 6 things that you have to send to get a credit file. Make sure they are of the correct length and in the correct order. TU will give you an error code back telling you what is wrong. After that, its pretty easy

Code: Select all

$tuCurl = curl_init();
			curl_setopt($tuCurl, CURLOPT_URL,$url);
			curl_setopt ($tuCurl, CURLOPT_PORT , $port); 
			curl_setopt($tuCurl, CURLOPT_VERBOSE, 1);
			curl_setopt($tuCurl, CURLOPT_HEADER, 1);
			curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($tuCurl, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($tuCurl, CURLOPT_SSLVERSION, 3);
			curl_setopt($tuCurl, CURLOPT_SSLCERT, $certLocation);
			curl_setopt($tuCurl, CURLOPT_SSLKEY, $keyLocation);
			curl_setopt($tuCurl, CURLOPT_SSLCERTPASSWD, $certPasswd);
			curl_setopt($tuCurl, CURLOPT_POST, 1);
			curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $dataString);
			 curl_setopt($tuCurl,CURLOPT_FOLLOWLOCATION,1);
			$tuData = curl_exec($tuCurl);
			curl_close($tuCurl);
		
		       $creditFile = wordwrap ( $tuData,76, "\r\n",false );
		      //echo $creditFile;
		     return $creditFile;
note the curl_setopt($tuCurl, CURLOPT_SSL_VERIFYPEER, 0);, you have to do that, because it will never verify successfully verify the peer and it does that by default so you have to make sure and shut it off. Make sure you have the correct password for the test server( im talking in the string you send them, not the cert passwords ) , as it is different from the pass that TU gives you. Call their tech support, they are pretty helpful but PHP is not supported so only expect like debugging help I guess you would call it. For example, when i went live, I told them what I was getting back, and they were smart enuff to know that I was still somehow hitting the test server, and they were correct. :roll: duh!
Their tech support doesnt seem to be really busy and I think thats because most people use some third party and not that many people really "roll their own".

I would really be happy to help anyone out on this. Its a good feeling when you can implement something cool and help other folks.

harry

Posted: Tue May 08, 2007 4:05 pm
by dsdintn
You the man! I have never reached a dead end like this....they basically said they had no idea how or if it worked. What is the port #? I didn't even know there was a password to put in the data string but hopefully they will answer my call. I am going to implement your stuff in the next few days.

Thank You,
Damon Doran

PORT

Posted: Wed May 09, 2007 8:19 am
by hforbess
oh yeah actually, now that I think about it and look at your code, thats the reason you cant connect. You need the port number. Its 3019 on the test server and 3018 on the real one.