phpnetbanx-apipaysafe

Error returned in Web Service


I have been having a hell of a time trying to debug this. I am running out of ideas. I have the following simple PHP code.

$url = "https://webservices.test.optimalpayments.com/creditcardWS/CreditCardServlet/v1";          
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,"&txnMode=".$txnMode."&txnRequest=".urlencode($ch));
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                $result = curl_exec($ch);

Unfortunately every time I try to run this I keep getting an problem with XML request. Here is the request.

$txnRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
                $txnRequest .= "<ccAuthRequestV1 xmlns=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\">\n";
                $txnRequest .= "<merchantAccount>\n";
                $txnRequest .= "<accountNum>".$account."</accountNum>\n";
                $txnRequest .= "<storeID>".$merchantId."</storeID>\n";
                $txnRequest .= "<storePwd>".$merchantPwd."</storePwd>\n";
                $txnRequest .= "</merchantAccount>\n";
                $txnRequest .= "<merchantRefNum>".$merchantRefNum."</merchantRefNum>\n";
                $txnRequest .= "<amount>".$amount."</amount>\n";
                $txnRequest .= "<card>\n";
                $txnRequest .= "<cardNum>".$cardNum."</cardNum>\n";
                $txnRequest .= "<cardExpiry>\n<month>".$eMonth."</month>\n<year>".$eYear."</year>\n</cardExpiry>\n";
                $txnRequest .= "<cardType>".$cardType."</cardType>\n";
                $txnRequest .= "<cvdIndicator>".$cvdIndicator."</cvdIndicator>\n";
                $txnRequest .= "<cvd>".$cvd."</cvd>\n";
                $txnRequest .= "</card>\n";
                $txnRequest .= "<billingDetails>\n";
                $txnRequest .= "<cardPayMethod>WEB</cardPayMethod>\n";
                $txnRequest .= "<firstName>".$firstName."</firstName>\n";
                $txnRequest .= "<lastName>".$lastName."</lastName>\n";
                $txnRequest .= "<street>".$bStreet."</street>\n";
                $txnRequest .= "<city>".$bCity."</city>\n";
                $txnRequest .= "<state>".$bState."</state>\n";
                $txnRequest .= "<country>".$bCountry."</country>\n";
                $txnRequest .= "<zip>".$bZip."</zip>\n";
                $txnRequest .= "<phone>".$bPhone."</phone>\n";
                $txnRequest .= "<email>".$bEmail."</email>\n";
                $txnRequest .= "</billingDetails>\n";
                $txnRequest .= "</ccAuthRequestV1>";

Can anyone provide some insight as to what is not encoded properly?


Solution

  • @aynber is correct, it looks like you are not encoding the correct part of your request.

    I believe the correct way of doing this would be like this.

        $url = "https://webservices.test.optimalpayments.com/creditcardWS/CreditCardServlet/v1";           
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,"&txnMode=".$txnMode."&txnRequest=".urlencode($txnRequest));
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    
        $result = curl_exec($ch); 
    

    Hope that this helps.