diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 1c6ee81eba1a..b7ced5d34948 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -123,7 +123,7 @@ class InvoiceController extends Controller //format totals $formatted_total = Number::formatMoney($total, auth()->user()->client); - $payment_methods = auth()->user()->client->getPaymentMethods($total); + $payment_methods = auth()->user()->client->service()->getPaymentMethods($total); $data = [ 'settings' => auth()->user()->client->getMergedSettings(), diff --git a/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php b/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php index 6a4d06ab6297..059a26cf2a97 100644 --- a/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php +++ b/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php @@ -34,7 +34,6 @@ class UpdateTaskStatusRequest extends Request $rules = []; if ($this->input('name')) { - //$rules['name'] = 'unique:task_statuses,name,'.$this->id.',id,company_id,'.$this->task_status->company_id; $rules['name'] = Rule::unique('task_statuses')->where('company_id', auth()->user()->company()->id)->ignore($this->task_status->id); } diff --git a/app/Models/Client.php b/app/Models/Client.php index 6f079cd56860..09afcc4a86b5 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -433,6 +433,7 @@ class Client extends BaseModel implements HasLocalePreference * * @param float $amount The amount to be charged * @return array Array of payment labels and urls + * @deprecated 5.0.38 - see service()->getPaymentMethods($amount); */ public function getPaymentMethods($amount) :array { diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index 9ff8cb6c08c0..9023f3aa53c7 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -12,6 +12,7 @@ namespace App\Services\Client; use App\Models\Client; +use App\Services\Client\PaymentMethod; use App\Utils\Number; use Illuminate\Database\Eloquent\Collection; @@ -63,6 +64,10 @@ class ClientService ->sortBy('created_at'); } + public function getPaymentMethods(float $amount) + { + return (new PaymentMethod($this->client, $amount))->run(); + } public function save() :Client { diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index 35fe8de2f735..a2b0c3c70c3c 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -11,11 +11,8 @@ namespace App\Services\Client; -use App\DataMapper\InvoiceItem; -use App\Events\Invoice\InvoiceWasPaid; -use App\Events\Invoice\InvoiceWasUpdated; +use App\Models\Client; use App\Models\CompanyGateway; -use App\Models\Credit; use App\Models\GatewayType; use App\Models\Invoice; use App\Models\Payment; @@ -36,18 +33,21 @@ class PaymentMethod private $payment_urls = []; - public function __construct(Credit $client, float $amount) + public function __construct(Client $client, float $amount) { $this->client = $client; $this->amount = $amount; } - public function run() :Credit + public function run() { $this->getGateways() ->getMethods() ->buildUrls(); + + + return $this->getPaymentUrls(); } public function getPaymentUrls() @@ -59,7 +59,7 @@ class PaymentMethod { return $this->payment_methods; } - + private function getGateways() { @@ -131,12 +131,12 @@ class PaymentMethod { // we should prefilter $gateway->driver($this)->gatewayTypes() // and only include the enabled payment methods on the gateway - $this->$this->payment_methods = []; + $this->payment_methods = []; foreach ($this->gateways as $gateway) { - foreach ($gateway->driver($this)->gatewayTypes() as $type) { + foreach ($gateway->driver($this->client)->gatewayTypes() as $type) { if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) { - if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $amount)) { + if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $this->amount)) { $this->payment_methods[] = [$gateway->id => $type]; } } else { @@ -156,9 +156,9 @@ class PaymentMethod //note we have to use GatewayType::CREDIT_CARD as alias for CUSTOM foreach ($this->gateways as $gateway) { - foreach ($gateway->driver($this)->gatewayTypes() as $type) { + foreach ($gateway->driver($this->client)->gatewayTypes() as $type) { if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) { - if ($this->validGatewayForAmount($gateway->fees_and_limits->{GatewayType::CREDIT_CARD}, $amount)) { + if ($this->validGatewayForAmount($gateway->fees_and_limits->{GatewayType::CREDIT_CARD}, $this->amount)) { $this->payment_methods->push([$gateway->id => $type]); } } else { @@ -167,16 +167,17 @@ class PaymentMethod } } + return $this; } private function buildUrls() { - foreach ($payment_methods_intersect as $key => $child_array) { + foreach ($this->payment_methods as $key => $child_array) { foreach ($child_array as $gateway_id => $gateway_type_id) { $gateway = CompanyGateway::find($gateway_id); - $fee_label = $gateway->calcGatewayFeeLabel($amount, $this); + $fee_label = $gateway->calcGatewayFeeLabel($this->amount, $this->client); if(!$gateway_type_id){ @@ -201,7 +202,7 @@ class PaymentMethod // Show credits as only payment option if both statements are true. if ( - $this->client->service()->getCreditBalance() > $amount + $this->client->service()->getCreditBalance() > $this->amount && $this->client->getSetting('use_credits_payment') == 'always') { $payment_urls = []; } @@ -225,11 +226,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 && $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) { return false; } - if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $fees_and_limits->max_limit != -1 && $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) { return false; }