fix to redirect request on dev controller

This commit is contained in:
Cyprian Beauvois 2019-07-16 18:08:09 +02:00
parent 5453a69312
commit e08c583b72
4 changed files with 15 additions and 23 deletions

View File

@ -18,11 +18,4 @@ class BillingBundle extends Bundle
{ {
parent::build($container); parent::build($container);
} }
// public function getContainerExtension()
// {
// if (null === $this->extension)
// $this->extension = new StorageExtension();
// return $this->extension;
// }
} }

View File

@ -33,10 +33,7 @@ class BillingController extends AbstractController
if ($event->type == 'checkout.session.completed') { if ($event->type == 'checkout.session.completed') {
$session = $event->data->object; $session = $event->data->object;
// Fulfill the purchase... return $this->redirectToRoute($this->container->getParameter('payment_confirmation_route'), $session);
if (file_put_contents("/tmp/return_stripe_session", json_encode($session)) !== false)
return $this->json("OK", 200);
return $this->json("KO", 500);
} }
} catch(\UnexpectedValueException $e) { } catch(\UnexpectedValueException $e) {

View File

@ -16,6 +16,10 @@ class Configuration implements ConfigurationInterface
->scalarNode('stripe_api_key_pub')->end() ->scalarNode('stripe_api_key_pub')->end()
->scalarNode('stripe_api_key')->end() ->scalarNode('stripe_api_key')->end()
->scalarNode('stripe_webhook_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()
->end(); ->end();

View File

@ -13,25 +13,23 @@ class BillingSrv
$this->container = $container; $this->container = $container;
} }
public function createPurchase($items) public function createPurchase($user_email, $items, $cbFormatter)
{ {
$apiKey = $this->container->getParameter('stripe_api_key_secret'); $apiKey = $this->container->getParameter('stripe_api_key_secret');
\Stripe\Stripe::setApiKey($apiKey); \Stripe\Stripe::setApiKey($apiKey);
$line_items = [];
foreach ($items as $item) $line_items = $cbFormatter($item);
return ( return (
\Stripe\Checkout\Session::create([ \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'], 'customer_email' => $user_email,
'line_items' => [[ 'payment_method_types' => $this->container->getParameter('payment_method'),
'name' => 'T-shirt', 'line_items' => $line_items,
'description' => 'Comfortable cotton t-shirt', 'success_url' => 'http://18d049f8.ngrok.io' . $this->container->getParameter('stripe_success_url'),
'images' => ['https://example.com/t-shirt.png'], 'cancel_url' => 'http://18d049f8.ngrok.io' . $this->container->getParameter('stripe_cancel_url'),
'amount' => 500,
'currency' => 'eur',
'quantity' => 1,
]],
'success_url' => 'http://18d049f8.ngrok.io/redirected',
'cancel_url' => 'http://18d049f8.ngrok.io/cancel',
]) ])
); );
} }