Remove all instances of dispatchSync()

This commit is contained in:
David Bomba 2022-12-12 15:27:22 +11:00
parent 8ed32acce2
commit 32ff078a64
8 changed files with 85 additions and 32 deletions

View File

@ -687,7 +687,7 @@ class BankIntegrationController extends BaseController
auth()->user()->account->bank_integrations->each(function ($bank_integration) {
ProcessBankTransactions::dispatchSync(auth()->user()->account->bank_integration_account_id, $bank_integration);
(new ProcessBankTransactions(auth()->user()->account->bank_integration_account_id, $bank_integration))->handle();
});

View File

@ -332,6 +332,8 @@ class BillingPortalPurchasev2 extends Component
$total = $p->price * $qty;
$this->bundle->push([
'product_key' => $p->product_key,
'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)),
'price' => Number::formatMoney($total, $this->subscription->company).' / '. RecurringInvoice::frequencyForKey($this->subscription->frequency_id),
'total' => $total,
@ -348,6 +350,8 @@ class BillingPortalPurchasev2 extends Component
$total = $p->price * $qty;
$this->bundle->push([
'product_key' => $p->product_key,
'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)),
'price' => Number::formatMoney($total, $this->subscription->company),
'total' => $total,
@ -375,6 +379,8 @@ class BillingPortalPurchasev2 extends Component
$this->bundle->push([
'product_key' => $p->product_key,
'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)),
'price' => Number::formatMoney($total, $this->subscription->company).' / '. RecurringInvoice::frequencyForKey($this->subscription->frequency_id),
'total' => $total,
@ -398,6 +404,8 @@ class BillingPortalPurchasev2 extends Component
return;
$this->bundle->push([
'product_key' => $p->product_key,
'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)),
'price' => Number::formatMoney($total, $this->subscription->company),
'total' => $total,
@ -503,19 +511,19 @@ class BillingPortalPurchasev2 extends Component
{
$this->payment_started = true;
// $data = [
// 'client_id' => $this->contact->client->id,
// 'date' => now()->format('Y-m-d'),
// 'invitations' => [[
// 'key' => '',
// 'client_contact_id' => $this->contact->hashed_id,
// ]],
// 'user_input_promo_code' => $this->coupon,
// 'coupon' => empty($this->subscription->promo_code) ? '' : $this->coupon,
// // 'quantity' => $this->quantity,
// ];
$data = [
'client_id' => $this->contact->client->id,
'date' => now()->format('Y-m-d'),
'invitations' => [[
'key' => '',
'client_contact_id' => $this->contact->hashed_id,
]],
'user_input_promo_code' => $this->coupon,
'coupon' => empty($this->subscription->promo_code) ? '' : $this->coupon,
// 'quantity' => $this->quantity,
];
// $is_eligible = $this->subscription->service()->isEligible($this->contact);
$is_eligible = $this->subscription->service()->isEligible($this->contact);
// if (is_array($is_eligible) && $is_eligible['message'] != 'Success') {
// $this->steps['not_eligible'] = true;
@ -525,14 +533,14 @@ class BillingPortalPurchasev2 extends Component
// return;
// }
// $this->invoice = $this->subscription
// ->service()
// ->createInvoice($data, $this->quantity)
// ->service()
// ->markSent()
// ->fillDefaults()
// ->adjustInventory()
// ->save();
$this->invoice = $this->subscription
->service()
->createInvoiceV2($this->bundle)
->service()
// ->markSent()
->fillDefaults()
->adjustInventory()
->save();
// Cache::put($this->hash, [
// 'subscription_id' => $this->subscription->id,

View File

@ -426,14 +426,14 @@ class NinjaMailerJob implements ShouldQueue
private function logMailError($errors, $recipient_object)
{
SystemLogger::dispatchSync(
(new SystemLogger(
$errors,
SystemLog::CATEGORY_MAIL,
SystemLog::EVENT_MAIL_SEND,
SystemLog::TYPE_FAILURE,
$recipient_object,
$this->nmo->company
);
))->handle();
$job_failure = new EmailFailure($this->nmo->company->company_key);
$job_failure->string_metric5 = 'failed_email';

View File

@ -60,7 +60,7 @@ class BankTransactionSync implements ShouldQueue
$account->bank_integrations()->where('auto_sync', true)->cursor()->each(function ($bank_integration) use ($account){
ProcessBankTransactions::dispatchSync($account->bank_integration_account_id, $bank_integration);
(new ProcessBankTransactions($account->bank_integration_account_id, $bank_integration))->handle();
});

View File

@ -142,13 +142,13 @@ class ProcessPostmarkWebhook implements ShouldQueue
$this->invitation->opened_date = now();
$this->invitation->save();
SystemLogger::dispatchSync($this->request,
(new SystemLogger($this->request,
SystemLog::CATEGORY_MAIL,
SystemLog::EVENT_MAIL_OPENED,
SystemLog::TYPE_WEBHOOK_RESPONSE,
$this->invitation->contact->client,
$this->invitation->company
);
))->handle();
}
@ -171,13 +171,13 @@ class ProcessPostmarkWebhook implements ShouldQueue
$this->invitation->email_status = 'delivered';
$this->invitation->save();
SystemLogger::dispatchSync($this->request,
(new SystemLogger($this->request,
SystemLog::CATEGORY_MAIL,
SystemLog::EVENT_MAIL_DELIVERY,
SystemLog::TYPE_WEBHOOK_RESPONSE,
$this->invitation->contact->client,
$this->invitation->company
);
))->handle();
}
// {
@ -219,7 +219,7 @@ class ProcessPostmarkWebhook implements ShouldQueue
LightLogs::create($bounce)->send();
SystemLogger::dispatchSync($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company);
(new SystemLogger($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company))->handle();
// if(config('ninja.notification.slack'))
// $this->invitation->company->notification(new EmailBounceNotification($this->invitation->company->account))->ninja();
@ -265,7 +265,7 @@ class ProcessPostmarkWebhook implements ShouldQueue
LightLogs::create($spam)->send();
SystemLogger::dispatchSync($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SPAM_COMPLAINT, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company);
(new SystemLogger($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SPAM_COMPLAINT, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company))->handle();
if(config('ninja.notification.slack'))
$this->invitation->company->notification(new EmailSpamNotification($this->invitation->company->account))->ninja();

View File

@ -127,7 +127,7 @@ class RecurringService
if($this->recurring_entity instanceof RecurringInvoice && $this->recurring_entity->status_id == RecurringInvoice::STATUS_DRAFT){
$this->start()->save();
SendRecurring::dispatchSync($this->recurring_entity, $this->recurring_entity->company->db);
(new SendRecurring($this->recurring_entity, $this->recurring_entity->company->db))->handle();
}
$this->recurring_entity = $this->recurring_entity->fresh();

View File

@ -702,6 +702,28 @@ class SubscriptionService
->fillDefaults()
->save();
}
public function createInvoiceV2($bundle)
{
$invoice_repo = new InvoiceRepository();
$subscription_repo = new SubscriptionRepository();
$invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
$invoice->subscription_id = $this->subscription->id;
$line_items = $bundle->map(function ($item){
$line_item = new InvoiceItem;
})->toArray();
$invoice->line_items = $line_items;
}
/**

View File

@ -7,8 +7,31 @@
{{ $subscription->name }}
</h1>
</div>
<form wire:submit.prevent="submit">
@if(isset($invoice))
<div class="flex items-center mt-4 text-sm">
<form action="{{ route('client.payments.process', ['hash' => $hash, 'sidebar' => 'hidden']) }}"
method="post"
id="payment-method-form">
@csrf
@if($invoice instanceof \App\Models\Invoice)
<input type="hidden" name="invoices[]" value="{{ $invoice->hashed_id }}">
<input type="hidden" name="payable_invoices[0][amount]"
value="{{ $invoice->partial > 0 ? \App\Utils\Number::formatValue($invoice->partial, $invoice->client->currency()) : \App\Utils\Number::formatValue($invoice->balance, $invoice->client->currency()) }}">
<input type="hidden" name="payable_invoices[0][invoice_id]"
value="{{ $invoice->hashed_id }}">
@endif
<input type="hidden" name="action" value="payment">
<input type="hidden" name="company_gateway_id" value=""/>
<input type="hidden" name="payment_method_id" value=""/>
</form>
</div>
@endif
<form wire:submit.prevent="submit">
<!-- Recurring Plan Products-->
<ul role="list" class="-my-6 divide-y divide-gray-200">
@if(!empty($subscription->recurring_product_ids))