-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/Frontend/Purchase/Exceptions/PurchaseFailedException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Frontend\Purchase\Exceptions; | ||
|
||
use Exception; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Response; | ||
|
||
class PurchaseFailedException extends Exception | ||
{ | ||
public function render(): JsonResponse | ||
{ | ||
return response() | ||
->json([ | ||
'message' => 'The purchase could not be completed. Please wait and try again.' | ||
], Response::HTTP_EXPECTATION_FAILED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Frontend\Purchase\Mail; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Src\Frontend\Customer\Domain\Customer; | ||
use Src\Frontend\Purchase\Domain\Purchase; | ||
|
||
final class OrderReceivedNotification extends Mailable | ||
{ | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public Purchase $purchase; | ||
|
||
public function __construct(Purchase $purchase) | ||
{ | ||
$this->purchase = $purchase; | ||
} | ||
|
||
public function build(): self | ||
{ | ||
return $this->view('frontend.purchase.emails.order_received') | ||
->with([ | ||
'purchase' => $this->purchase, | ||
]); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/Frontend/Purchase/Providers/PurchaseEventServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Frontend\Purchase\Providers; | ||
|
||
|
||
use Illuminate\Foundation\Support\Providers\EventServiceProvider; | ||
use Src\Frontend\Purchase\Domain\PurchaseCreatedDomainEvent; | ||
use Src\Frontend\Purchase\Infrastructure\Mailer\LaravelMailerSendOrderReceivedNotification; | ||
|
||
class PurchaseEventServiceProvider extends EventServiceProvider | ||
{ | ||
protected $listen = [ | ||
PurchaseCreatedDomainEvent::class => [ | ||
LaravelMailerSendOrderReceivedNotification::class, | ||
] | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
resources/views/frontend/purchase/emails/order_received.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
We have received your order for {{ $purchase->uuid() }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Frontend/Purchase/Application/Listener/SendOrderReceivedNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Src\Frontend\Purchase\Application\Listener; | ||
|
||
use Src\Frontend\Purchase\Domain\PurchaseCreatedDomainEvent; | ||
|
||
interface SendOrderReceivedNotification | ||
{ | ||
public function handle(PurchaseCreatedDomainEvent $event): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Frontend/Purchase/Domain/PurchaseCreatedDomainEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Src\Frontend\Purchase\Domain; | ||
|
||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Src\Shared\Domain\Bus\Event\DomainEvent; | ||
|
||
final class PurchaseCreatedDomainEvent implements DomainEvent | ||
{ | ||
use Dispatchable; | ||
use InteractsWithSockets; | ||
|
||
public Purchase $purchase; | ||
|
||
public function __construct(Purchase $purchase) | ||
{ | ||
$this->purchase = $purchase; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Frontend/Purchase/Infrastructure/Mailer/LaravelMailerSendOrderReceivedNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Src\Frontend\Purchase\Infrastructure\Mailer; | ||
|
||
use App\Frontend\Purchase\Mail\OrderReceivedNotification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Support\Facades\Mail; | ||
use Src\Frontend\Customer\Domain\CustomerRepository; | ||
use Src\Frontend\Purchase\Application\Listener\SendOrderReceivedNotification; | ||
use Src\Frontend\Purchase\Domain\PurchaseCreatedDomainEvent; | ||
|
||
class LaravelMailerSendOrderReceivedNotification implements SendOrderReceivedNotification, ShouldQueue | ||
{ | ||
private CustomerRepository $customerRepository; | ||
|
||
public function __construct(CustomerRepository $customerRepository) | ||
{ | ||
$this->customerRepository = $customerRepository; | ||
} | ||
|
||
public function handle(PurchaseCreatedDomainEvent $event): void | ||
{ | ||
Mail::to( | ||
$this->customerRepository | ||
->find($event->purchase->customerUuid()) | ||
->email() | ||
->value() | ||
)->send(new OrderReceivedNotification($event->purchase)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Src\Shared\Domain\Logger; | ||
|
||
interface Logger | ||
{ | ||
public function critical(string $message, array $context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Src\Shared\Infrastructure\Logger; | ||
|
||
use Illuminate\Support\Facades\Log; | ||
use Src\Shared\Domain\Logger\Logger; | ||
|
||
class LaravelLogger implements Logger | ||
{ | ||
public function critical(string $message, array $context) | ||
{ | ||
Log::critical($message, $context); | ||
} | ||
} |