tags:

views:

17

answers:

1

I having trouble posting XML to a payment gateway using PHP.

The gateway (PSiGate) gives this sandbox url to POST XML to: https://dev.psigate.com:8645/Messenger/AMMessenger

Here the code:

if (isset($_POST) && $_GET['task'] == 'new') {
    $dealer = new Dealer($USER->getDealerId());
    $contact = $dealer->getContact();
    // new PSiGate Account
    $xml  = '<?XML version="1.0"?>';
    $xml .= "<Request>\n";
    $xml .= "   <CID>10000001</CID>\n";
    $xml .= "   <UsertID>teststore</UserID>\n";
    $xml .= "   <Password>testpass</Password>\n";  
    $xml .= "   <Action>AMA01</Action>\n";  
    $xml .= "   <Account>\n";
    $xml .= "       <AccountID>".$USER->getDealerId()."</AccountID>\n";
    $xml .= "       <Name>".$contact->getFirstname()." ".$contact->getFirstname()."</Name>\n";
    $xml .= "       <Company>".$contact->getCompany()."</Company>\n";
    $xml .= "       <Address1>".$contact->getAddressLine1()."</Address1>\n";
    $xml .= "       <Address2>".$contact->getAddressLine2()."</Address2>\n";
    $xml .= "       <City>".$contact->getCity()."</City>\n";
    $xml .= "       <Province>".$contact->getProvince()."</Province>\n";
    $xml .= "       <Postalcode>".$contact->getPostalCode(TRUE)."</Postalcode>\n";
    $xml .= "       <Country>".$contact->getCountry()."</Country>\n";
    $xml .= "       <Phone>".$contact->getWorkPhone(TRUE)." EXT. ".$contact->getWorkPhoneExt()."</Phone>\n";
    $xml .= "       <Fax>".$contact->getFaxPhone(TRUE)."</Fax>\n";
    $xml .= "       <Email>".$contact->getEmail()."</Email>\n";
    $xml .= "       <CardInfo>\n";
    $xml .= "           <CardHolder>".$_POST['Bname']."</CardHolder>\n";
    $xml .= "           <CardNumber>".$_POST['CardNumber']."</CardNumber>\n";
    $xml .= "           <CardExpMonth>".$_POST['CardExpMonth']."</CardExpMonth>\n";
    $xml .= "           <CardExpYear>".$_POST['CardExpYear']."</CardExpYear>\n";
    $xml .= "       </CardInfo>\n";
    $xml .= "   </Account>\n";
    $xml .= "</Request>\n";
    $fp = fsockopen("dev.psigate.com", 8645, $errno, $errstr, 30);
    if (!$fp)    {
        echo 'Failed to open connection.';
    } else {
        $contentlength = strlen($xml);
        $out  = "POST /Messenger/AMMessenger HTTP/1.0\r\n";
        $out .= "Host: ssl://dev.psigate.com\r\n";
        $out .= "Connection: Keep-Alive\r\n";
        $out .= "Content-type: application/x-www-form-urlencoded\r\n";
        $out .= "Content-length: $contentlength\r\n\r\n";
        $out .= "XML=$xml";
        fwrite($fp, $out);
        while (!feof($fp)) {
            $theOutput .= fgets($fp, 128);
        }
        fclose($fp);
        echo "there should be output";       
        echo $theOutput;
    } 
}

I don't get any output just the message: "there should be output", and script runs for about 45 secs or so I believe it's doing something..lol!

+1  A: 

try:

<?php
if (isset($_POST) && $_GET['task'] == 'new') {
    $dealer = new Dealer($USER->getDealerId());
    $contact = $dealer->getContact();
    // new PSiGate Account
    $xml  = '<?XML version="1.0"?>' . "\n";
    $xml .= "<Request>\n";
    $xml .= "   <CID>10000001</CID>\n";
    $xml .= "   <UsertID>teststore</UserID>\n";
    $xml .= "   <Password>testpass</Password>\n";  
    $xml .= "   <Action>AMA01</Action>\n";  
    $xml .= "   <Account>\n";
    $xml .= "       <AccountID>".$USER->getDealerId()."</AccountID>\n";
    $xml .= "       <Name>".$contact->getFirstname()." ".$contact->getFirstname()."</Name>\n";
    $xml .= "       <Company>".$contact->getCompany()."</Company>\n";
    $xml .= "       <Address1>".$contact->getAddressLine1()."</Address1>\n";
    $xml .= "       <Address2>".$contact->getAddressLine2()."</Address2>\n";
    $xml .= "       <City>".$contact->getCity()."</City>\n";
    $xml .= "       <Province>".$contact->getProvince()."</Province>\n";
    $xml .= "       <Postalcode>".$contact->getPostalCode(TRUE)."</Postalcode>\n";
    $xml .= "       <Country>".$contact->getCountry()."</Country>\n";
    $xml .= "       <Phone>".$contact->getWorkPhone(TRUE)." EXT. ".$contact->getWorkPhoneExt()."</Phone>\n";
    $xml .= "       <Fax>".$contact->getFaxPhone(TRUE)."</Fax>\n";
    $xml .= "       <Email>".$contact->getEmail()."</Email>\n";
    $xml .= "       <CardInfo>\n";
    $xml .= "           <CardHolder>".$_POST['Bname']."</CardHolder>\n";
    $xml .= "           <CardNumber>".$_POST['CardNumber']."</CardNumber>\n";
    $xml .= "           <CardExpMonth>".$_POST['CardExpMonth']."</CardExpMonth>\n";
    $xml .= "           <CardExpYear>".$_POST['CardExpYear']."</CardExpYear>\n";
    $xml .= "       </CardInfo>\n";
    $xml .= "   </Account>\n";
    $xml .= "</Request>\n";
    $fp = fsockopen("ssl://dev.psigate.com", 8645, $errno, $errstr, 30);
    if (!$fp)    {
        echo 'Failed to open connection.';
    } else {
        $contentlength = strlen($xml);
        $out  = "POST /Messenger/AMMessenger HTTP/1.1\r\n";
        $out .= "Host: dev.psigate.com\r\n";
        $out .= "Connection: close\r\n";
        $out .= "Content-type: application/x-www-form-urlencoded\r\n";
        $out .= "Content-length: $contentlength\r\n\r\n";
        $out .= "XML=$xml";
        fwrite($fp, $out);
        while (!feof($fp)) {
            $theOutput .= fgets($fp, 128);
        }
        fclose($fp);
        echo "there should be output";       
        echo $theOutput;
    } 
}
nathan
I don't think fsockopen() takes ssl:// need to be in the header.. correct me if I wrong.
Mikey1980
hostnameIf you have compiled in OpenSSL support, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host.
nathan
Thanks anyways but no dice.. using cURL instead.. still learning somthing..lol!
Mikey1980