From 0a4d00158cd8bb6c8713f004d5507f4771b302b6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 29 Sep 2024 16:52:34 +1000 Subject: [PATCH] null safety not required --- .../GoCardlessOAuthWebhookController.php | 2 +- app/Models/CompanyGateway.php | 10 +--------- app/PaymentDrivers/BaseDriver.php | 2 +- app/PaymentDrivers/GoCardless/DirectDebit.php | 2 +- app/PaymentDrivers/GoCardless/SEPA.php | 2 +- app/Services/Client/PaymentMethod.php | 2 +- app/Services/Invoice/AddGatewayFee.php | 4 +--- app/Services/Invoice/InvoiceService.php | 20 +++++++++++++------ 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/Gateways/GoCardlessOAuthWebhookController.php b/app/Http/Controllers/Gateways/GoCardlessOAuthWebhookController.php index 0d91a288225f..e9ccbc2fbc89 100644 --- a/app/Http/Controllers/Gateways/GoCardlessOAuthWebhookController.php +++ b/app/Http/Controllers/Gateways/GoCardlessOAuthWebhookController.php @@ -39,7 +39,7 @@ class GoCardlessOAuthWebhookController extends Controller ->whereJsonContains('config->account_id', $e['links.organisation']) ->firstOrFail(); - $current = $company_gateway->getConfig('__current'); + $current = $company_gateway->getConfigField('__current'); if ($current) { $company_gateway->setConfig($current); diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index adfaad5f00f1..ba7eaaaecf85 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -425,7 +425,6 @@ class CompanyGateway extends BaseModel $fee = 0; - if ($fees_and_limits->adjust_fee_percent ?? false) { $adjusted_fee = 0; @@ -452,11 +451,7 @@ class CompanyGateway extends BaseModel } else { $fee += round(($amount * $fees_and_limits->fee_percent / 100), 2); } - //elseif ($fees_and_limits->adjust_fee_percent) { - // $fee += round(($amount / (1 - $fees_and_limits->fee_percent / 100) - $amount), 2); - //} else { - - //} + } } /* Cap fee if we have to here. */ @@ -470,17 +465,14 @@ class CompanyGateway extends BaseModel if ($include_taxes) { if ($fees_and_limits->fee_tax_rate1) { $fee += round(($pre_tax_fee * $fees_and_limits->fee_tax_rate1 / 100), 2); - // info("fee after adding fee tax 1 = {$fee}"); } if ($fees_and_limits->fee_tax_rate2) { $fee += round(($pre_tax_fee * $fees_and_limits->fee_tax_rate2 / 100), 2); - // info("fee after adding fee tax 2 = {$fee}"); } if ($fees_and_limits->fee_tax_rate3) { $fee += round(($pre_tax_fee * $fees_and_limits->fee_tax_rate3 / 100), 2); - // info("fee after adding fee tax 3 = {$fee}"); } } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 23f7a81545f9..d06f33427ea0 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -456,7 +456,7 @@ class BaseDriver extends AbstractPaymentDriver $invoice ->ledger() - ->updateInvoiceBalance($adjustment, 'Adjustment for adding gateway fee'); + ->updateInvoiceBalance($adjustment, 'Adjustment for adding gateway fee **Base Driver**'); $invoice->client->service()->calculateBalance(); } diff --git a/app/PaymentDrivers/GoCardless/DirectDebit.php b/app/PaymentDrivers/GoCardless/DirectDebit.php index 515aef5451e0..8789f48516b3 100644 --- a/app/PaymentDrivers/GoCardless/DirectDebit.php +++ b/app/PaymentDrivers/GoCardless/DirectDebit.php @@ -96,7 +96,7 @@ class DirectDebit implements MethodInterface, LivewireMethodInterface 'session_token' => $session_token, 'billing_request' => $response->id, 'authorize_then_redirect' => true, - 'payment_hash' => $this->go_cardless->payment_hash?->hash, + 'payment_hash' => $this->go_cardless->payment_hash->hash, ]), "exit_uri" => $exit_uri, "links" => [ diff --git a/app/PaymentDrivers/GoCardless/SEPA.php b/app/PaymentDrivers/GoCardless/SEPA.php index 62cf1ebe1113..76dcf9407a72 100644 --- a/app/PaymentDrivers/GoCardless/SEPA.php +++ b/app/PaymentDrivers/GoCardless/SEPA.php @@ -65,7 +65,7 @@ class SEPA implements MethodInterface, LivewireMethodInterface 'method' => GatewayType::SEPA, 'session_token' => $session_token, 'authorize_then_redirect' => true, - 'payment_hash' => $this->go_cardless->payment_hash?->hash, + 'payment_hash' => $this->go_cardless->payment_hash->hash, ]), 'prefilled_customer' => [ 'given_name' => auth()->guard('contact')->user()->client->present()->first_name(), diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index 4aae450790b7..d690532091b7 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -48,7 +48,7 @@ class PaymentMethod $this->payment_urls = $pu->when($contains_both, function ($methods) { return $methods->reject(function ($item) { - return $item['gateway_type_id'] == '29'; + return $item['gateway_type_id'] == '29'; //PayPal advanced credit cards, needs to be excluded here }); })->toArray(); diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index 386b8a8e05e7..ffeafb67fdd8 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -51,7 +51,7 @@ class AddGatewayFee extends AbstractService $invoice_items = collect($invoice_items)->filter(function ($item) { return $item->type_id != '3'; - }); + })->toArray(); $this->invoice->line_items = $invoice_items; @@ -92,8 +92,6 @@ class AddGatewayFee extends AbstractService /**Refresh Invoice values*/ $this->invoice = $this->invoice->calc()->getInvoice(); - nlog($this->invoice->line_items); - $new_balance = $this->invoice->balance; if (floatval($new_balance) - floatval($balance) != 0) { diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 283333fca75c..43bc48591972 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -444,14 +444,22 @@ class InvoiceService return $this; } - $pre_count = count($this->invoice->line_items); + $pre_count = count((array)$this->invoice->line_items); - $items = collect($this->invoice->line_items) - ->reject(function ($item) { - return $item->type_id == '3'; - })->toArray(); + // $items = collect((array)$this->invoice->line_items) + // ->reject(function ($item) { + // return $item->type_id == '3'; + // })->toArray(); - $this->invoice->line_items = array_values($items); + + $items = collect((array)$this->invoice->line_items) + ->filter(function ($item) { + return $item->type_id != '3'; + })->toArray(); + + $this->invoice->line_items = $items; + + // $this->invoice->line_items = array_values($items); $this->invoice = $this->invoice->calc()->getInvoice();