mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Better refund handling
This commit is contained in:
parent
65feee34e3
commit
919aec2192
@ -307,8 +307,8 @@ class ActivityListener
|
|||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$payment,
|
$payment,
|
||||||
ACTIVITY_TYPE_DELETE_PAYMENT,
|
ACTIVITY_TYPE_DELETE_PAYMENT,
|
||||||
$payment->amount,
|
$payment->amount - $payment->refunded,
|
||||||
$payment->amount * -1
|
($payment->amount - $payment->refunded) * -1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,8 +343,8 @@ class ActivityListener
|
|||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$payment,
|
$payment,
|
||||||
ACTIVITY_TYPE_FAILED_PAYMENT,
|
ACTIVITY_TYPE_FAILED_PAYMENT,
|
||||||
$payment->amount,
|
($payment->amount - $payment->refunded),
|
||||||
$payment->amount * -1
|
($payment->amount - $payment->refunded) * -1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,8 +367,8 @@ class ActivityListener
|
|||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$payment,
|
$payment,
|
||||||
ACTIVITY_TYPE_RESTORE_PAYMENT,
|
ACTIVITY_TYPE_RESTORE_PAYMENT,
|
||||||
$event->fromDeleted ? $payment->amount * -1 : 0,
|
$event->fromDeleted ? ($payment->amount - $payment->refunded) * -1 : 0,
|
||||||
$event->fromDeleted ? $payment->amount : 0
|
$event->fromDeleted ? ($payment->amount - $payment->refunded) : 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1048,41 +1048,76 @@ class PaymentService extends BaseService
|
|||||||
|
|
||||||
if ($payment->payment_type_id != PAYMENT_TYPE_CREDIT) {
|
if ($payment->payment_type_id != PAYMENT_TYPE_CREDIT) {
|
||||||
$gateway = $this->createGateway($accountGateway);
|
$gateway = $this->createGateway($accountGateway);
|
||||||
$refund = $gateway->refund(array(
|
|
||||||
'transactionReference' => $payment->transaction_reference,
|
if ($accountGateway->gateway_id != GATEWAY_WEPAY) {
|
||||||
'amount' => $amount,
|
$refund = $gateway->refund(array(
|
||||||
));
|
'transactionReference' => $payment->transaction_reference,
|
||||||
$response = $refund->send();
|
'amount' => $amount,
|
||||||
|
));
|
||||||
if ($response->isSuccessful()) {
|
$response = $refund->send();
|
||||||
$payment->recordRefund($amount);
|
|
||||||
|
if ($response->isSuccessful()) {
|
||||||
|
$payment->recordRefund($amount);
|
||||||
|
} else {
|
||||||
|
$data = $response->getData();
|
||||||
|
|
||||||
|
if ($data instanceof \Braintree\Result\Error) {
|
||||||
|
$error = $data->errors->deepAll()[0];
|
||||||
|
if ($error && $error->code == 91506) {
|
||||||
|
if ($amount == $payment->amount) {
|
||||||
|
// This is an unsettled transaction; try to void it
|
||||||
|
$void = $gateway->void(array(
|
||||||
|
'transactionReference' => $payment->transaction_reference,
|
||||||
|
));
|
||||||
|
$response = $void->send();
|
||||||
|
|
||||||
|
if ($response->isSuccessful()) {
|
||||||
|
$payment->markVoided();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->error('Unknown', 'Partial refund not allowed for unsettled transactions.', $accountGateway);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$response->isSuccessful()) {
|
||||||
|
$this->error('Unknown', $response->getMessage(), $accountGateway);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$data = $response->getData();
|
$wepay = \Utils::setupWePay($accountGateway);
|
||||||
|
|
||||||
if ($data instanceof \Braintree\Result\Error) {
|
try {
|
||||||
$error = $data->errors->deepAll()[0];
|
$wepay->request('checkout/refund', array(
|
||||||
if ($error && $error->code == 91506) {
|
'checkout_id' => intval($payment->transaction_reference),
|
||||||
|
'refund_reason' => 'Refund issued by merchant.',
|
||||||
|
'amount' => $amount,
|
||||||
|
));
|
||||||
|
$payment->recordRefund($amount);
|
||||||
|
} catch (\WePayException $ex) {
|
||||||
|
if ($ex->getCode() == 4004) {
|
||||||
if ($amount == $payment->amount) {
|
if ($amount == $payment->amount) {
|
||||||
// This is an unsettled transaction; try to void it
|
try {
|
||||||
$void = $gateway->void(array(
|
// This is an uncaptured transaction; try to cancel it
|
||||||
'transactionReference' => $payment->transaction_reference,
|
$wepay->request('checkout/cancel', array(
|
||||||
));
|
'checkout_id' => intval($payment->transaction_reference),
|
||||||
$response = $void->send();
|
'cancel_reason' => 'Refund issued by merchant.',
|
||||||
|
));
|
||||||
if ($response->isSuccessful()) {
|
|
||||||
$payment->markVoided();
|
$payment->markVoided();
|
||||||
|
} catch (\WePayException $ex) {
|
||||||
|
$this->error('Unknown', $ex->getMessage(), $accountGateway);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->error('Unknown', 'Partial refund not allowed for unsettled transactions.', $accountGateway);
|
$this->error('Unknown', 'Partial refund not allowed for unsettled transactions.', $accountGateway);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$this->error('Unknown', $ex->getMessage(), $accountGateway);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$response->isSuccessful()) {
|
|
||||||
$this->error('Unknown', $response->getMessage(), $accountGateway);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$payment->recordRefund($amount);
|
$payment->recordRefund($amount);
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<label for="trashed" style="font-weight:normal; margin-left: 10px;">
|
<label for="trashed" style="font-weight:normal; margin-left: 10px;">
|
||||||
<input id="trashed" type="checkbox" onclick="setTrashVisible()"
|
<input id="trashed" type="checkbox" onclick="setTrashVisible()"
|
||||||
{{ Session::get("show_trash:{$entityType}") ? 'checked' : ''}}/> {{ trans('texts.show_archived_deleted')}} {{ Utils::transFlowText($entityType.'s') }}
|
{{ Session::get("show_trash:{$entityType}") ? 'checked' : ''}}/> {{ trans('texts.show_archived_deleted')}} {{ Utils::transFlowText($entityType.'s') }}
|
||||||
</label>-onli
|
</label>
|
||||||
|
|
||||||
<div id="top_right_buttons" class="pull-right">
|
<div id="top_right_buttons" class="pull-right">
|
||||||
<input id="tableFilter" type="text" style="width:140px;margin-right:17px;background-color: white !important"
|
<input id="tableFilter" type="text" style="width:140px;margin-right:17px;background-color: white !important"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user