Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
siddii committed Jun 19, 2015
1 parent 2576e92 commit 2bdc348
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,39 @@

$token = $_POST['simplifyToken'];
$payment = $_POST["amount"];
$currency = isset($_POST["currency"]) ? $_POST["currency"] : 'USD';

$paymentPayload = array(
'amount' => $payment,
'token' => $token,
'description' => 'payment description',
'currency' => 'USD'
'description' => 'Test payment',
'currency' => $currency
);
$result = array();
$response = array();
try {
$payment = Simplify_Payment::createPayment($paymentPayload);
if ($payment->paymentStatus == 'APPROVED') {
$result["id"] = $payment->{'id'};
$response["id"] = $payment->{'id'};
}
$result["status"] = $payment->paymentStatus;
$response["status"] = $payment->paymentStatus;
} catch (Exception $e) {
//error handling
if ($e instanceof Simplify_ApiException) {
$result["reference"] = $e->getReference();
$result["message"] = $e->getMessage();
$result["errorCode"] = $e->getErrorCode();
$response["reference"] = $e->getReference();
$response["message"] = $e->getMessage();
$response["errorCode"] = $e->getErrorCode();
}
if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors()) {
$fieldErrors = '';
foreach ($e->getFieldErrors() as $fieldError) {
$fieldErrors = $fieldErrors . $fieldError->getFieldName()
. ": '" . $fieldError->getMessage()
. "' (" . $fieldError->getErrorCode()
. ")\n";
. ")";
}
$result["fieldErrors"] = $fieldErrors;
$response["fieldErrors"] = $fieldErrors;
}
$response["error"] = $e->getMessage();
}
echo json_encode($result);
echo json_encode($response);
?>

0 comments on commit 2bdc348

Please sign in to comment.