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 #} -