Added better error handling
On the completion of an order Attendize Generates a ticket and sends it via email. However if the ticket could not be generated we still attempt to send a file that does not exist which causes the checkout process to hang and throw an error message. Chained the Generate Ticket and SendOrderTickets events so that if a ticket cannot be generate we don't attempt to send it.
This commit is contained in:
parent
e45fe77568
commit
ec69e0711b
|
|
@ -74,11 +74,17 @@ class GenerateTicket extends Job implements ShouldQueue
|
|||
'image' => base64_encode(file_get_contents(public_path($image_path))),
|
||||
'images' => $images,
|
||||
];
|
||||
try {
|
||||
PDF::setOutputMode('F'); // force to file
|
||||
PDF::html('Public.ViewEvent.Partials.PDFTicket', $data, $file_path);
|
||||
Log::info("Ticket generated!");
|
||||
} catch(\Exception $e) {
|
||||
Log::error("Error generating ticket. This can be due to permissions on vendor/nitmedia/wkhtml2pdf/src/Nitmedia/Wkhtml2pdf/lib. This folder requires write and execute permissions for the web user");
|
||||
Log::error("Error message. " . $e->getMessage());
|
||||
Log::error("Error stack trace" . $e->getTraceAsString());
|
||||
$this->fail($e);
|
||||
}
|
||||
|
||||
PDF::setOutputMode('F'); // force to file
|
||||
PDF::html('Public.ViewEvent.Partials.PDFTicket', $data, $file_path);
|
||||
|
||||
Log::info("Ticket generated!");
|
||||
}
|
||||
|
||||
private function isAttendeeTicket()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
|
||||
|
||||
class ProcessGenerateAndSendTickets extends Job implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,15 @@ class SendOrderNotification extends Job implements ShouldQueue
|
|||
*/
|
||||
public function handle(OrderMailer $orderMailer)
|
||||
{
|
||||
$orderMailer->sendOrderNotification($this->order);
|
||||
try {
|
||||
$orderMailer->sendOrderNotification($this->order);
|
||||
} catch(\Exception $e) {
|
||||
Log::error("Cannot send actual ticket to : " . $this->order->email . " as ticket file does not exist on disk");
|
||||
Log::error("Error message. " . $e->getMessage());
|
||||
Log::error("Error stack trace" . $e->getTraceAsString());
|
||||
$this->fail($e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class SendOrderTickets extends Job implements ShouldQueue
|
|||
*/
|
||||
public function handle(OrderMailer $orderMailer)
|
||||
{
|
||||
$this->dispatchNow(new GenerateTicket($this->order->order_reference));
|
||||
//$this->dispatchNow(new GenerateTicket($this->order->order_reference));
|
||||
$orderMailer->sendOrderTickets($this->order);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Events\OrderCompletedEvent;
|
|||
use App\Jobs\GenerateTicket;
|
||||
use App\Jobs\SendOrderNotification;
|
||||
use App\Jobs\SendOrderTickets;
|
||||
use App\Jobs\ProcessGenerateAndSendTickets;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
|
@ -26,7 +27,8 @@ class OrderCompletedListener implements ShouldQueue
|
|||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
* Generate the ticket and send it to the attendee. If the ticket can't be generated don't attempt to send the ticket
|
||||
* to the attendee as the ticket is attached as a PDF.
|
||||
*
|
||||
* @param OrderCompletedEvent $event
|
||||
* @return void
|
||||
|
|
@ -37,9 +39,11 @@ class OrderCompletedListener implements ShouldQueue
|
|||
* Generate the PDF tickets and send notification emails etc.
|
||||
*/
|
||||
Log::info('Begin Processing Order: ' . $event->order->order_reference);
|
||||
$this->dispatchNow(new GenerateTicket($event->order->order_reference));
|
||||
$this->dispatch(new SendOrderTickets($event->order));
|
||||
$this->dispatch(new SendOrderNotification($event->order));
|
||||
ProcessGenerateAndSendTickets::withChain([
|
||||
new GenerateTicket($event->order->order_reference),
|
||||
new SendOrderTickets($event->order)
|
||||
])->dispatch();
|
||||
|
||||
$this->dispatch(new SendOrderNotification($event->order));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,13 +37,16 @@ class OrderMailer
|
|||
'orderService' => $orderService
|
||||
];
|
||||
|
||||
Mail::send('Mailers.TicketMailer.SendOrderTickets', $data, function ($message) use ($order) {
|
||||
$file_name = $order->order_reference;
|
||||
$file_path = public_path(config('attendize.event_pdf_tickets_path')) . '/' . $file_name . '.pdf';
|
||||
if (!file_exists($file_path)) {
|
||||
Log::error("Cannot send actual ticket to : " . $order->email . " as ticket file does not exist on disk");
|
||||
return;
|
||||
}
|
||||
|
||||
Mail::send('Mailers.TicketMailer.SendOrderTickets', $data, function ($message) use ($order, $file_path) {
|
||||
$message->to($order->email);
|
||||
$message->subject(trans("Controllers.tickets_for_event", ["event"=>$order->event->title]));
|
||||
|
||||
$file_name = $order->order_reference;
|
||||
$file_path = public_path(config('attendize.event_pdf_tickets_path')) . '/' . $file_name . '.pdf';
|
||||
|
||||
$message->subject(trans("Controllers.tickets_for_event", ["event" => $order->event->title]));
|
||||
$message->attach($file_path);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue