Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

convert java class to php

Posted on 2008-06-13
7
Medium Priority
?
349 Views
Last Modified: 2010-04-21
Can anyone convert this simple java class into php?
Neil

it basically takes a error "-092832312"

and from that does a lookup returning a user friendly reason and prompt for what to do next.

Neil
public class FailReason {
 
 
  private String cause = null;
  private String action = null;
 
  public String getCause() { return this.cause; }
  public String getAction() { return this.action; }
 
  public FailReason(PaymentResponse paymentResponse) {
  
    int code;
    this.action = "";
    
    switch (code) {
		case -2147221303:
			this.cause = "Failed Denial of Service check.";
			this.action = "Please re-try in a few minutes.";
			break;
		case -2147221302:
			this.cause = "Payment Engine internal system error";
			this.action = "Please re-try in a few minutes.";
			break;
		case -2147221301:
			this.cause = "Payment Engine internal system error";
			this.action = "Please re-try in a few minutes.";
			break;	
    default:
      this.cause = "An unexpected error occurred.";
      break;
    }
 
  }
 
}

Open in new window

0
Comment
Question by:Neil Thompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 21778934
Try:
public class FailReason {
 
 
  private $cause = null;
  private $action = null;
 
  public getCause() { return $this->cause; }
  public getAction() { return $this->action; }
 
  public FailReason($paymentResponse) {
  
    $code;
    $this->action = "";
    
    switch ($code) {
            case -2147221303:
                  $this->cause = "Failed Denial of Service check.";
                  $this->action = "Please re-try in a few minutes.";
                  break;
            case -2147221302:
                  $this->cause = "Payment Engine internal system error";
                  $this->action = "Please re-try in a few minutes.";
                  break;
            case -2147221301:
                  $this->cause = "Payment Engine internal system error";
                  $this->action = "Please re-try in a few minutes.";
                  break;      
    default:
      $this->cause = "An unexpected error occurred.";
      break;
    }
 
  }
 
}

Open in new window

0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 21779022
Thanks

how would I go about calling this if I had an error number of "-2147221303"

I 'm guessing something like:
$fr = new FailReason("-2147221303")
$fr-cause = fr->getCause();
$fr-action= fr->getAction();

????

Neil
0
 
LVL 82

Expert Comment

by:hielo
ID: 21779291
Is your original Java class even working? How are you calling it? I see you have:
int code;
...
switch (code)...

but you are not initializing code anywhere, so I would expect it to always default.

>.how would I go about calling
$fr = new FailReason("-2147221303")
$fr_cause = $fr->getCause();
$fr_action= $fr->getAction();
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Author Comment

by:Neil Thompson
ID: 21779343
Hi

Yes the java code works but I'm not a java chap, just muddling through. I'll try your suggestion above
0
 
LVL 4

Accepted Solution

by:
afzz earned 1000 total points
ID: 21779345
Usage

$failreason = New FailReason(-2147221302);
$fr_cause = $failreason->getCause();
$fr_action = $failreason->getAction();
<?
class FailReason {
 
 
  var $cause = "";
  var $action = "";
  
  function getCause() { return $this->cause; }
  function getAction() { return $this->action; }
 
  function FailReason($code) {
  
 
    $this->action = "";
    
    switch ($code) {
                case -2147221303:
                        $this->cause = "Failed Denial of Service check.";
                        $this->action = "Please re-try in a few minutes.";
                        break;
                case -2147221302:
                        $this->cause = "Payment Engine internal system error";
                        $this->action = "Please re-try in a few minutes.";
                        break;
                case -2147221301:
                        $this->cause = "Payment Engine internal system error";
                        $this->action = "Please re-try in a few minutes.";
                        break;  
    default:
      $this->cause = "An unexpected error occurred.";
      break;
    }
 
  }
 
}
 
 
 
 
 
?>

Open in new window

0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 1000 total points
ID: 21779495
From what you posted initially, you do not need $code at all; you just need:
switch ($paymentResponse)
public class FailReason {
 
 
  private $cause = null;
  private $action = null;
 
  public getCause() { return $this->cause; }
  public getAction() { return $this->action; }
 
  public FailReason($paymentResponse) {
 
    $this->action = "";
    
    switch ($paymentResponse) {
            case -2147221303:
                  $this->cause = "Failed Denial of Service check.";
                  $this->action = "Please re-try in a few minutes.";
                  break;
            case -2147221302:
                  $this->cause = "Payment Engine internal system error";
                  $this->action = "Please re-try in a few minutes.";
                  break;
            case -2147221301:
                  $this->cause = "Payment Engine internal system error";
                  $this->action = "Please re-try in a few minutes.";
                  break;      
    default:
      $this->cause = "An unexpected error occurred.";
      break;
    }
 
  }
 
}

Open in new window

0
 
LVL 3

Author Closing Comment

by:Neil Thompson
ID: 31466927
Many thanks

Split points as hielo sorted the class and afzz showed my how I need to use it.

Regards
Neil
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question