Fixes for client contact authentication

This commit is contained in:
David Bomba 2022-03-16 16:29:39 +11:00
parent 9ccc43cece
commit 29ed09db5d
8 changed files with 10 additions and 162 deletions

View File

@ -101,7 +101,6 @@ class InvoiceController extends Controller
return $this->makePayment((array) $transformed_ids); return $this->makePayment((array) $transformed_ids);
} elseif ($request->input('action') == 'download') { } elseif ($request->input('action') == 'download') {
return $this->downloadInvoices((array) $transformed_ids); return $this->downloadInvoices((array) $transformed_ids);
// return $this->downloadInvoicePDF((array) $transformed_ids);
} }
return redirect() return redirect()
@ -113,7 +112,7 @@ class InvoiceController extends Controller
{ {
$data['invoices'] = Invoice::whereIn('id', $ids) $data['invoices'] = Invoice::whereIn('id', $ids)
->whereClientId(auth()->user()->client->id) ->whereClientId(auth()->guard('contact')->user()->client->id)
->withTrashed() ->withTrashed()
->get(); ->get();
@ -135,7 +134,7 @@ class InvoiceController extends Controller
private function makePayment(array $ids) private function makePayment(array $ids)
{ {
$invoices = Invoice::whereIn('id', $ids) $invoices = Invoice::whereIn('id', $ids)
->whereClientId(auth()->user()->client->id) ->whereClientId(auth()->guard('contact')->user()->client->id)
->withTrashed() ->withTrashed()
->get(); ->get();
@ -172,14 +171,14 @@ class InvoiceController extends Controller
}); });
//format totals //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 //if there is only one payment method -> lets return straight to the payment page
$data = [ $data = [
'settings' => auth()->user()->client->getMergedSettings(), 'settings' => auth()->guard('contact')->user()->client->getMergedSettings(),
'invoices' => $invoices, 'invoices' => $invoices,
'formatted_total' => $formatted_total, 'formatted_total' => $formatted_total,
'payment_methods' => $payment_methods, 'payment_methods' => $payment_methods,
@ -201,7 +200,7 @@ class InvoiceController extends Controller
{ {
$invoices = Invoice::whereIn('id', $ids) $invoices = Invoice::whereIn('id', $ids)
->withTrashed() ->withTrashed()
->whereClientId(auth()->user()->client->id) ->whereClientId(auth()->guard('contact')->user()->client->id)
->get(); ->get();
//generate pdf's of invoices locally //generate pdf's of invoices locally
@ -212,9 +211,8 @@ class InvoiceController extends Controller
//if only 1 pdf, output to buffer for download //if only 1 pdf, output to buffer for download
if ($invoices->count() == 1) { if ($invoices->count() == 1) {
$invoice = $invoices->first(); $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))); // return response()->download(file_get_contents(public_path($file)));

View File

@ -41,8 +41,6 @@ class InvoiceEmailFailedActivity implements ShouldQueue
*/ */
public function handle($event) public function handle($event)
{ {
nlog("inside activity_repo");
MultiDB::setDb($event->company->db); MultiDB::setDb($event->company->db);
if(strpos($event->message, 'shared/public') !== false) if(strpos($event->message, 'shared/public') !== false)

View File

@ -38,8 +38,7 @@ class InvoiceFailedEmailNotification
*/ */
public function handle($event) public function handle($event)
{ {
nlog("inside a failed notification");
MultiDB::setDb($event->company->db); MultiDB::setDb($event->company->db);
$first_notification_sent = true; $first_notification_sent = true;

View File

@ -58,7 +58,6 @@ class InvoicePaidActivity implements ShouldQueue
if($event->invoice->subscription()->exists()) if($event->invoice->subscription()->exists())
{ {
nlog("subscription exists");
$event->invoice->subscription->service()->planPaid($event->invoice); $event->invoice->subscription->service()->planPaid($event->invoice);
} }

View File

@ -48,8 +48,6 @@ class SendVerificationNotification implements ShouldQueue
*/ */
public function handle($event) public function handle($event)
{ {
nlog("In Send Verification Notification");
MultiDB::setDB($event->company->db); MultiDB::setDB($event->company->db);
$event->user->service()->invite($event->company); $event->user->service()->invite($event->company);

View File

@ -153,7 +153,7 @@ class Client extends BaseModel implements HasLocalePreference
public function gateway_tokens() 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() public function expenses()
@ -582,149 +582,6 @@ class Client extends BaseModel implements HasLocalePreference
return 'USD'; 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 public function validGatewayForAmount($fees_and_limits_for_payment_type, $amount) :bool
{ {
if (isset($fees_and_limits_for_payment_type)) { if (isset($fees_and_limits_for_payment_type)) {

View File

@ -256,7 +256,7 @@ class AuthorizeCreditCard
$code = "Error"; $code = "Error";
$description = "There was an error processing the payment"; $description = "There was an error processing the payment";
if ($response->getErrors() != null) { if ($response && $response->getErrors() != null) {
$code = $response->getErrors()[0]->getErrorCode(); $code = $response->getErrors()[0]->getErrorCode();
$description = $response->getErrors()[0]->getErrorText(); $description = $response->getErrors()[0]->getErrorText();
} }

View File

@ -157,7 +157,6 @@ class InstantPayment
$payable_invoice_collection = collect(); $payable_invoice_collection = collect();
foreach ($payable_invoices as $payable_invoice) { foreach ($payable_invoices as $payable_invoice) {
// nlog($payable_invoice);
$payable_invoice['amount'] = Number::parseFloat($payable_invoice['amount']); $payable_invoice['amount'] = Number::parseFloat($payable_invoice['amount']);