From e41602de49643a0f646df834c87b42b3b2939135 Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Wed, 3 Dec 2025 17:51:58 +0100 Subject: [PATCH] =?UTF-8?q?```=20=E2=9C=A8=20feat(PaymentClient):=20Cr?= =?UTF-8?q?=C3=A9e=20une=20fonction=20pour=20cr=C3=A9er=20des=20abonnement?= =?UTF-8?q?s=20Stripe.=20=F0=9F=8E=A8=20refactor(prestation.twig):=20Cache?= =?UTF-8?q?=20le=20bloc=20de=20tarification=20EPage.=20=E2=9E=95=20feat(Pa?= =?UTF-8?q?yAbonementCommand):=20Cr=C3=A9e=20une=20commande=20pour=20initi?= =?UTF-8?q?aliser=20les=20abonnements.=20=F0=9F=9A=80=20chore(ansible/play?= =?UTF-8?q?book.yml):=20Ajoute=20l'ex=C3=A9cution=20de=20la=20commande=20e?= =?UTF-8?q?cosplay:abonement.=20```?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/playbook.yml | 5 +++ src/Command/PayAbonementCommand.php | 58 ++++++++++++++++++++++++++ src/Service/Payments/PaymentClient.php | 22 ++++++++++ templates/pages/prestation.twig | 2 +- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/Command/PayAbonementCommand.php diff --git a/ansible/playbook.yml b/ansible/playbook.yml index d50ce1a..284ee82 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -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 diff --git a/src/Command/PayAbonementCommand.php b/src/Command/PayAbonementCommand.php new file mode 100644 index 0000000..02e6d74 --- /dev/null +++ b/src/Command/PayAbonementCommand.php @@ -0,0 +1,58 @@ +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; + } +} diff --git a/src/Service/Payments/PaymentClient.php b/src/Service/Payments/PaymentClient.php index b61a4ce..d8a8502 100644 --- a/src/Service/Payments/PaymentClient.php +++ b/src/Service/Payments/PaymentClient.php @@ -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; + + } } diff --git a/templates/pages/prestation.twig b/templates/pages/prestation.twig index 31ceef3..78f26aa 100644 --- a/templates/pages/prestation.twig +++ b/templates/pages/prestation.twig @@ -285,7 +285,7 @@ {# BLOC DE TARIFICATION EPage (CARTE UNIQUE AVEC SÉLECTEUR) - CENTRÉ ET RESPONSIVE #} -
+