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);
}
// 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') {
$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) {

View File

@ -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();

View File

@ -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'),
])
);
}