Parcourir la source

Attach invoice to mail

1day2die il y a 3 ans
Parent
commit
c12e825b2e

+ 7 - 8
app/Http/Controllers/Admin/PaymentController.php

@@ -7,9 +7,7 @@ use App\Http\Controllers\Controller;
 use App\Models\Configuration;
 use App\Models\Payment;
 use App\Models\PaypalProduct;
-use App\Models\Product;
 use App\Models\User;
-use App\Notifications\ConfirmPaymentNotification;
 use App\Notifications\InvoiceNotification;
 use Exception;
 use Illuminate\Contracts\Foundation\Application;
@@ -192,8 +190,6 @@ class PaymentController extends Controller
                     'payer' => json_encode($response->result->payer),
                 ]);
 
-                //payment notification
-                $user->notify(new ConfirmPaymentNotification($payment));
 
                 event(new UserUpdateCreditsEvent($user));
 
@@ -237,22 +233,25 @@ class PaymentController extends Controller
                     ->delimiter("-")
                     ->sequence($newInvoiceID)
                     ->serialNumberFormat(env("INVOICE_PREFIX","INV").'{DELIMITER}{SERIES}{SEQUENCE}')
-
                     ->logo(public_path('vendor/invoices/logo.png'));
 
                 //Save the invoice in "storage\app\invoice\USER_ID\YEAR"
+                $invoice->filename=$invoice->getSerialNumber().'.pdf';
                 $invoice->render();
                 Storage::disk("local")->put("invoice/".$user->id."/".now()->format('Y')."/".$invoice->filename, $invoice->output);
 
-               // $user->notify(new InvoiceNotification($invoice));
 
                 \App\Models\invoice::create([
                     'invoice_user' => $user->id,
-                    'invoice_name' => "invoice_".$invoice->series.$invoice->delimiter.$invoice->sequence,
+                    'invoice_name' => $invoice->getSerialNumber(),
                     'payment_id' => $payment->payment_id,
                 ]);
+
+                //Send Invoice per Mail
+                $user->notify(new InvoiceNotification($invoice,$user, $payment));
+
                 //redirect back to home
-                return redirect()->route('home')->with('success', 'Your credit balance has been increased! Find the invoice in your Notifications');
+                return redirect()->route('home')->with('success', 'Your credit balance has been increased!');
             }
 
 

+ 19 - 7
app/Notifications/InvoiceNotification.php

@@ -2,10 +2,11 @@
 
 namespace App\Notifications;
 
-use App\Models\Server;
+use App\Models\User;
 use Illuminate\Bus\Queueable;
 use Illuminate\Notifications\Messages\MailMessage;
 use Illuminate\Notifications\Notification;
+use App\Models\Payment;
 use LaravelDaily\Invoices\Invoice;
 
 class InvoiceNotification extends Notification
@@ -14,17 +15,23 @@ class InvoiceNotification extends Notification
     use Queueable;
     /**
      * @var invoice
+     *      * @var invoice
+     *      * @var invoice
      */
     private $invoice;
+    private $user;
+    private $payment;
 
     /**
      * Create a new notification instance.
      *
      * @param Invoice $invoice
      */
-    public function __construct(Invoice $invoice)
+    public function __construct(Invoice $invoice, User $user, Payment $payment)
     {
         $this->invoice = $invoice;
+        $this->user = $user;
+        $this->payment = $payment;
     }
 
     /**
@@ -47,10 +54,15 @@ class InvoiceNotification extends Notification
     public function toMail($notifiable)
     {
         return (new MailMessage)
-            ->subject('Your Invoice!')
-            ->greeting('Your invoice is ready')
-            ->line("Skurr skurr.")
-            ->line('damn son.')
-            ->attach($this->invoice->stream());
+            ->subject('Your Payment was successful!')
+            ->greeting('Hello,')
+            ->line("Your payment was processes!.")
+            ->line('Status: '.$this->payment->status)
+            ->line('Price: '.$this->payment->formatToCurrency($this->payment->total_price))
+            ->line('Type: '.$this->payment->type)
+            ->line('Amount: '.$this->payment->amount)
+            ->line('Balance: '.$this->user->credits)
+            ->line('User ID: '.$this->payment->user_id)
+            ->attach(storage_path('app/invoice/'.$this->user->id.'/'.now()->format('Y').'/'.$this->invoice->filename));
     }
 }