mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improve check for duplicate gateways
This commit is contained in:
parent
dcdfb4f21c
commit
93c3521952
@ -101,8 +101,9 @@ class AccountGatewayController extends BaseController
|
|||||||
$data['title'] = trans('texts.add_gateway');
|
$data['title'] = trans('texts.add_gateway');
|
||||||
|
|
||||||
if ($otherProviders) {
|
if ($otherProviders) {
|
||||||
$data['primaryGateways'] = Gateway::primary($accountGatewaysIds)->orderBy('name', 'desc')->get();
|
$availableGatewaysIds = $account->availableGatewaysIds();
|
||||||
$data['secondaryGateways'] = Gateway::secondary($accountGatewaysIds)->orderBy('name')->get();
|
$data['primaryGateways'] = Gateway::primary($availableGatewaysIds)->orderBy('name', 'desc')->get();
|
||||||
|
$data['secondaryGateways'] = Gateway::secondary($availableGatewaysIds)->orderBy('name')->get();
|
||||||
$data['hiddenFields'] = Gateway::$hiddenFields;
|
$data['hiddenFields'] = Gateway::$hiddenFields;
|
||||||
|
|
||||||
return View::make('accounts.account_gateway', $data);
|
return View::make('accounts.account_gateway', $data);
|
||||||
|
@ -9,6 +9,7 @@ use Cache;
|
|||||||
use App;
|
use App;
|
||||||
use File;
|
use File;
|
||||||
use App\Models\Document;
|
use App\Models\Document;
|
||||||
|
use App\Models\AccountGateway;
|
||||||
use App\Events\UserSettingsChanged;
|
use App\Events\UserSettingsChanged;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
@ -418,6 +419,39 @@ class Account extends Eloquent
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function availableGatewaysIds()
|
||||||
|
{
|
||||||
|
if ( ! $this->relationLoaded('account_gateways')) {
|
||||||
|
$this->load('account_gateways');
|
||||||
|
}
|
||||||
|
|
||||||
|
$gatewayTypes = [];
|
||||||
|
$gatewayIds = [];
|
||||||
|
|
||||||
|
foreach ($this->account_gateways as $accountGateway) {
|
||||||
|
$paymentDriver = $accountGateway->paymentDriver();
|
||||||
|
$gatewayTypes = array_unique(array_merge($gatewayTypes, $paymentDriver->gatewayTypes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Cache::get('gateways') as $gateway) {
|
||||||
|
$paymentDriverClass = AccountGateway::paymentDriverClass($gateway->provider);
|
||||||
|
$paymentDriver = new $paymentDriverClass();
|
||||||
|
$available = true;
|
||||||
|
|
||||||
|
foreach ($gatewayTypes as $type) {
|
||||||
|
if ($paymentDriver->handles($type)) {
|
||||||
|
$available = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($available) {
|
||||||
|
$gatewayIds[] = $gateway->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $gatewayIds;
|
||||||
|
}
|
||||||
|
|
||||||
public function paymentDriver($invitation = false, $gatewayType = false)
|
public function paymentDriver($invitation = false, $gatewayType = false)
|
||||||
{
|
{
|
||||||
if ($accountGateway = $this->getGatewayByType($gatewayType)) {
|
if ($accountGateway = $this->getGatewayByType($gatewayType)) {
|
||||||
|
@ -37,20 +37,26 @@ class AccountGateway extends EntityModel
|
|||||||
return $arrayOfImages;
|
return $arrayOfImages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function paymentDriver($invitation = false, $gatewayType = false)
|
public static function paymentDriverClass($provider)
|
||||||
{
|
{
|
||||||
$folder = "App\\Ninja\\PaymentDrivers\\";
|
$folder = "App\\Ninja\\PaymentDrivers\\";
|
||||||
$class = $folder . $this->gateway->provider . 'PaymentDriver';
|
$class = $folder . $provider . 'PaymentDriver';
|
||||||
$class = str_replace('_', '', $class);
|
$class = str_replace('_', '', $class);
|
||||||
|
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
return new $class($this, $invitation, $gatewayType);
|
return $class;
|
||||||
} else {
|
} else {
|
||||||
$baseClass = $folder . "BasePaymentDriver";
|
return $folder . "BasePaymentDriver";
|
||||||
return new $baseClass($this, $invitation, $gatewayType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function paymentDriver($invitation = false, $gatewayType = false)
|
||||||
|
{
|
||||||
|
$class = static::paymentDriverClass($this->gateway->provider);
|
||||||
|
|
||||||
|
return new $class($this, $invitation, $gatewayType);
|
||||||
|
}
|
||||||
|
|
||||||
public function isGateway($gatewayId)
|
public function isGateway($gatewayId)
|
||||||
{
|
{
|
||||||
return $this->gateway_id == $gatewayId;
|
return $this->gateway_id == $gatewayId;
|
||||||
|
@ -25,6 +25,8 @@ class Gateway extends Eloquent
|
|||||||
GATEWAY_DWOLLA,
|
GATEWAY_DWOLLA,
|
||||||
GATEWAY_STRIPE,
|
GATEWAY_STRIPE,
|
||||||
GATEWAY_BRAINTREE,
|
GATEWAY_BRAINTREE,
|
||||||
|
GATEWAY_AUTHORIZE_NET,
|
||||||
|
GATEWAY_MOLLIE,
|
||||||
];
|
];
|
||||||
|
|
||||||
// allow adding these gateway if another gateway
|
// allow adding these gateway if another gateway
|
||||||
@ -81,25 +83,16 @@ class Gateway extends Eloquent
|
|||||||
{
|
{
|
||||||
$query->where('payment_library_id', '=', 1)
|
$query->where('payment_library_id', '=', 1)
|
||||||
->where('id', '!=', GATEWAY_WEPAY)
|
->where('id', '!=', GATEWAY_WEPAY)
|
||||||
->whereIn('id', Gateway::$preferred)
|
->whereIn('id', static::$preferred)
|
||||||
->whereNotIn('id', $accountGatewaysIds);
|
->whereIn('id', $accountGatewaysIds);
|
||||||
|
|
||||||
// if the user has a credit card gateway only show alternate options
|
|
||||||
if (static::hasStandardGateway($accountGatewaysIds)) {
|
|
||||||
$query->whereNotIn('id', array_diff(static::$preferred, static::$alternate));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSecondary($query, $accountGatewaysIds)
|
public function scopeSecondary($query, $accountGatewaysIds)
|
||||||
{
|
{
|
||||||
// if the user has a credit card don't show an secondary options
|
$query->where('payment_library_id', '=', 1)
|
||||||
if (static::hasStandardGateway($accountGatewaysIds)) {
|
->where('id', '!=', GATEWAY_WEPAY)
|
||||||
$query->where('id', '=', 0);
|
->whereNotIn('id', static::$preferred)
|
||||||
} else {
|
->whereIn('id', $accountGatewaysIds);
|
||||||
$query->where('payment_library_id', '=', 1)
|
|
||||||
->where('id', '!=', GATEWAY_WEPAY)
|
|
||||||
->whereNotIn('id', static::$preferred);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHelp()
|
public function getHelp()
|
||||||
|
@ -30,7 +30,7 @@ class BasePaymentDriver
|
|||||||
protected $customerReferenceParam;
|
protected $customerReferenceParam;
|
||||||
protected $transactionReferenceParam;
|
protected $transactionReferenceParam;
|
||||||
|
|
||||||
public function __construct($accountGateway, $invitation = false, $gatewayType = false)
|
public function __construct($accountGateway = false, $invitation = false, $gatewayType = false)
|
||||||
{
|
{
|
||||||
$this->accountGateway = $accountGateway;
|
$this->accountGateway = $accountGateway;
|
||||||
$this->invitation = $invitation;
|
$this->invitation = $invitation;
|
||||||
@ -47,7 +47,7 @@ class BasePaymentDriver
|
|||||||
return $this->gatewayType === $gatewayType;
|
return $this->gatewayType === $gatewayType;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
GATEWAY_TYPE_CREDIT_CARD
|
GATEWAY_TYPE_CREDIT_CARD
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class BitPayPaymentDriver extends BasePaymentDriver
|
class BitPayPaymentDriver extends BasePaymentDriver
|
||||||
{
|
{
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
GATEWAY_TYPE_BITCOIN
|
GATEWAY_TYPE_BITCOIN
|
||||||
|
@ -9,14 +9,14 @@ class BraintreePaymentDriver extends BasePaymentDriver
|
|||||||
protected $customerReferenceParam = 'customerId';
|
protected $customerReferenceParam = 'customerId';
|
||||||
protected $sourceReferenceParam = 'paymentMethodToken';
|
protected $sourceReferenceParam = 'paymentMethodToken';
|
||||||
|
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
$types = [
|
$types = [
|
||||||
GATEWAY_TYPE_CREDIT_CARD,
|
GATEWAY_TYPE_CREDIT_CARD,
|
||||||
GATEWAY_TYPE_TOKEN,
|
GATEWAY_TYPE_TOKEN,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->accountGateway->getPayPalEnabled()) {
|
if ($this->accountGateway && $this->accountGateway->getPayPalEnabled()) {
|
||||||
$types[] = GATEWAY_TYPE_PAYPAL;
|
$types[] = GATEWAY_TYPE_PAYPAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class DwollaPaymentDriver extends BasePaymentDriver
|
class DwollaPaymentDriver extends BasePaymentDriver
|
||||||
{
|
{
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
return [GATEWAY_TYPE_DWOLLA];
|
return [GATEWAY_TYPE_DWOLLA];
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use Exception;
|
|||||||
|
|
||||||
class PayPalExpressPaymentDriver extends BasePaymentDriver
|
class PayPalExpressPaymentDriver extends BasePaymentDriver
|
||||||
{
|
{
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
GATEWAY_TYPE_PAYPAL
|
GATEWAY_TYPE_PAYPAL
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class PayPalProPaymentDriver extends BasePaymentDriver
|
class PayPalProPaymentDriver extends BasePaymentDriver
|
||||||
{
|
{
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
GATEWAY_TYPE_CREDIT_CARD
|
GATEWAY_TYPE_CREDIT_CARD
|
||||||
|
@ -8,14 +8,14 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
{
|
{
|
||||||
protected $customerReferenceParam = 'customerReference';
|
protected $customerReferenceParam = 'customerReference';
|
||||||
|
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
$types = [
|
$types = [
|
||||||
GATEWAY_TYPE_CREDIT_CARD,
|
GATEWAY_TYPE_CREDIT_CARD,
|
||||||
GATEWAY_TYPE_TOKEN
|
GATEWAY_TYPE_TOKEN
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->accountGateway->getAchEnabled()) {
|
if ($this->accountGateway && $this->accountGateway->getAchEnabled()) {
|
||||||
$types[] = GATEWAY_TYPE_BANK_TRANSFER;
|
$types[] = GATEWAY_TYPE_BANK_TRANSFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,13 +6,18 @@ use Exception;
|
|||||||
|
|
||||||
class WePayPaymentDriver extends BasePaymentDriver
|
class WePayPaymentDriver extends BasePaymentDriver
|
||||||
{
|
{
|
||||||
protected function gatewayTypes()
|
public function gatewayTypes()
|
||||||
{
|
{
|
||||||
return [
|
$types = [
|
||||||
GATEWAY_TYPE_CREDIT_CARD,
|
GATEWAY_TYPE_CREDIT_CARD,
|
||||||
GATEWAY_TYPE_BANK_TRANSFER,
|
|
||||||
GATEWAY_TYPE_TOKEN
|
GATEWAY_TYPE_TOKEN
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($this->accountGateway && $this->accountGateway->getAchEnabled()) {
|
||||||
|
$types[] = GATEWAY_TYPE_BANK_TRANSFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user