Skip to content

Commit

Permalink
Dispatching QR generation at the point of voucher generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ok200paul committed Sep 30, 2024
1 parent 39aa343 commit e0f0c06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 1 addition & 7 deletions app/Jobs/Vouchers/GenerateStorageVoucherQrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Exception;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
Expand All @@ -32,13 +33,6 @@ public function __construct(public Voucher $voucher) {}
public function handle(): void
{

if(!isset($this->voucher->voucher_short_code) || is_null($this->voucher->voucher_short_code))
{
dispatch(new GenerateStorageVoucherQrCode($this->voucher))->delay(now()->addMinutes(10));
return;
}


$redeemUrl = URL::to('/redeem/' . $this->voucher->voucher_set_id . '/' . $this->voucher->id);

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/Vouchers/HandleVoucherWasCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(VoucherWasCreated $event): void
/**
* Delay this job by 5 minutes so that the image generation comes last.
*/
dispatch(new GenerateStorageVoucherQrCode($event->voucher))->delay(now()->addMinutes(10));
dispatch(new GenerateStorageVoucherQrCode($event->voucher));
}
}
}
10 changes: 10 additions & 0 deletions app/Services/VoucherTemplateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public static function generateVoucherTemplate(VoucherTemplate $voucherTemplate,
*/
$img->place($qrCode, 'top-left', $voucherTemplate->voucher_qr_x, $voucherTemplate->voucher_qr_y);



/**
*
*/
if(!isset($voucher->voucher_short_code) || is_null($voucher->voucher_short_code))
{
Log::error('generateVoucherTemplate: No voucher_short_code exists for voucher #'.$voucher->id);
}

/**
* Place the voucher short code
*/
Expand Down

0 comments on commit e0f0c06

Please sign in to comment.