Provide more detailed failure reports

This commit is contained in:
David Bomba 2021-08-25 14:36:30 +10:00
parent 8bcfeffb11
commit bedc319094
3 changed files with 53 additions and 12 deletions

View File

@ -26,8 +26,16 @@ class PaymentRefundFailed extends Exception
*/
public function render($request)
{
// $msg = 'Unable to refund the transaction';
$msg = ctrans('texts.warning_local_refund');
if($this->getMessage() && strlen($this->getMessage()) >=1 )
$msg = $this->getMessage();
return response()->json([
'message' => 'Unable to refund the transaction',
'message' => $msg,
], 401);
}
}

View File

@ -124,24 +124,57 @@ class BraintreePaymentDriver extends BaseDriver
{
$this->init();
try {
try{
$response = $this->gateway->transaction()->refund($payment->transaction_reference, $amount);
return [
'transaction_reference' => $response->id,
'transaction_response' => json_encode($response),
'success' => (bool)$response->success,
'description' => $response->status,
'code' => 0,
];
} catch (Exception $e) {
return [
$data = [
'transaction_reference' => null,
'transaction_response' => json_encode($e->getMessage()),
'success' => false,
'description' => $e->getMessage(),
'code' => $e->getCode(),
];
SystemLogger::dispatch(['server_response' => null, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_BRAINTREE, $this->client, $this->client->company);
return $data;
}
if($response->success)
{
$data = [
'transaction_reference' => $response->id,
'transaction_response' => json_encode($response),
'success' => (bool)$response->success,
'description' => $response->status,
'code' => 0,
];
SystemLogger::dispatch(['server_response' => $response, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_BRAINTREE, $this->client, $this->client->company);
return $data;
}
else{
$error = $response->errors->deepAll()[0];
$data = [
'transaction_reference' => null,
'transaction_response' => $response->errors->deepAll(),
'success' => false,
'description' => $error->message,
'code' => $error->code,
];
SystemLogger::dispatch(['server_response' => $response, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_BRAINTREE, $this->client, $this->client->company);
return $data;
}
}

View File

@ -81,7 +81,7 @@ class RefundPayment
if ($response['success'] == false) {
$this->payment->save();
throw new PaymentRefundFailed();
throw new PaymentRefundFailed($response['description']);
}
}
} else {