diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 6dad4a19ab79..42cd3598d1b4 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -101,7 +101,6 @@ class InvoiceController extends Controller return $this->makePayment((array) $transformed_ids); } elseif ($request->input('action') == 'download') { return $this->downloadInvoices((array) $transformed_ids); - // return $this->downloadInvoicePDF((array) $transformed_ids); } return redirect() @@ -113,7 +112,7 @@ class InvoiceController extends Controller { $data['invoices'] = Invoice::whereIn('id', $ids) - ->whereClientId(auth()->user()->client->id) + ->whereClientId(auth()->guard('contact')->user()->client->id) ->withTrashed() ->get(); @@ -135,7 +134,7 @@ class InvoiceController extends Controller private function makePayment(array $ids) { $invoices = Invoice::whereIn('id', $ids) - ->whereClientId(auth()->user()->client->id) + ->whereClientId(auth()->guard('contact')->user()->client->id) ->withTrashed() ->get(); @@ -172,14 +171,14 @@ class InvoiceController extends Controller }); //format totals - $formatted_total = Number::formatMoney($total, auth()->user()->client); + $formatted_total = Number::formatMoney($total, auth()->guard('contact')->user()->client); - $payment_methods = auth()->user()->client->service()->getPaymentMethods($total); + $payment_methods = auth()->guard('contact')->user()->client->service()->getPaymentMethods($total); //if there is only one payment method -> lets return straight to the payment page $data = [ - 'settings' => auth()->user()->client->getMergedSettings(), + 'settings' => auth()->guard('contact')->user()->client->getMergedSettings(), 'invoices' => $invoices, 'formatted_total' => $formatted_total, 'payment_methods' => $payment_methods, @@ -201,7 +200,7 @@ class InvoiceController extends Controller { $invoices = Invoice::whereIn('id', $ids) ->withTrashed() - ->whereClientId(auth()->user()->client->id) + ->whereClientId(auth()->guard('contact')->user()->client->id) ->get(); //generate pdf's of invoices locally @@ -212,9 +211,8 @@ class InvoiceController extends Controller //if only 1 pdf, output to buffer for download if ($invoices->count() == 1) { $invoice = $invoices->first(); - $invitation = $invoice->invitations->first(); - $file = $invoice->service()->getInvoicePdf(auth()->user()); + $file = $invoice->service()->getInvoicePdf(auth()->guard('contact')->user()); // return response()->download(file_get_contents(public_path($file))); diff --git a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php index 72a306b34483..481e65f5344d 100644 --- a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php @@ -41,8 +41,6 @@ class InvoiceEmailFailedActivity implements ShouldQueue */ public function handle($event) { - nlog("inside activity_repo"); - MultiDB::setDb($event->company->db); if(strpos($event->message, 'shared/public') !== false) diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index fbaba6e97be3..ce2405431318 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -38,8 +38,7 @@ class InvoiceFailedEmailNotification */ public function handle($event) { - nlog("inside a failed notification"); - + MultiDB::setDb($event->company->db); $first_notification_sent = true; diff --git a/app/Listeners/Invoice/InvoicePaidActivity.php b/app/Listeners/Invoice/InvoicePaidActivity.php index 5bc5d42a6f62..3e21a3565091 100644 --- a/app/Listeners/Invoice/InvoicePaidActivity.php +++ b/app/Listeners/Invoice/InvoicePaidActivity.php @@ -58,7 +58,6 @@ class InvoicePaidActivity implements ShouldQueue if($event->invoice->subscription()->exists()) { - nlog("subscription exists"); $event->invoice->subscription->service()->planPaid($event->invoice); } diff --git a/app/Listeners/SendVerificationNotification.php b/app/Listeners/SendVerificationNotification.php index 5f2d98b5a338..b7d819abed1e 100644 --- a/app/Listeners/SendVerificationNotification.php +++ b/app/Listeners/SendVerificationNotification.php @@ -48,8 +48,6 @@ class SendVerificationNotification implements ShouldQueue */ public function handle($event) { - nlog("In Send Verification Notification"); - MultiDB::setDB($event->company->db); $event->user->service()->invite($event->company); diff --git a/app/Models/Client.php b/app/Models/Client.php index 71317443deb3..0c7bbb3d84f9 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -153,7 +153,7 @@ class Client extends BaseModel implements HasLocalePreference public function gateway_tokens() { - return $this->hasMany(ClientGatewayToken::class)->orderBy('is_default', 'ASC'); + return $this->hasMany(ClientGatewayToken::class)->orderBy('is_default', 'DESC'); } public function expenses() @@ -582,149 +582,6 @@ class Client extends BaseModel implements HasLocalePreference return 'USD'; } - /** - * Generates an array of payment urls per client - * for a given amount. - * - * The route produced will provide the - * company_gateway and payment_type ids - * - * The invoice/s will need to be injected - * upstream of this method as they are not - * included in this logic. - * - * @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 - // { - // //this method will get all the possible gateways a client can pay with - // //but we also need to consider payment methods that are already stored - // //so we MUST filter the company gateways and remove duplicates. - - // //Also need to harvest the list of client gateway tokens and present these - // //for instant payment - - // $company_gateways = $this->getSetting('company_gateway_ids'); - - // //we need to check for "0" here as we disable a payment gateway for a client with the number "0" - // if ($company_gateways || $company_gateways == '0') { - // $transformed_ids = $this->transformKeys(explode(',', $company_gateways)); - // $gateways = $this->company - // ->company_gateways - // ->whereIn('id', $transformed_ids) - // ->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa') - // ->sortby(function ($model) use ($transformed_ids) { //company gateways are sorted in order of priority - // return array_search($model->id, $transformed_ids);// this closure sorts for us - // }); - // } else { - // $gateways = $this->company - // ->company_gateways - // ->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa') - // ->where('is_deleted', false); - // } - - // $payment_methods = []; - - // foreach ($gateways as $gateway) { - // foreach ($gateway->driver($this)->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)) { - // $payment_methods[] = [$gateway->id => $type]; - // } - // } else { - // $payment_methods[] = [$gateway->id => $type]; - // } - // } - // } - - // $payment_methods_collections = collect($payment_methods); - - // //** Plucks the remaining keys into its own collection - // $payment_methods_intersect = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique()); - - // // handle custom gateways as they are not unique'd()--------------------------------------------------------- - // // we need to split the query here as we allow multiple custom gateways, so we must show all of them, they query logic - // // above only pulls in unique gateway types.. ie.. we only allow 1 credit card gateway, but many custom gateways. - - // if ($company_gateways || $company_gateways == '0') { - // $transformed_ids = $this->transformKeys(explode(',', $company_gateways)); - // $gateways = $this->company - // ->company_gateways - // ->whereIn('id', $transformed_ids) - // ->where('gateway_key', '=', '54faab2ab6e3223dbe848b1686490baa') - // ->sortby(function ($model) use ($transformed_ids) { //company gateways are sorted in order of priority - // return array_search($model->id, $transformed_ids);// this closure sorts for us - // }); - // } else { - // $gateways = $this->company - // ->company_gateways - // ->where('gateway_key', '=', '54faab2ab6e3223dbe848b1686490baa') - // ->where('is_deleted', false); - // } - - // //note we have to use GatewayType::CREDIT_CARD as alias for CUSTOM - // foreach ($gateways as $gateway) { - // foreach ($gateway->driver($this)->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)) { - // $payment_methods_intersect->push([$gateway->id => $type]); - // } - // } else { - // $payment_methods_intersect->push([$gateway->id => NULL]); - // } - // } - // } - - // //handle custom gateways as they are not unique'd()--------------------------------------------------------- - - // $payment_urls = []; - - // foreach ($payment_methods_intersect as $key => $child_array) { - // foreach ($child_array as $gateway_id => $gateway_type_id) { - // $gateway = CompanyGateway::find($gateway_id); - - // $fee_label = $gateway->calcGatewayFeeLabel($amount, $this); - - // if(!$gateway_type_id){ - - // $payment_urls[] = [ - // 'label' => $gateway->getConfigField('name') . $fee_label, - // 'company_gateway_id' => $gateway_id, - // 'gateway_type_id' => GatewayType::CREDIT_CARD, - // ]; - // } - // else - // { - // $payment_urls[] = [ - // 'label' => $gateway->getTypeAlias($gateway_type_id) . $fee_label, - // 'company_gateway_id' => $gateway_id, - // 'gateway_type_id' => $gateway_type_id, - // ]; - // } - // } - // } - - // if (($this->getSetting('use_credits_payment') == 'option' || $this->getSetting('use_credits_payment') == 'always') && $this->service()->getCreditBalance() > 0) { - - // // Show credits as only payment option if both statements are true. - // if ( - // $this->service()->getCreditBalance() > $amount - // && $this->getSetting('use_credits_payment') == 'always') { - // $payment_urls = []; - // } - - // $payment_urls[] = [ - // 'label' => ctrans('texts.apply_credit'), - // 'company_gateway_id' => CompanyGateway::GATEWAY_CREDIT, - // 'gateway_type_id' => GatewayType::CREDIT, - // ]; - // } - - // return $payment_urls; - // } - public function validGatewayForAmount($fees_and_limits_for_payment_type, $amount) :bool { if (isset($fees_and_limits_for_payment_type)) { diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 5579a22ed892..98906f81d2d2 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -256,7 +256,7 @@ class AuthorizeCreditCard $code = "Error"; $description = "There was an error processing the payment"; - if ($response->getErrors() != null) { + if ($response && $response->getErrors() != null) { $code = $response->getErrors()[0]->getErrorCode(); $description = $response->getErrors()[0]->getErrorText(); } diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index bd7b89378645..c628c803f853 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -157,7 +157,6 @@ class InstantPayment $payable_invoice_collection = collect(); foreach ($payable_invoices as $payable_invoice) { - // nlog($payable_invoice); $payable_invoice['amount'] = Number::parseFloat($payable_invoice['amount']);