From 6b73f319937898bde5bb14c4589ca6fc1f976a62 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 3 Jun 2023 15:48:33 +0800 Subject: [PATCH] email payment proof --- .../SendUserPaymentProofUploadedEmail.php | 42 +++++++++++++++++++ .../CreatePaymentProofDocumentLogic.php | 15 ++++++- .../PaymentProofUploadedEmail.php | 41 ++++++++++++++++++ .../accounts/payment_proof_email.blade.php | 12 ++++++ routes/web.php | 38 ++++++++++++++++- 5 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php create mode 100644 app/Classes/Notifications/PaymentProofUploadedEmail.php create mode 100644 resources/views/emails/accounts/payment_proof_email.blade.php diff --git a/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php new file mode 100644 index 00000000..8aa94ce8 --- /dev/null +++ b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php @@ -0,0 +1,42 @@ +user = $user; + $this->booking = $booking; + } + + + public function handle() + { + $this->user->notify(new PaymentProofUploadedEmail($this->user, $this->booking)); + } +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php index fdda9019..b4448729 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php @@ -14,6 +14,7 @@ use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\CompanyType; use App\Classes\ValueObjects\Constants\DocumentType; +use App\Classes\Jobs\SendUserPaymentProofUploadedEmail; use App\Models\Company; use App\Models\Document; use Illuminate\Http\JsonResponse; @@ -50,6 +51,9 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic /** @var CreateInvoiceTransactionProcessor */ private $createInvoiceTransactionProcessor; + /** @var SendUserPaymentProofUploadedEmail */ + private $sendUserPaymentProofUploadedEmail; + /** * CreatePaymentProofDocumentLogic constructor. * @param FetchesTransaction $fetchesTransaction @@ -58,13 +62,14 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic * @param UpdatesTransactionStatus $updatesTransactionStatus * @param CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor */ - public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor) + public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor, SendUserPaymentProofUploadedEmail $sendUserPaymentProofUploadedEmail) { $this->fetchesTransaction = $fetchesTransaction; $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor; + $this->sendUserPaymentProofUploadedEmail = $sendUserPaymentProofUploadedEmail; } /** @@ -88,6 +93,14 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic $this->createInvoiceTransactionProcessor->execute($transaction->owner->booking); + // send email to customer + // todo: send them the file also + // todo: a function to send a proof to the receipiant, they have to give us a email of the receipiant and also need to submiited purchase order + $companyEmployee = $transaction->owner->booking->company->employees; + foreach ($companyEmployee as $employee) { + $this->sendUserPaymentProofUploadedEmail::dispatch($employee, $transaction->owner->booking); + } + return $this->response([]); } diff --git a/app/Classes/Notifications/PaymentProofUploadedEmail.php b/app/Classes/Notifications/PaymentProofUploadedEmail.php new file mode 100644 index 00000000..d0bf21f0 --- /dev/null +++ b/app/Classes/Notifications/PaymentProofUploadedEmail.php @@ -0,0 +1,41 @@ +user = $user; + $this->booking = $booking; + } + + + public function toMail() + { + return (new MailMessage) + ->subject('Transfer Completed (REF: ' . $this->booking->marking . ')') + ->to('edmond.wuiming2021@gmail.com') // testing email + // ->attach('/path/to/file') // todo-new: add attachement + ->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]); + } + + +} diff --git a/resources/views/emails/accounts/payment_proof_email.blade.php b/resources/views/emails/accounts/payment_proof_email.blade.php new file mode 100644 index 00000000..8d888671 --- /dev/null +++ b/resources/views/emails/accounts/payment_proof_email.blade.php @@ -0,0 +1,12 @@ +@extends('emails.layout.base') + +@section('content') +

Dear {{$user->name}},

+

Thank you for using CIEF Exchange service!

+

We have completed your RMB transfer transaction for the ref. no {{$booking->marking}}. The RMB bank slip has been attached to this email. If you would like to view the transaction, please click on the following link:

+
+ +
+ + +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 2547d087..3116a479 100644 --- a/routes/web.php +++ b/routes/web.php @@ -600,4 +600,40 @@ Route::get('/po/outsource/check', function(){ Route::get('/upload-honey-trap', function () { return view('pages.honey_trap'); -})->name('upload_honey_trap'); \ No newline at end of file +})->name('upload_honey_trap'); + +Route::get('/text-transfer-email', function () { + $booking = Booking::where('marking', '25760')->first(); + $mployee = $booking->company->employees->first(); + return view('emails.accounts.payment_proof_email', ['booking' => $booking, 'user' => $mployee, ]); +}); + +use Illuminate\Support\Facades\Mail; + +Route::get('/show-email', function () { + // Send some emails using MailMessage + // Retrieve the Swift Mailer instance + $mailer = Mail::getSwiftMailer(); + // Retrieve the Transport instance + $transport = $mailer->getTransport(); + // Retrieve the sent messages + $messages = $transport->getMessages(); + // Loop through the sent messages + foreach ($messages as $message) { + // Access the email details + $subject = $message->getSubject(); + $from = $message->getFrom(); + $to = $message->getTo(); + $cc = $message->getCc(); + $bcc = $message->getBcc(); + // ...and so on + + // Output the email details + echo "Subject: $subject\n"; + echo "From: $from\n"; + echo "To: $to\n"; + echo "Cc: $cc\n"; + echo "Bcc: $bcc\n"; + echo "\n"; + } +});