Skip to content
Snippets Groups Projects
Commit c36cf0d9 authored by Roman Khimin's avatar Roman Khimin Committed by Jonathan Sacksick
Browse files

Issue #3003273 by khiminrm, marchuk.vitaliy, rszrama, jsacksick: Add the...

Issue #3003273 by khiminrm, marchuk.vitaliy, rszrama, jsacksick: Add the ability to void an unsettled capture.
parent d1705186
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,9 @@ class ErrorHelper {
if (in_array($error->code, $hard_decline_codes)) {
throw new HardDeclineException($error->message, $error->code);
}
elseif ($error->code == 91506) {
throw new InvalidRequestException('Partial refunds will not be possible until the original transaction has settled. Please try again later.', $error->code);
}
else {
throw new InvalidRequestException($error->message, $error->code);
}
......
......@@ -317,6 +317,23 @@ class HostedFields extends OnsitePaymentGatewayBase implements HostedFieldsInter
$remote_id = $payment->getRemoteId();
$decimal_amount = $amount->getNumber();
$result = $this->api->transaction()->refund($remote_id, $decimal_amount);
if (!$result->success) {
$errors = $result->errors->deepAll();
$balance = $payment->getBalance();
if (!empty($errors) && $amount->equals($balance)) {
$error = reset($errors);
// Cannot refund transaction unless it is settled.
if ($error->code === '91506') {
$result = $this->api->transaction()->void($remote_id);
if ($result->success) {
$payment->setState('refunded');
$payment->setRefundedAmount($amount);
$payment->save();
return;
}
}
}
}
ErrorHelper::handleErrors($result);
}
catch (BraintreeException $e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment