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 $customerReferenceParam;
protected $transactionReferenceParam; protected $transactionReferenceParam;
public $canRefundPayments = false;
public function __construct($accountGateway = false, $invitation = false, $gatewayType = false) public function __construct($accountGateway = false, $invitation = false, $gatewayType = false)
{ {
$this->accountGateway = $accountGateway; $this->accountGateway = $accountGateway;

View File

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

View File

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

View File

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

View File

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