dev push
This commit is contained in:
parent
a444fa949c
commit
42e3400f2e
|
@ -6,11 +6,39 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
|
||||
class BillingController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/bluesquare/billing-bundle/webhook", name="bluesquare.billing_bundle.webhook")
|
||||
*/
|
||||
public function webhook()
|
||||
public function webhookAction()
|
||||
{
|
||||
\Stripe\Stripe::setApiKey($this->container->get('stripe_api_key_secret'));
|
||||
|
||||
// You can find your endpoint's secret in your webhook settings
|
||||
$endpoint_secret = $this->container->get('stripe_webhook_key');
|
||||
|
||||
$payload = @file_get_contents('php://input');
|
||||
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
|
||||
$event = null;
|
||||
|
||||
try {
|
||||
$event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
|
||||
|
||||
} catch(\UnexpectedValueException $e) {
|
||||
// Invalid payload
|
||||
file_put_contents("/tmp/test_stripe", json_encode($e->getMessage()));
|
||||
exit();
|
||||
} catch(\Stripe\Error\SignatureVerification $e) {
|
||||
// Invalid signature
|
||||
file_put_contents("/tmp/test_stripe", json_encode($e->getMessage()));
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle the checkout.session.completed event
|
||||
if ($event->type == 'checkout.session.completed') {
|
||||
$session = $event->data->object;
|
||||
|
||||
// Fulfill the purchase...
|
||||
file_put_contents("/tmp/test_stripe", json_encode($session));
|
||||
//handle_checkout_session($session);
|
||||
}
|
||||
|
||||
return $this->json("OK", 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,36 @@
|
|||
|
||||
namespace Bluesquare\BillingBundle\Service;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class BillingSrv
|
||||
{
|
||||
public function createPurchase($arr)
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
public function createPurchase($items)
|
||||
{
|
||||
$apiKey = $this->container->getParameter('stripe_api_key_secret');
|
||||
|
||||
\Stripe\Stripe::setApiKey($apiKey);
|
||||
|
||||
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',
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue