From 8e3ccc83ad1d78af4f1123515324e0f6d4d83493 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 18 May 2022 08:47:54 +1000 Subject: [PATCH] Fixes for displaying payment gateways where min_limit is enforced --- app/Http/Livewire/InvoicesTable.php | 2 +- .../PaymentMethod/CreatePaymentMethodRequest.php | 2 +- app/Models/Client.php | 4 ++-- app/Models/Company.php | 1 + app/Services/Client/PaymentMethod.php | 12 +++++------- app/Services/PdfMaker/Design.php | 3 +++ app/Transformers/CompanyTransformer.php | 2 ++ ..._224917_add_auto_bill_tries_to_invoices_table.php | 1 + 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/Http/Livewire/InvoicesTable.php b/app/Http/Livewire/InvoicesTable.php index 6671ca82de..e31bfee86a 100644 --- a/app/Http/Livewire/InvoicesTable.php +++ b/app/Http/Livewire/InvoicesTable.php @@ -83,7 +83,7 @@ class InvoicesTable extends Component return render('components.livewire.invoices-table', [ 'invoices' => $query, - 'gateway_available' => !empty(auth()->user()->client->service()->getPaymentMethods(0)), + 'gateway_available' => !empty(auth()->user()->client->service()->getPaymentMethods(-1)), ]); } } diff --git a/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php b/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php index b3da292939..f94d207142 100644 --- a/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php +++ b/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php @@ -22,7 +22,7 @@ class CreatePaymentMethodRequest extends FormRequest $available_methods = []; - collect($client->service()->getPaymentMethods(1)) + collect($client->service()->getPaymentMethods(-1)) ->filter(function ($method) use (&$available_methods) { $available_methods[] = $method['gateway_type_id']; }); diff --git a/app/Models/Client.php b/app/Models/Client.php index 199cf9fbd4..8e692393db 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -432,7 +432,7 @@ class Client extends BaseModel implements HasLocalePreference public function getCreditCardGateway() :?CompanyGateway { - $pms = $this->service()->getPaymentMethods(0); + $pms = $this->service()->getPaymentMethods(-1); foreach($pms as $pm) { @@ -462,7 +462,7 @@ class Client extends BaseModel implements HasLocalePreference //todo refactor this - it is only searching for existing tokens public function getBankTransferGateway() :?CompanyGateway { - $pms = $this->service()->getPaymentMethods(0); + $pms = $this->service()->getPaymentMethods(-1); if($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, array_column($pms, 'gateway_type_id'))){ diff --git a/app/Models/Company.php b/app/Models/Company.php index 40300ae897..64b4a712e2 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -102,6 +102,7 @@ class Company extends BaseModel 'markdown_email_enabled', 'stop_on_unpaid_recurring', 'use_quote_terms_on_conversion', + 'show_production_description_dropdown', ]; protected $hidden = [ diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index ef4eae67ed..7af4d6155e 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -132,8 +132,7 @@ class PaymentMethod private function getMethods() { - // we should prefilter $gateway->driver($this)->gatewayTypes() - // and only include the enabled payment methods on the gateway + $this->payment_methods = []; foreach ($this->gateways as $gateway) { @@ -148,13 +147,12 @@ class PaymentMethod if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $this->amount) && $gateway->fees_and_limits->{$type}->is_enabled) { - // if($type == GatewayType::BANK_TRANSFER); - $this->payment_methods[] = [$gateway->id => $type]; + } } else { - //$this->payment_methods[] = [$gateway->id => $type]; + } } } @@ -243,11 +241,11 @@ class PaymentMethod return true; } - if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $fees_and_limits->min_limit != -1 && $this->amount < $fees_and_limits->min_limit) { + if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $fees_and_limits->min_limit != -1 && ($this->amount < $fees_and_limits->min_limit && $this->amount != -1)) { return false; } - if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $fees_and_limits->max_limit != -1 && $this->amount > $fees_and_limits->max_limit) { + if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $fees_and_limits->max_limit != -1 && ($this->amount > $fees_and_limits->max_limit && $this->amount != -1)) { return false; } diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 05dab3c75d..01692d5ae2 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -453,6 +453,9 @@ class Design extends BaseDesign foreach ($this->invoices as $invoice) { foreach ($invoice->payments as $payment) { + if($payment->is_deleted) + continue; + $element = ['element' => 'tr', 'elements' => []]; $element['elements'][] = ['element' => 'td', 'content' => $invoice->number]; diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 3bc05c684e..549365f4a4 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -169,6 +169,8 @@ class CompanyTransformer extends EntityTransformer 'convert_rate_to_client' => (bool) $company->convert_rate_to_client, 'markdown_email_enabled' => (bool) $company->markdown_email_enabled, 'stop_on_unpaid_recurring' => (bool) $company->stop_on_unpaid_recurring, + 'show_production_description_dropdown' => (bool)$company->show_production_description_dropdown, + 'use_quote_terms_on_conversion' => (bool) $company->use_quote_terms_on_conversion, ]; } diff --git a/database/migrations/2022_05_16_224917_add_auto_bill_tries_to_invoices_table.php b/database/migrations/2022_05_16_224917_add_auto_bill_tries_to_invoices_table.php index 5d57b04687..01d4c313c6 100644 --- a/database/migrations/2022_05_16_224917_add_auto_bill_tries_to_invoices_table.php +++ b/database/migrations/2022_05_16_224917_add_auto_bill_tries_to_invoices_table.php @@ -20,6 +20,7 @@ class AddAutoBillTriesToInvoicesTable extends Migration Schema::table('companies', function (Blueprint $table) { $table->boolean('stop_on_unpaid_recurring')->default(0); $table->boolean('use_quote_terms_on_conversion')->default(0); + $table->boolean('show_production_description_dropdown')->default(0); }); }