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(
|
||||
$payment,
|
||||
ACTIVITY_TYPE_DELETE_PAYMENT,
|
||||
$payment->amount,
|
||||
$payment->amount * -1
|
||||
$payment->amount - $payment->refunded,
|
||||
($payment->amount - $payment->refunded) * -1
|
||||
);
|
||||
}
|
||||
|
||||
@ -343,8 +343,8 @@ class ActivityListener
|
||||
$this->activityRepo->create(
|
||||
$payment,
|
||||
ACTIVITY_TYPE_FAILED_PAYMENT,
|
||||
$payment->amount,
|
||||
$payment->amount * -1
|
||||
($payment->amount - $payment->refunded),
|
||||
($payment->amount - $payment->refunded) * -1
|
||||
);
|
||||
}
|
||||
|
||||
@ -367,8 +367,8 @@ class ActivityListener
|
||||
$this->activityRepo->create(
|
||||
$payment,
|
||||
ACTIVITY_TYPE_RESTORE_PAYMENT,
|
||||
$event->fromDeleted ? $payment->amount * -1 : 0,
|
||||
$event->fromDeleted ? $payment->amount : 0
|
||||
$event->fromDeleted ? ($payment->amount - $payment->refunded) * -1 : 0,
|
||||
$event->fromDeleted ? ($payment->amount - $payment->refunded) : 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1048,6 +1048,8 @@ class PaymentService extends BaseService
|
||||
|
||||
if ($payment->payment_type_id != PAYMENT_TYPE_CREDIT) {
|
||||
$gateway = $this->createGateway($accountGateway);
|
||||
|
||||
if ($accountGateway->gateway_id != GATEWAY_WEPAY) {
|
||||
$refund = $gateway->refund(array(
|
||||
'transactionReference' => $payment->transaction_reference,
|
||||
'amount' => $amount,
|
||||
@ -1084,6 +1086,39 @@ class PaymentService extends BaseService
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$wepay = \Utils::setupWePay($accountGateway);
|
||||
|
||||
try {
|
||||
$wepay->request('checkout/refund', array(
|
||||
'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) {
|
||||
try {
|
||||
// This is an uncaptured transaction; try to cancel it
|
||||
$wepay->request('checkout/cancel', array(
|
||||
'checkout_id' => intval($payment->transaction_reference),
|
||||
'cancel_reason' => 'Refund issued by merchant.',
|
||||
));
|
||||
$payment->markVoided();
|
||||
} catch (\WePayException $ex) {
|
||||
$this->error('Unknown', $ex->getMessage(), $accountGateway);
|
||||
}
|
||||
} else {
|
||||
$this->error('Unknown', 'Partial refund not allowed for unsettled transactions.', $accountGateway);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->error('Unknown', $ex->getMessage(), $accountGateway);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$payment->recordRefund($amount);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
<label for="trashed" style="font-weight:normal; margin-left: 10px;">
|
||||
<input id="trashed" type="checkbox" onclick="setTrashVisible()"
|
||||
{{ 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">
|
||||
<input id="tableFilter" type="text" style="width:140px;margin-right:17px;background-color: white !important"
|
||||
|
Loading…
x
Reference in New Issue
Block a user