We help IT Professionals succeed at work.

Fatal Error on payment page

beechfielder
beechfielder asked
on
568 Views
Last Modified: 2008-01-09
Hi

We are near the end of developing an online payment system and it is being tested.  However, one person got an error on the payment page (everyone else's payments went through ok)

I cannot see why this has happened and do not have access to the server logs unfortunately

The error is

Fatal error: Call to a member function on a non-object in /homepages/11/d559862/htdocs/work/classes/class_payment.inc.php on line 131

The actual script it refers to is as follows - I am confused as to why only one person got this error and then when he tried again he was able to pay without an error.  I have marked line 131. Not sure if this is enough info but I can post more if necessary

      $xmlrpc->addParam(new xmlrpcval("dups=false,deferred=true,card_type=".$data['card_type'].",cv2=".$data['cv2'].",start_date=".$data['start_date'],"string")) ;      // Options String

// Test mode
//      $xmlrpc->addParam(new xmlrpcval("test_status=true,dups=false"));      // Options String



   //print "<pre>sending data ...\n" . htmlentities($xmlrpc->serialize()) . "... end of send\n</pre>";

   /*
   Create the XMLRPC client, using the server 'make_call', on the host 'www.secpay.com', via the https port '443'
   */
   $call      =      new xmlrpc_client("/secxmlrpc/make_call", "www.secpay.com", 443);

   /*
   Debugging is enabled for testing purposes
   */
   $call->setDebug(0);

   /*
   Send the request using the 'https' protocol.
   */
   if (!$response=$call->send($xmlrpc,20,"https")) {
      die("Transaction failed: ".$response->faultCode());
   }

LINE 131      $response_value      =      $response->value();
      $this->result=$this->parse_response_string($response_value->scalarval());
      /*
   Display response or fault information
   */
   if (!$response->faultCode()) {
            //transaction success
            if ($this->result["transaction"]=="A" && $this->result["valid"]=="true"){
                  $this->success=true;
                  $this->set_payment($data);
            }
      }
      return $this->result["code"];
}

function parse_response_string($value){
      $return['error_log']      =$value;
      $result_prepend="";
      $parse_string      =      substr($value,1);
      $temp                  =      explode("&",$parse_string);
      foreach($temp as $void){
            list($key,$value)      =      explode("=",$void);
            $return[$key]            =      $value;
      }
      $return["transaction"]=$return["code"];
      if($pos_colon=strpos($return["code"],":")){
            $return["code"]=substr($return["code"],$pos_colon+1);
            $result_prepend="P:";
      }
      for($i=0;$i<=strlen($return["code"]);$i++){
            $message[]=$this->result_code[$result_prepend.$return["code"][$i]];
      }
      $return["code"]=implode("<br />",array_unique($message));
      return $return;
}

function set_payment($data){
      $payment_db      =      user::fieldNames("payments");
      $data["amount"]                  =      $data["total_price"];
      $data["transaction"]      =      $this->result_code[$this->result["code"]];
      $data["timedate"]            =      date("Y-m-d H:i:s");
      $data["ip"]                        =      $_SERVER["REMOTE_ADDR"];
      $query      ="INSERT INTO payments ".filter::build_SQL($data,$payment_db,"insert");
      $result =$this->db->query($query);
}
}
?>



Comment
Watch Question

Can you reproduce the error? If so can you print_r($response) before your line 131 and print_r($response_value) before the following line?

Also are you sure the marked line is definitely 131? The reason I ask is that I just had a quick look at XML/RPC.php and can't immediately see how send() could return anything other than 0 or an XML_RPC_Response, whereas it *could* return an XML_RPC_Response with the value '0', causing the following line to give that error (since 0 isn't an object, you can't call scalarval() on it).

I might have missed something though, apologies if so...

Author

Commented:
Hi

Thanks for the reply, unfortunately we are not sure how to replicate it, we are testing a new system and have had 7 successful and one transaction that gave this error.  Still testing though so it may happen again.

I am wondering if it could have been something on the Secpay server that caused the problem
Presumably you've checked that invalid transactions (bad card number, etc.) do trigger the "Transaction failed" message?

Author

Commented:
Hi, yes all error reporting is working ok.  The only thing the customer said they did, was to enter a slash in the start date 02/04 rather than the format 0204

But I have double checked it and it will accept both formats.  The transaction did not actually get as far as sending the information to the secpay servers, there is no failed transaction logged.

Puzzled
How about if you simulate failure of the XMLRPC call itself, e.g. change the path to /secxmlrpc/make_cake :)

Author

Commented:
hmm will check that after the testing, don't want to do it in a live environment but will definitely give it a go later

thanks

Author

Commented:
HI

Well thank you for the answer about the value of scalarval - this helped and we found out that the problem was happening because the object was not instantiated because the XMLRPC-class didn't receive an answer from
the SecPay server.

see lines below in the payment class

if($response=$call->send($xmlrpc,20,"https")){
   $response_value    =    $response->value();
   $this->result    =    
$this->parse_response_string($response_value->scalarval());
}

We  provisionally added

  $response=$call->send($xmlrpc,20,"https");
  if (!is_object($response)) {
     die("Transaction failed: ".$response->faultCode());
  }
   $response_value    =    $response->value();
   $this->result    =    
$this->parse_response_string($response_value->scalarval());

which will now let the system die "gracefully", but it does not solve
the underlying problem, which lies with the XMLRPC class

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.