Better refund handling

This commit is contained in:
Joshua Dwire 2016-05-14 23:03:39 -04:00
parent 65feee34e3
commit 919aec2192
3 changed files with 65 additions and 30 deletions

View File

@ -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
); );
} }
} }

View File

@ -1048,6 +1048,8 @@ 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);
if ($accountGateway->gateway_id != GATEWAY_WEPAY) {
$refund = $gateway->refund(array( $refund = $gateway->refund(array(
'transactionReference' => $payment->transaction_reference, 'transactionReference' => $payment->transaction_reference,
'amount' => $amount, 'amount' => $amount,
@ -1084,6 +1086,39 @@ class PaymentService extends BaseService
return false; 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 { } else {
$payment->recordRefund($amount); $payment->recordRefund($amount);
} }

View File

@ -26,7 +26,7 @@
&nbsp;<label for="trashed" style="font-weight:normal; margin-left: 10px;"> &nbsp;<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' : ''}}/>&nbsp; {{ trans('texts.show_archived_deleted')}} {{ Utils::transFlowText($entityType.'s') }} {{ Session::get("show_trash:{$entityType}") ? 'checked' : ''}}/>&nbsp; {{ 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"