src/Controller/TunnelController.php line 760
<?php
namespace App\Controller;
use App\Entity\Page;
use App\Entity\User;
use App\Entity\Country;
use App\Entity\PromoCode;
use App\Helper\GeoPlugin;
use App\Entity\UserPayment;
use App\Helper\IpToCountry;
use App\Entity\ReminderUser;
use App\Entity\UserTempData;
use App\Helper\FacebookSAPI;
use App\Entity\PaymentMethod;
use App\Service\MailchimpAPI;
use App\Service\MailingTransac;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
#[Route('/{_locale}')]
class TunnelController extends AbstractController
{
public $doctrine;
private $entityManager;
public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
$this->entityManager = $this->doctrine->getManager();
}
#[Route('/default', name: 'tunnel_default')]
public function index(): Response
{
return $this->render('tunn/index.html.twig', [
'controller_name' => 'DefaultController',
]);
}
public static function detectCountry(Request $request)
{
$session = $request->getSession();
$country = new IpToCountry();
$country->setUserCountry($request, $session);
}
public static function setPromoCode(Request $request, $session, $doctrine){
if($request->getMethod() == 'POST'){
$promoCode = $request->request->get('cp',false);
if($promoCode !== false){
$promoCode = addslashes(str_replace(' ', '', trim(mb_strtolower($promoCode, 'UTF-8'))));
$code = $doctrine->getRepository(PromoCode::class)->getPromoCode($promoCode);
if($code != null){
$session->set('promo_code',$promoCode);
$session->set('url_promo_code',true);
}else{
$session->set('promo_code','');
$session->set('url_promo_code',false);
}
}
}
}
protected function getUserIsoCode($request, $session)
{
$ipAddress = $request->getClientIp();
if ($session->get('country_iso',null) == null) {
try {
$geo = new GeoPlugin();
$geo->locate($ipAddress);
$countryCode = $geo->countryCode;
if($countryCode == null)
$countryCode = 'FR';
} catch (\Exception $e) {
$countryCode = 'FR';
}
$session->set('country_iso', $countryCode);
} else {
$countryCode = $session->get('country_iso',null);
}
return $countryCode;
}
static function findUser($controller, $session)
{
$user = $controller->getUser();
if($user != null)
{
return $user;
} else {
$tempId = $session->get('user_data_id',null);
if($tempId != null)
{
$user = $controller->doctrine->getRepository(UserTempData::class)->findOneById($tempId);
if($user != null)
{
return $user;
}
}
}
return null;
//retourne un user ou un tempUserData
}
#[Route('/inscription/gratuit.html', name: 'tunnel_simple_register')]
public function registerSimple(Request $request, UserPasswordHasherInterface $passwordHasher, MailchimpAPI $mailchimp, Security $security): Response
{
$session = $request->getSession();
$user = new User(); //on crée un user vide pour récupérer les informations
$form = $this->createFormBuilder($user, ['validation_groups' => ['Default', 'registration'], 'translation_domain' => 'tunnel'])
->add('username', TextType::class, ['label' => 'Choisissez un pseudo'])
->add('email', RepeatedType::class, [
'type' => EmailType::class,
'required' => true,
'first_options' => ['label' => 'Entrez votre e-mail'],
'second_options' => ['label' => 'Répétez votre e-mail'],
])
->add('plainPassword', PasswordType::class, ['attr' => ['class' => 'w-75'], 'label' => 'Choisissez un mot de passe'])
->add('captcha', Recaptcha3Type::class, [
'constraints' => new Recaptcha3(),
'action_name' => 'subscriptionFree',
'locale' => $request->getLocale(),
])
->add('submit', SubmitType::class, ['label' => 'Continuer'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$user = $form->getData();
$password = $user->getPlainPassword();
//hasher le password
$hashedPassword = $passwordHasher->hashPassword(
$user,
$password
);
$user->setPassword($hashedPassword);
$user->setLocale($request->getLocale());
$session = $request->getSession();
$countryCode = $this->getUserIsoCode($request, $session);
$defaultCountry = $this->doctrine->getRepository(Country::class)->findOneByIsoCode($countryCode);
if(!$defaultCountry || $countryCode == "FR")
$defaultCountry = $this->doctrine->getRepository(Country::class)->findOneByCanonicalName('france-metropolitaine');
$user->setEcountry($defaultCountry);
$this->entityManager->persist($user);
$this->entityManager->flush();
$session = $request->getSession();
$session->set('user_data_id',$user->getId());
//FB API !
$event_id = $this->sendFBMsgRegister($user);
$session->set('reg_event_id',$event_id);
$this->doctrine->getRepository(ReminderUser::class)->addEmail($user->getEmail(),$user->getUsername(), $request->getLocale());
$mailchimp->addUser($user);
$security->login($user, 'security.authenticator.form_login.main');
return $this->redirectToRoute('tunnel_simple_confirm');
}
return $this->renderForm('tunnel/simple/register.html.twig', [
'form' => $form
]);
}
#[Route('/inscription/essai.html', name: 'tunnel_simple_confirm')]
public function registerSimpleConfirm(Request $request): Response
{
//confirmer l'inscription
//proposer abonnement ou tester gratuitement
$user = $this->getUser();
return $this->render('tunnel/simple/confirm.html.twig', [
'user' => $user,
]);
}
#[Route('/inscription/inscription.html', name: 'tunnel_register')]
public function register(Request $request, UserPasswordHasherInterface $passwordHasher, MailchimpAPI $mailchimp): Response
{
$session = $request->getSession();
$user = self::findUser($this, $session);
//$user = $this->getUser();
if($user instanceof User)
{
//on passe la phase registration
return $this->redirectToRoute('tunnel_subscription_choice');
//return $this->redirectToRoute('tunnel_billing');
} else {
//ON SIMPLIFIE L'INSCRIPTION !!
return $this->redirectToRoute('tunnel_simple_register');
}
$user = new User(); //on crée un user vide pour récupérer les informations
$form = $this->createFormBuilder($user, ['validation_groups' => ['Default', 'registration'], 'translation_domain' => 'tunnel'])
->add('username', TextType::class, ['label' => 'Choisissez un pseudo'])
->add('email', RepeatedType::class, [
'type' => EmailType::class,
'required' => true,
'first_options' => ['label' => 'Entrez votre e-mail'],
'second_options' => ['label' => 'Répétez votre e-mail'],
])
//->add('emailConfirm', EmailType::class, ['label' => 'Répétez votre e-mail'])
->add('plainPassword', PasswordType::class, ['attr' => ['class' => 'w-75'], 'label' => 'Choisissez un mot de passe'])
->add('submit', SubmitType::class, ['label' => 'Continuer'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$user = $form->getData();
$email = $user->getEmail();
$password = $user->getPlainPassword();
//hasher le password
$hashedPassword = $passwordHasher->hashPassword(
$user,
$password
);
$user->setPassword($hashedPassword);
$currentUser = $this->doctrine->getRepository(UserTempData::class)->findOneByEmail($email);
if($currentUser == null)
$currentUser = new UserTempData();
$currentUser->setUsername($user->getUsername());
$currentUser->setEmail($user->getEmail());
$currentUser->setPassword($hashedPassword);
$currentUser->setLocale($request->getLocale());
$session = $request->getSession();
$countryCode = $this->getUserIsoCode($request, $session);
$defaultCountry = $this->doctrine->getRepository(Country::class)->findOneByIsoCode($countryCode);
if(!$defaultCountry || $countryCode == "FR")
$defaultCountry = $this->doctrine->getRepository(Country::class)->findOneByCanonicalName('france-metropolitaine');
//$currentUser->setSiteUrl(IpToCountry::getExtension($session));
$currentUser->setEcountry($defaultCountry);
$this->entityManager->persist($currentUser);
$this->entityManager->flush();
$session = $request->getSession();
$session->set('user_data_id',$currentUser->getId());
//FB API !
$event_id = $this->sendFBMsgRegister($user);
$session->set('reg_event_id',$event_id);
$this->doctrine->getRepository(ReminderUser::class)->addEmail($user->getEmail(),$user->getUsername(), $request->getLocale());
$mailchimp->addTempUser($currentUser);
//si on est passé par la page prix.html
$forceChoice = $session->get('forceChoice', false);
if($forceChoice) {
//cela ne fonctionne qu'une fois
$session->set('forceChoice', false);
return $this->redirectToRoute('tunnel_billing');
} else {
return $this->redirectToRoute('tunnel_subscription_choice');
}
}
return $this->renderForm('tunnel/register.html.twig', [
'form' => $form
]);
}
#[Route('/inscription/facturation.html', name: 'tunnel_billing')]
public function billing(Request $request): Response
{
$session = $request->getSession();
$currentUser = self::findUser($this, $session);
if($currentUser == null)
{
//aucun user connecté ou tempUser
return $this->redirectToRoute('tunnel_register');
}
$user = new User(); //on crée un user vide pour récupérer les informations
$countryCode = $this->getUserIsoCode($request, $session);
$defaultCountry = $this->doctrine->getRepository(Country::class)->findOneByIsoCode($countryCode);
if(!$defaultCountry || $countryCode == "FR")
$defaultCountry = $this->doctrine->getRepository(Country::class)->findOneByCanonicalName('france-metropolitaine');
$user->setFirstName($currentUser->getFirstName());
$user->setLastName($currentUser->getLastName());
$user->setAddress($currentUser->getAddress());
$user->setZipCode($currentUser->getZipCode());
$user->setCity($currentUser->getCity());
$user->setEcountry($currentUser->getEcountry());
$user->setECountry($defaultCountry);
$form = $this->createFormBuilder($user, ['validation_groups' => ['facturation'], 'translation_domain' => 'tunnel'])
->add('firstName', TextType::class, ['label' => 'Nom'])
->add('lastName', TextType::class, ['label' => 'Prénom'])
->add('address', TextType::class, ['label' => 'Adresse'])
->add('zipCode', TextType::class, ['label' => 'Code postal'])
->add('city', TextType::class, ['label' => 'Ville'])
->add('ecountry', EntityType::class, ['class' => Country::class, 'label' => 'Pays', 'choice_label' => 'canonicalName', 'choice_translation_domain' => 'countries'])
->add('submit', SubmitType::class, ['label' => 'Continuer'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$user = $form->getData();
$currentUser->setFirstName($user->getFirstName());
$currentUser->setLastName($user->getLastName());
$currentUser->setAddress($user->getAddress());
$currentUser->setZipCode($user->getZipCode());
$currentUser->setCity($user->getCity());
$currentUser->setEcountry($user->getEcountry());
$this->entityManager->flush();
return $this->redirectToRoute('tunnel_payment');
}
return $this->renderForm('tunnel/billing.html.twig', [
'form' => $form
]);
}
#[Route('/inscription/reglement.html', name: 'tunnel_payment')]
public function payment(Request $request): Response
{
$session = $request->getSession();
$currentUser = self::findUser($this, $session);
if($currentUser == null)
{
//aucun user connecté ou tempUser
return $this->redirectToRoute('tunnel_register');
}
$type = 'cb';
if($request->getMethod() == 'POST')
{
$type = $request->get('type','cb');
}
$currentChoice = $session->get('formule', null);
if($currentChoice == null)
{
return $this->redirectToRoute('default_price');
}
$payment_id = $this->doctrine->getRepository(PaymentMethod::class)->getChoiceSubscription($currentChoice,$session);
$paymentMethod = $this->doctrine->getRepository(PaymentMethod::class)->findOneById($payment_id);
if($paymentMethod != null && $paymentMethod->getType() != PaymentMethod::TYPE_CODECADEAU)
{
$prixBase = $prix = $paymentMethod->getValeur();
$reduction = self::getReduction($session, $this->doctrine);
$url_promo_code = $session->get('url_promo_code',false);
$prix = self::getPriceReduction($paymentMethod,$prix,$reduction,$url_promo_code);
if(!$url_promo_code || ($url_promo_code && $paymentMethod->getMontant() != 1)){
$displayReduction = $reduction !== false;
}else{
$displayReduction = false;
}
$montant = $paymentMethod->getMontant();
$prixMois = round($prix / $montant, 2, PHP_ROUND_HALF_DOWN);
$prix = number_format($prix, 2, ',', ' ');
$prixBase = number_format($prixBase, 2, ',', ' ');
$prixMois = number_format($prixMois, 2, ',', ' ');
$currency = IpToCountry::getCurrency($session);
$time = $paymentMethod->getMontant();
return $this->render('tunnel/payment.html.twig', [
'user' => $currentUser,
'paymentMethod' => $session->get('formule'),
'paymentType' => $paymentMethod->getType(),
'paymentDuration' => $montant,
'currency' => $currency,
'nom' => $currentUser->getLastName(),
'prenom' => $currentUser->getFirstName(),
'adresse' => $currentUser->getAddress(),
'ville' => $currentUser->getCity(),
'zipCode' => $currentUser->getZipCode(),
'pays' => $currentUser->getCountry(),
'schoolName' => $currentUser->getSchoolName(),
'prix' => $prix,
'prixBase' => $prixBase,
'prixMois' => $prixMois,
'time' => $time,
'libelle' => $paymentMethod->getName(),
'displayReduction' => $displayReduction,
'type' => $type,
]);
}
}
#[Route('/delayed_payment.html', name: 'delayed_payment')]
public function bankTransferSubscription(Request $request): Response
{
$session = $request->getSession();
$currentUser = self::findUser($this, $session);
if($currentUser == null)
{
//aucun user connecté ou tempUser
return $this->redirectToRoute('tunnel_register');
}
$formule = $request->get('formule',0);
$type = $request->get('paymentMethod',0);
$isTransfer = $request->get('transfer',null) != null;
$payment_id = 0;
$payment_id = $this->doctrine->getRepository(PaymentMethod::class)->getChoiceSubscription($formule,$session);
$paymentMethod = $this->doctrine->getRepository(PaymentMethod::class)->findOneById($payment_id);
if($paymentMethod != null)
{
switch ($type){
case "cheque":
$route = 'tunnel_subscription_check';
break;
case "virement":
$route = 'tunnel_subscription_transfer';
break;
/*case "paiement-cadhoc":
$route = 'envoi-cadhoc';
$type = 'cadhoc';
break;*/
}
$time = '' . time() . '';
$sReference = base_convert($currentUser->getId(), 10, 36) . '-' . base_convert($time, 10, 36);
$sMontant = $paymentMethod->getValeur();
$reduction = self::getReduction($session, $this->doctrine);
$displayReduction = $reduction !== false;
$url_promo_code = $session->get('url_promo_code',false);
$sMontant = $this->getPriceReduction($paymentMethod,$sMontant,$reduction,$url_promo_code);
$isTempUser = !($currentUser instanceof User);
$searchParam = $isTempUser ? 'userData' : 'user';
//pour éviter de créer des payment en masse, on cherche un paiement précédent non validé fait par la personne
$payment = $this->doctrine->getRepository(UserPayment::class)->findOneBy([
$searchParam => $currentUser->getId(),
'type' => $type,
'waitingPayment' => true
]);
if($payment == null)
$payment = new UserPayment();
if($isTempUser)
$payment->setUserData($currentUser);
else
$payment->setUser($currentUser);
$payment->setLocale($currentUser->getLocale());
$payment->setECountry($currentUser->getECountry());
$payment->setFirstName($currentUser->getFirstName());
$payment->setLastName($currentUser->getLastName());
$payment->setMontant($sMontant);
$payment->setMontantReel($sMontant/$paymentMethod->getBaseReel());
$payment->setPayment($paymentMethod);
$payment->setReference($sReference);
$payment->setWaitingPayment(true);
$payment->setIsCredit(false);
$payment->setCreatedAt(new \DateTimeImmutable());
$payment->setType($type);
$payment->setOccurence(1);
$payment->setStatut("waiting");
$code = $this->doctrine->getRepository(PromoCode::class)->getPromoCode($session->get('promo_code',null));
$payment->setPromoCode($code);
$this->entityManager->persist($payment);
$this->entityManager->flush();
$country_code = $session->get('payment_code');
$currency = $this->getCurrency($country_code);
return $this->render('tunnel/form_cheque.html.twig', [
'montant' => $sMontant,
'time' => $paymentMethod->getMontant(),
'reference' => $sReference,
'currency' => $currency,
'route' => $route,
]);
}
}
#[Route('/virement-bancaire.html', name: 'tunnel_subscription_transfer')]
public function sendBankTransfer(Request $request, MailingTransac $mailer): Response
{
$session = $request->getSession();
$currentUser = self::findUser($this, $session);
if($currentUser == null)
{
//aucun user connecté ou tempUser
return $this->redirectToRoute('tunnel_register');
}
$montant = $request->get('montant',0);
$currency = $request->get('currency',"");
$reference = $request->get('reference',"");
$time = intval($request->get('time',0));
$montant = number_format($montant,2);
$montant = str_replace(".", ",", $montant);
if($reference != '' && $session->get('ref_mail',null) != $reference)
{
$session->set('ref_mail',$reference);
$mailer->sendBankTransferMail($currentUser->getEmail(),$montant,$currency,$reference,$time,"",$currentUser);
}
return $this->render('tunnel/sendBankTransfer.html.twig', [
'montant' => $montant,
'reference' => $reference,
'time' => $time,
'currency' => $currency,
]);
}
#[Route('/envoi-cheque.html', name: 'tunnel_subscription_check')]
public function sendCheck(Request $request, MailingTransac $mailer): Response
{
$session = $request->getSession();
$currentUser = self::findUser($this, $session);
if($currentUser == null)
{
//aucun user connecté ou tempUser
return $this->redirectToRoute('tunnel_register');
}
$montant = $request->get('montant',0);
$currency = $request->get('currency',0);
$reference = $request->get('reference',"");
$time = intval($request->get('time',0));
//$time = $this->transformTime($time);
$montant = number_format($montant,2);
$montant = str_replace(".", ",", $montant);
if($reference != '' && $session->get('ref_mail',null) != $reference){
$session->set('ref_mail',$reference);
$mailer->sendChequeMail($currentUser->getEmail(),$montant,$currency,$reference,$time,"",$currentUser);
}
return $this->render('tunnel/sendCheque.html.twig', [
'montant' => $montant,
'reference' => $reference,
'time' => $time,
'currency' => $currency,
]);
}
#[Route('/abonnement-cb-reussi.html', name: 'tunnel_subscription_cb')]
#[Route('/abonnement-reussi.html', name: 'tunnel_subscription_confirmed')]
#[Route('/abonnement-paypal-reussi.html', name: 'tunnel_subscription_paypal')]
public function subscriptionConfirmed(Request $request): Response
{
$session = $request->getSession();
$currentUser = $this->getUser();
$value = 0;
$currency = 'EUR';
if($currentUser instanceof User && $currentUser->getSubscriptionConfirmed() != null)
{
$payment = $this->doctrine->getRepository(UserPayment::class)->getLastConfirmedByUser($currentUser->getId(),false);
if($payment != null)
{
$value = intval(round($payment->getMontantReel()));
$method = $payment->getPayment();
$currency = $method->getCurrency();
}
}
return $this->render('tunnel/subscriptionConfirmed.html.twig', [
'currency' => $currency,
'value' => $value,
'user' => $currentUser,
]);
}
#[Route('/inscription/abonnement.html', name: 'tunnel_subscription_choice')]
public function chooseSubscription(Request $request): Response
{
$session = $request->getSession();
if ($request->getMethod() == 'POST')
{
if($request->get('subscription',null) != null)
{
$session->set('forceChoice', true);
$session->set('formule', $request->get('subscription',null));
$currentUser = self::findUser($this, $session);
$this->sendFBMsgInitCheckout($currentUser);
return $this->redirectToRoute('tunnel_billing');
}
}
self::detectCountry($request);
self::setPromoCode($request, $session, $this->doctrine);
$default = 'choice3';
$choice = $session->get('formule', $default);
$choice = ($choice) ? $choice : $default;
$country_code = $session->get('payment_code');
$url_promo_code = $session->get('url_promo_code',false);
$promoCode = $session->get('promo_code',false);
$reduction = self::getReduction($session, $this->doctrine);
$displayReduction = $reduction !== false;
$prices = $this->doctrine->getRepository(PaymentMethod::class)->getPrices($country_code,$reduction,$url_promo_code);
$currency = $this->getCurrency($country_code);
return $this->render('tunnel/price.html.twig', [
'prices' => $prices,
'currency' => $currency,
'choice' => $choice,
'displayReduction' => $displayReduction,
'codeReduction' => $promoCode,
'montantReduction' => floor($reduction),
'route' => 'tunnel_subscription_choice'
//'isPromoUrl' => $url_promo_code
]);
}
#[Route('/prix.html', name: 'default_price')]
public function prices(Request $request): Response
{
$session = $request->getSession();
if ($request->getMethod() == 'POST')
{
if($request->get('subscription',null) != null)
{
$session->set('forceChoice', true);
$session->set('formule', $request->get('subscription',null));
$currentUser = self::findUser($this, $session);
if($currentUser instanceof User) //tester si on est déjà enregistré ou pas
{
$this->sendFBMsgInitCheckout($currentUser);
return $this->redirectToRoute('tunnel_billing');
} else {
$this->sendFBMsgInitCheckout($currentUser);
return $this->redirectToRoute('tunnel_register');
}
}
}
self::detectCountry($request);
self::setPromoCode($request, $session, $this->doctrine);
$default = 'choice3';
$choice = $session->get('formule', $default);
$choice = ($choice) ? $choice : $default;
$country_code = $session->get('payment_code');
$url_promo_code = $session->get('url_promo_code',false);
$promoCode = $session->get('promo_code',false);
$reduction = self::getReduction($session, $this->doctrine);
$displayReduction = $reduction !== false;
$prices = $this->doctrine->getRepository(PaymentMethod::class)->getPrices($country_code,$reduction,$url_promo_code);
$currency = $this->getCurrency($country_code);
return $this->render('tunnel/price.html.twig', [
'prices' => $prices,
'currency' => $currency,
'choice' => $choice,
'displayReduction' => $displayReduction,
'codeReduction' => $promoCode,
'montantReduction' => floor($reduction),
'route' => 'default_price'
//'isPromoUrl' => $url_promo_code
]);
}
#[Route('/pop-cg.html', name: 'tunnel_cg')]
public function getContentCG(Request $request)
{
$locale = $request->query->get('locale', 'fr');
$pageRepository = $this->doctrine->getRepository(Page::class);
if( $content = $pageRepository->getI18nPageByRoute('cgv', $locale))
{
return new Response($content->getContent());
}else{
throw $this->createNotFoundException();
}
}
static function getPriceReduction($paymentMethod,$price,$reduction, $url_promo_code){
if($reduction !== false)
{
//si on est pas arrivé via une url promo ou que l'on a choisit le paiement a 6 mois
if(!$url_promo_code || ($url_promo_code && $paymentMethod->getMontant() != 1)){
if(is_float($reduction)){
$price = round($price * (1 - $reduction/100), 2, PHP_ROUND_HALF_DOWN);
}else{
$price = $paymentMethod->getValeurPromo();
}
}
}
return $price;
}
static function getReduction($session, $doctrine)
{
if($session != null){
$promoCode = $session->get('promo_code',false);
if($promoCode != false){
$code = $doctrine->getRepository(PromoCode::class)->getPromoCode($promoCode);
if($code != null) {
return $code->getReduction();
}
}
}
return false;
}
protected function getCurrency($country_code){
switch($country_code){
case 'CA':
$currency = '$CAN';
break;
case 'CH':
$currency = "CHF";
break;
case 'MA':
$currency = "MAD";
break;
default:
$currency = "€";
break;
}
return $currency;
}
protected function sendFBMsgInitCheckout($user) {
try {
$url = $this->generateUrl('routeName', [], UrlGenerator::ABSOLUTE_URL);
$fb = new FacebookSAPI($this->getParameter('fb.business_api'), $this->getParameter('fb.pixel_id'));
$data = $fb->createCheckoutData($user, $url);
$fb->sendRequest($data);
} catch(\Exception $e) {
}
}
protected function sendFBMsgRegister($user) {
try {
$url = $this->generateUrl('tunnel_register', [], UrlGenerator::ABSOLUTE_URL);
$fb = new FacebookSAPI($this->getParameter('fb.business_api'), $this->getParameter('fb.pixel_id'));
$data = $fb->createRegisterData($user, $url);
$fb->sendRequest($data);
return $data["event_id"];
} catch(\Exception $e) {
}
}
}