I want some help on PHP coding for a payment gateway ! Information My Payment gateway provider returns a value 0 , if the payment was successful, and other values ranging from 1 to 9 , in case of error. Now, problem, is :- I have passed the status value (which i get from payment gateway after payment) to $status , and have the following below code for it... if ($status != 0) { $error_message = "Transaction Failed. Code: " . $status; } Code (markup): Now it works fine and echo's this , " Transaction Failed. Code: THE STATUS CODE HERE" But what i want is, it should echo the status description message and not the status code. The status messages are given below .. function getResponseDescription($status) { switch ($status) { case "0" : $result = "Transaction Successful"; break; case "?" : $result = "Transaction status is unknown"; break; case "1" : $result = "Unknown Error"; break; case "2" : $result = "Bank Declined Transaction"; break; case "3" : $result = "No Reply from Bank"; break; case "4" : $result = "Expired Card"; break; case "5" : $result = "Insufficient funds"; break; case "6" : $result = "Error Communicating with Bank"; break; case "7" : $result = "Payment Server System Error"; break; case "8" : $result = "Transaction Type Not Supported"; break; case "9" : $result = "Bank declined transaction (Do not contact Bank)"; break; case "A" : $result = "Transaction Aborted"; break; case "C" : $result = "Transaction Cancelled"; break; case "D" : $result = "Deferred transaction has been received and is awaiting processing"; break; case "F" : $result = "3D Secure Authentication failed"; break; case "I" : $result = "Card Security Code verification failed"; break; case "L" : $result = "Shopping Transaction Locked (Please try the transaction again later)"; break; case "N" : $result = "Cardholder is not enrolled in Authentication scheme"; break; case "P" : $result = "Transaction has been received by the Payment Adaptor and is being processed"; break; case "R" : $result = "Transaction was not processed - Reached limit of retry attempts allowed"; break; case "S" : $result = "Duplicate SessionID (OrderInfo)"; break; case "T" : $result = "Address Verification Failed"; break; case "U" : $result = "Card Security Code Failed"; break; case "V" : $result = "Address Verification and Card Security Code Failed"; break; default : $result = "Unable to be determined"; } return $result; } Code (markup): I have made above function to get STATUS Message, but how should i echo them ? I mean, what shall i write in if ($status != 0) { $error_message = "Transaction Failed. Code: " . $status; } Code (markup): so $error_message = "gives output of status response description" Thank You
$error_message = "Transaction Failed. Code: " . $status; } Code (markup): Could that not be: $error_message = "Transaction Failed. Code: " . $result; } Code (markup): ? EDIT: Oops. Didn't see the function. Do what the others say.
$error_message = "Transaction Failed. Code: " . getResponseDescription($status); But I want to comment on something more important: it is not a good idea to give the zero value to success. Zero is the default for any variable, so it should not be the value for process success, you know what I mean? Let it be 100 or any other number. Now, zero means success and means no variable at all.
or $error_message = "Transaction Failed. Code: " . $status . " Error: " . getResponseDescription($status); PHP:
Thanks it worked i can not change zero values, as that is being returned from MasterCard in case of success payment.