From db7a52970ace36e1ce5cbd0989996c43839859b1 Mon Sep 17 00:00:00 2001 From: cbeauvoi Date: Mon, 22 Jul 2019 11:28:50 +0200 Subject: [PATCH] debug dev router --- BillingBundle/Resources/config/services.yaml | 1 + BillingBundle/Service/BillingSrv.php | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/BillingBundle/Resources/config/services.yaml b/BillingBundle/Resources/config/services.yaml index a10ebea..44bf68f 100644 --- a/BillingBundle/Resources/config/services.yaml +++ b/BillingBundle/Resources/config/services.yaml @@ -4,6 +4,7 @@ services: public: true arguments: $container: "@service_container" + $env: '%kernel.environment%' Bluesquare\BillingBundle\Controller\: resource: "../../Controller/*" diff --git a/BillingBundle/Service/BillingSrv.php b/BillingBundle/Service/BillingSrv.php index 28e01e1..c668c04 100644 --- a/BillingBundle/Service/BillingSrv.php +++ b/BillingBundle/Service/BillingSrv.php @@ -7,10 +7,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class BillingSrv { private $container; + private $url_prefix; - public function __construct(ContainerInterface $container) + public function __construct(ContainerInterface $container, $env) { $this->container = $container; + + $this->url_prefix = $env->isDebug() ? $this->container->getParameter('dev_ngrok_prefix') + : $container->get('router')->getContext()->getBaseUrl(); } private function setApiKey() @@ -28,15 +32,13 @@ class BillingSrv foreach ($items as $item) $line_items[] = $cbFormatter($item); - $ngrok_url = $this->container->getParameter('dev_ngrok_prefix'); - return ( \Stripe\Checkout\Session::create([ 'customer' => $customer, 'payment_method_types' => $this->container->getParameter('payment_method'), 'line_items' => $line_items, - 'success_url' => $ngrok_url . $this->container->getParameter('stripe_success_url'), - 'cancel_url' => $ngrok_url . $this->container->getParameter('stripe_cancel_url'), + 'success_url' => $this->url_prefix . $this->container->getParameter('stripe_success_url'), + 'cancel_url' => $this->url_prefix . $this->container->getParameter('stripe_cancel_url'), ]) ); }