[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

convert java class to php

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
Neil Thompson
Asked:
Neil Thompson
  • 3
  • 3
2 Solutions
 
hieloCommented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
hieloCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Hi

Yes the java code works but I'm not a java chap, just muddling through. I'll try your suggestion above
0
 
afzzCommented:
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
 
hieloCommented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Many thanks

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

Regards
Neil
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now