```
✨ feat(PaymentClient): Crée une fonction pour créer des abonnements Stripe. 🎨 refactor(prestation.twig): Cache le bloc de tarification EPage. ➕ feat(PayAbonementCommand): Crée une commande pour initialiser les abonnements. 🚀 chore(ansible/playbook.yml): Ajoute l'exécution de la commande ecosplay:abonement. ```
This commit is contained in:
@@ -227,6 +227,11 @@
|
||||
- "{{ path }}/public/media"
|
||||
- "{{ path }}/public/storage"
|
||||
- "{{ path }}/public/tmp"
|
||||
- name: Exécuter ecosplay:abonement dans le répertoire de l application
|
||||
ansible.builtin.command: php bin/console ecosplay:abonement
|
||||
become: false
|
||||
args:
|
||||
chdir: "{{ path }}"
|
||||
- name: Exécuter app:cloudflare:purge dans le répertoire de l application
|
||||
ansible.builtin.command: php bin/console app:cloudflare:purge
|
||||
become: false
|
||||
|
||||
58
src/Command/PayAbonementCommand.php
Normal file
58
src/Command/PayAbonementCommand.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Abonements;
|
||||
use App\Service\Payments\PaymentClient;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(name: 'ecosplay:abonement')]
|
||||
class PayAbonementCommand extends Command
|
||||
{
|
||||
|
||||
public function __construct(protected readonly EntityManagerInterface $entityManager,private readonly PaymentClient $paymentClient,?string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title("EPage - Abonement");
|
||||
$abos =[
|
||||
['name'=>'Epage 1 Mois','price'=>5,'time'=>1],
|
||||
['name'=>'Epage 2 Mois','price'=>8,'time'=>2],
|
||||
['name'=>'Epage 3 Mois','price'=>12,'time'=>3],
|
||||
['name'=>'Epage 6 Mois','price'=>25,'time'=>6],
|
||||
['name'=>'Epage 12 Mois','price'=>40,'time'=>12],
|
||||
];
|
||||
foreach ($abos as $abos) {
|
||||
$abo = $this->entityManager->getRepository(Abonements::class)->findOneBy(['name'=>$abos['name']]);
|
||||
if(!$abo instanceof Abonements){
|
||||
$abo = new Abonements();
|
||||
$abo->setName($abos['name']);
|
||||
$abo->setCreateAt(new \DateTimeImmutable());
|
||||
$abo->setIsActif(true);
|
||||
$abo->setTva(1);
|
||||
$abo->setDuration($abos['time']);
|
||||
}
|
||||
$abo->setPriceHt($abos['price']);
|
||||
$abo->setPriceTtc($abos['price'] *$abo->getTva() );
|
||||
$abo->setUpdateAt(new \DateTimeImmutable());
|
||||
if($abo->getStripeId() == null){
|
||||
$stripeProduct = $this->paymentClient->createAbos($abo);
|
||||
$abo->setStripeId($stripeProduct);
|
||||
}
|
||||
$this->entityManager->persist($abo);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -81,4 +81,26 @@ class PaymentClient
|
||||
|
||||
return $checkoutSession;
|
||||
}
|
||||
|
||||
public function createAbos(\App\Entity\Abonements $abo)
|
||||
{
|
||||
$stripe = new \Stripe\StripeClient($_ENV['STRIPE_SK']);
|
||||
$product = $stripe->products->create([
|
||||
'name' => $abo->getName(),
|
||||
'active' => true,
|
||||
'description' => $abo->getName(),
|
||||
'default_price_data' => [
|
||||
'currency' => 'EUR',
|
||||
'recurring' => [
|
||||
'interval' => 'month',
|
||||
'interval_count' => $abo->getDuration(),
|
||||
],
|
||||
'tax_behavior' => 'unspecified',
|
||||
'unit_amount' => $abo->getPriceTtc()*100,
|
||||
|
||||
],
|
||||
]);
|
||||
return $product->id;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@
|
||||
</div>
|
||||
|
||||
{# BLOC DE TARIFICATION EPage (CARTE UNIQUE AVEC SÉLECTEUR) - CENTRÉ ET RESPONSIVE #}
|
||||
<div class="mt-16 text-center">
|
||||
<div class="mt-16 text-center" style="display:none;">
|
||||
<h3 class="text-4xl font-extrabold text-gray-800 mb-8">{{ 'page.presentation.pricing.choose_period'|trans }}</h3>
|
||||
|
||||
<div class="max-w-xl mx-auto p-6 sm:p-8 bg-white border-4 border-red-500 rounded-3xl shadow-2xl">
|
||||
|
||||
Reference in New Issue
Block a user