1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Check gateway supports refunding payment

This commit is contained in:
Hillel Coren 2017-05-16 12:20:35 +03:00
parent 48d22a48bf
commit 8f43eb02b3
5 changed files with 9 additions and 0 deletions

View File

@ -38,6 +38,8 @@ class BasePaymentDriver
protected $customerReferenceParam;
protected $transactionReferenceParam;
public $canRefundPayments = false;
public function __construct($accountGateway = false, $invitation = false, $gatewayType = false)
{
$this->accountGateway = $accountGateway;

View File

@ -11,6 +11,7 @@ class BraintreePaymentDriver extends BasePaymentDriver
{
protected $customerReferenceParam = 'customerId';
protected $sourceReferenceParam = 'paymentMethodToken';
public $canRefundPayments = true;
public function gatewayTypes()
{

View File

@ -10,6 +10,7 @@ use Exception;
class StripePaymentDriver extends BasePaymentDriver
{
protected $customerReferenceParam = 'customerReference';
public $canRefundPayments = true;
public function gatewayTypes()
{

View File

@ -10,6 +10,8 @@ use Utils;
class WePayPaymentDriver extends BasePaymentDriver
{
public $canRefundPayments = true;
public function gatewayTypes()
{
$types = [

View File

@ -178,8 +178,11 @@ class PaymentService extends BaseService
foreach ($payments as $payment) {
if (Auth::user()->can('edit', $payment)) {
$amount = ! empty($params['refund_amount']) ? floatval($params['refund_amount']) : null;
$paymentDriver = false;
if ($accountGateway = $payment->account_gateway) {
$paymentDriver = $accountGateway->paymentDriver();
}
if ($paymentDriver && $paymentDriver->canRefundPayments) {
if ($paymentDriver->refundPayment($payment, $amount)) {
$successful++;
}