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) 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([ return response()->json([
'message' => 'Unable to refund the transaction', 'message' => $msg,
], 401); ], 401);
} }
} }

View File

@ -124,24 +124,57 @@ class BraintreePaymentDriver extends BaseDriver
{ {
$this->init(); $this->init();
try { try{
$response = $this->gateway->transaction()->refund($payment->transaction_reference, $amount); $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) { } catch (Exception $e) {
return [
$data = [
'transaction_reference' => null, 'transaction_reference' => null,
'transaction_response' => json_encode($e->getMessage()), 'transaction_response' => json_encode($e->getMessage()),
'success' => false, 'success' => false,
'description' => $e->getMessage(), 'description' => $e->getMessage(),
'code' => $e->getCode(), '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) { if ($response['success'] == false) {
$this->payment->save(); $this->payment->save();
throw new PaymentRefundFailed(); throw new PaymentRefundFailed($response['description']);
} }
} }
} else { } else {