mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 13:04:30 -04:00
Restrict payments based on gateway type limits
This commit is contained in:
parent
3c4ad52463
commit
ca71ea5622
@ -173,8 +173,8 @@ class ClientPortalController extends BaseController
|
||||
|
||||
foreach ($account->account_gateways as $accountGateway) {
|
||||
$paymentDriver = $accountGateway->paymentDriver($invitation);
|
||||
$links = array_merge($links, $paymentDriver->tokenLinks());
|
||||
$links = array_merge($links, $paymentDriver->paymentLinks());
|
||||
$links = array_merge($links, $paymentDriver->tokenLinks($invitation->invoice));
|
||||
$links = array_merge($links, $paymentDriver->paymentLinks($invitation->invoice));
|
||||
}
|
||||
|
||||
return $links;
|
||||
|
@ -11,4 +11,12 @@ class PaymentType extends Eloquent
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function gatewayType()
|
||||
{
|
||||
return $this->belongsTo('App\Models\GatewayType');
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,14 @@
|
||||
|
||||
use URL;
|
||||
use Session;
|
||||
use Utils;
|
||||
use Request;
|
||||
use Omnipay;
|
||||
use Exception;
|
||||
use CreditCard;
|
||||
use DateTime;
|
||||
use App\Models\AccountGatewayToken;
|
||||
use App\Models\AccountGatewaySettings;
|
||||
use App\Models\Account;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentMethod;
|
||||
@ -733,7 +735,7 @@ class BasePaymentDriver
|
||||
return $this->createPayment($ref);
|
||||
}
|
||||
|
||||
public function tokenLinks()
|
||||
public function tokenLinks($invoice)
|
||||
{
|
||||
if ( ! $this->customer()) {
|
||||
return [];
|
||||
@ -747,6 +749,10 @@ class BasePaymentDriver
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !$this->invoiceMeetsGatewayTypeLimits($invoice, $paymentMethod->payment_type->gateway_type_id) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = URL::to("/payment/{$this->invitation->invitation_key}/token/".$paymentMethod->public_id);
|
||||
|
||||
if ($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) {
|
||||
@ -770,24 +776,51 @@ class BasePaymentDriver
|
||||
return $links;
|
||||
}
|
||||
|
||||
public function paymentLinks()
|
||||
public function paymentLinks($invoice)
|
||||
{
|
||||
$links = [];
|
||||
|
||||
foreach ($this->gatewayTypes() as $gatewayType) {
|
||||
if ($gatewayType === GATEWAY_TYPE_TOKEN) {
|
||||
foreach ($this->gatewayTypes() as $gatewayTypeId) {
|
||||
if ($gatewayTypeId === GATEWAY_TYPE_TOKEN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !$this->invoiceMeetsGatewayTypeLimits($invoice, $gatewayTypeId) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$links[] = [
|
||||
'url' => $this->paymentUrl($gatewayType),
|
||||
'label' => trans("texts.{$gatewayType}")
|
||||
'url' => $this->paymentUrl($gatewayTypeId),
|
||||
'label' => trans("texts.{$gatewayTypeId}")
|
||||
];
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
protected function invoiceMeetsGatewayTypeLimits( $invoice, $gatewayTypeId ) {
|
||||
if ( !$gatewayTypeId ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$accountGatewaySettings = AccountGatewaySettings::scope()->where('account_gateway_settings.gateway_type_id',
|
||||
'=', $gatewayTypeId)->first();
|
||||
|
||||
if ($accountGatewaySettings) {
|
||||
if ($accountGatewaySettings->min_limit && $invoice->balance < $accountGatewaySettings->min_limit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($accountGatewaySettings->max_limit && $invoice->balance >= $accountGatewaySettings->max_limit + 1) {
|
||||
// The max is limit_max + 0.99, so we add 1 to max_limit
|
||||
// Then, if the balance is greater than or equal to that value, it's over the max.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function paymentUrl($gatewayType)
|
||||
{
|
||||
$account = $this->account();
|
||||
|
Loading…
x
Reference in New Issue
Block a user