File: /var/www/vhost/disk-apps/alq-cali.bikenow.co/app/Mail/ExperienceConfirmed.php
<?php
namespace App\Mail;
use App\Core\Experience\Domain\ValueObjects\PurchaseOriginEnum;
use App\Core\Parameter\Application\ParameterService;
use App\Core\User\Application\UserService;
use App\Models\Experience\ExperiencePayment;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
class ExperienceConfirmed extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
private $parameterService;
private $ticketService;
private $tranferService;
private $userService;
public $experiencePaymentId;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($experiencePaymentId)
{
$this->parameterService = new ParameterService();
$this->userService = new UserService();
$this->experiencePaymentId = $experiencePaymentId;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$experiencePayment = ExperiencePayment::findOrFail($this->experiencePaymentId);
if ($experiencePayment->experience_plan_price->plan->experience->enable_raffle == 1) {
return $this->sendEmailRaffle($experiencePayment);
} else if ($experiencePayment->purchase_origin == PurchaseOriginEnum::APP) {
return $this->sendEmailApp($experiencePayment);
} else {
return $this->sendEmailWeb($experiencePayment);
}
}
private function sendEmailApp($experiencePayment)
{
$experienceUser = $experiencePayment->experience_user;
$appUser = User::findOrFail($experiencePayment->experience_user->user_id);
$experience = $experiencePayment->experience_plan_price->plan->experience;
if (is_null($experience->email_template_id)) {
// send default email
return $this->from('noreply@sports-crowd.com', 'Sports Crowd')
->subject(__('experiences.email.subject'))
->view('mails.experience.experience-confirmed')
->to([$experienceUser->email, $appUser->email]) // En línea
->with([
'experiencePayment' => $experiencePayment,
'experienceUser' => $experienceUser,
'experience' => $experience,
'appStoreUrl' => $this->parameterService->appStoreUrl(),
'playStoreUrl' => $this->parameterService->playStoreUrl(),
]);
} else {
// send custom email
return $this->from('noreply@sports-crowd.com', 'Sports Crowd')
->subject($experience->emailTemplate->subject)
->html($experience->emailTemplate->body)
->to([$experienceUser->email, $appUser->email]);
}
}
private function sendEmailWeb($experiencePayment)
{
$experienceUser = $experiencePayment->experience_user;
$appUser = User::findOrFail($experiencePayment->experience_user->user_id);
$experience = $experiencePayment->experience_plan_price->plan->experience;
// 1. Información que se va a codificar como QR
$qrData = json_encode(['t' => 'E', 'u' => $experiencePayment->id]);
// 2. Crear QR como imagen en memoria (puede ser PNG base64 o contenido binario)
$qrImage = QrCode::format('png')->size(300)->generate($qrData);
return $this->from('noreply@sports-crowd.com', 'Sports Crowd')
->subject(__('experiences.email.subject'))
->view('mails.experience.experience-confirmed-with-qr')
->to([$experienceUser->email, $appUser->email]) // En línea
->with([
'experiencePayment' => $experiencePayment,
'experienceUser' => $experienceUser,
'experience' => $experience,
])
->attachData($qrImage, 'qr-code.png', [
'mime' => 'image/png',
]);
}
private function sendEmailRaffle($experiencePayment)
{
$experienceUser = $experiencePayment->experience_user;
$appUser = User::findOrFail($experiencePayment->experience_user->user_id);
$experience = $experiencePayment->experience_plan_price->plan->experience;
return $this->from('noreply@sports-crowd.com', 'Sports Crowd')
->subject(__('experiences.email.subject'))
->view('mails.experience.experience-confirmed-raffle')
->to([$experienceUser->email, $appUser->email]) // En línea
->with([
'experiencePayment' => $experiencePayment,
'experienceUser' => $experienceUser,
'experience' => $experience,
'appStoreUrl' => $this->parameterService->appStoreUrl(),
'playStoreUrl' => $this->parameterService->playStoreUrl(),
]);
}
}