2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Payment;
|
|
|
|
|
|
|
|
use App\Helpers\Email\PaymentEmail;
|
|
|
|
use App\Jobs\Payment\EmailPayment;
|
|
|
|
|
|
|
|
class SendEmail
|
|
|
|
{
|
|
|
|
public $payment;
|
|
|
|
|
2020-05-09 00:35:49 +02:00
|
|
|
public $contact;
|
|
|
|
|
|
|
|
public function __construct($payment, $contact)
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
|
|
|
$this->payment = $payment;
|
2020-05-09 00:35:49 +02:00
|
|
|
|
|
|
|
$this->contact = $contact;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the correct template to send
|
|
|
|
* @param string $reminder_template The template name ie reminder1
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-05-09 00:35:49 +02:00
|
|
|
public function run()
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
|
|
|
$email_builder = (new PaymentEmail())->build($this->payment, $contact);
|
|
|
|
|
|
|
|
$this->payment->client->contacts->each(function ($contact) use ($email_builder) {
|
2020-02-15 13:27:24 +01:00
|
|
|
if ($contact->send && $contact->email) {
|
2020-02-15 10:01:15 +01:00
|
|
|
EmailPayment::dispatchNow($this->payment, $email_builder, $contact);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|