diff --git a/BillingBundle/BillingBundle.php b/BillingBundle/BillingBundle.php index 993335b..20f1bf7 100644 --- a/BillingBundle/BillingBundle.php +++ b/BillingBundle/BillingBundle.php @@ -18,11 +18,4 @@ class BillingBundle extends Bundle { parent::build($container); } - -// public function getContainerExtension() -// { -// if (null === $this->extension) -// $this->extension = new StorageExtension(); -// return $this->extension; -// } } diff --git a/BillingBundle/Controller/BillingController.php b/BillingBundle/Controller/BillingController.php index 0184922..1cb40d5 100644 --- a/BillingBundle/Controller/BillingController.php +++ b/BillingBundle/Controller/BillingController.php @@ -33,10 +33,7 @@ class BillingController extends AbstractController if ($event->type == 'checkout.session.completed') { $session = $event->data->object; - // Fulfill the purchase... - if (file_put_contents("/tmp/return_stripe_session", json_encode($session)) !== false) - return $this->json("OK", 200); - return $this->json("KO", 500); + return $this->redirectToRoute($this->container->getParameter('payment_confirmation_route'), $session); } } catch(\UnexpectedValueException $e) { diff --git a/BillingBundle/DependencyInjection/Configuration.php b/BillingBundle/DependencyInjection/Configuration.php index 9656723..3922d94 100644 --- a/BillingBundle/DependencyInjection/Configuration.php +++ b/BillingBundle/DependencyInjection/Configuration.php @@ -16,6 +16,10 @@ class Configuration implements ConfigurationInterface ->scalarNode('stripe_api_key_pub')->end() ->scalarNode('stripe_api_key')->end() ->scalarNode('stripe_webhook_key')->end() + ->scalarNode('stripe_success_url')->end() + ->scalarNode('stripe_cancel_url')->end() + ->scalarNode('payment_method')->end() + ->scalarNode('payment_confirmation_route')->end() ->end() ->end(); diff --git a/BillingBundle/Service/BillingSrv.php b/BillingBundle/Service/BillingSrv.php index e713734..2f4cd3a 100644 --- a/BillingBundle/Service/BillingSrv.php +++ b/BillingBundle/Service/BillingSrv.php @@ -13,25 +13,23 @@ class BillingSrv $this->container = $container; } - public function createPurchase($items) + public function createPurchase($user_email, $items, $cbFormatter) { $apiKey = $this->container->getParameter('stripe_api_key_secret'); \Stripe\Stripe::setApiKey($apiKey); + $line_items = []; + + foreach ($items as $item) $line_items = $cbFormatter($item); + return ( \Stripe\Checkout\Session::create([ - 'payment_method_types' => ['card'], - 'line_items' => [[ - 'name' => 'T-shirt', - 'description' => 'Comfortable cotton t-shirt', - 'images' => ['https://example.com/t-shirt.png'], - 'amount' => 500, - 'currency' => 'eur', - 'quantity' => 1, - ]], - 'success_url' => 'http://18d049f8.ngrok.io/redirected', - 'cancel_url' => 'http://18d049f8.ngrok.io/cancel', + 'customer_email' => $user_email, + 'payment_method_types' => $this->container->getParameter('payment_method'), + 'line_items' => $line_items, + 'success_url' => 'http://18d049f8.ngrok.io' . $this->container->getParameter('stripe_success_url'), + 'cancel_url' => 'http://18d049f8.ngrok.io' . $this->container->getParameter('stripe_cancel_url'), ]) ); }