Compare commits
17 Commits
Author | SHA1 | Date |
---|---|---|
Cyprian Beauvois | 22f3393b09 | |
Cyprian Beauvois | 199b45508d | |
Loann | ae6c0f383c | |
Cyprian Beauvois | f71c5da2c0 | |
Cyprian Beauvois | ae6f621bf5 | |
Cyprian Beauvois | 44ab2846df | |
Cyprian Beauvois | 3553562f62 | |
Cyprian Beauvois | 8d7cdd1fe2 | |
Cyprian Beauvois | 2832a953b9 | |
Cyprian Beauvois | f7cffe894a | |
Cyprian Beauvois | 90d2ebddcc | |
Cyprian Beauvois | db7a52970a | |
Cyprian Beauvois | a553d74f48 | |
Cyprian Beauvois | 8578b07f7e | |
Cyprian Beauvois | 488017579f | |
Cyprian Beauvois | 35a0d8f705 | |
Cyprian Beauvois | 251b5144a1 |
|
@ -37,7 +37,7 @@ class BillingController extends AbstractController
|
||||||
|
|
||||||
list($service, $function) = explode('::', $serviceToCall);
|
list($service, $function) = explode('::', $serviceToCall);
|
||||||
|
|
||||||
$srv = new $service();
|
$srv = $this->container->get($service);
|
||||||
|
|
||||||
$srv->{$function}($session);
|
$srv->{$function}($session);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
services:
|
services:
|
||||||
Bluesquare\BillingBundle\Service\:
|
Bluesquare\BillingBundle\Service\:
|
||||||
resource: "../../Service/*"
|
resource: "../../Service/*"
|
||||||
arguments:
|
public: true
|
||||||
$container: "@service_container"
|
arguments: ["@service_container","@doctrine.orm.entity_manager",'%kernel.environment%']
|
||||||
|
|
||||||
Bluesquare\BillingBundle\Controller\:
|
Bluesquare\BillingBundle\Controller\:
|
||||||
resource: "../../Controller/*"
|
resource: "../../Controller/*"
|
||||||
|
|
|
@ -2,37 +2,87 @@
|
||||||
|
|
||||||
namespace Bluesquare\BillingBundle\Service;
|
namespace Bluesquare\BillingBundle\Service;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
class BillingSrv
|
class BillingSrv
|
||||||
{
|
{
|
||||||
private $container;
|
private $container;
|
||||||
|
private $manager;
|
||||||
|
private $url_prefix;
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container, EntityManager $manager, $env)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
|
|
||||||
|
$this->manager = $manager;
|
||||||
|
|
||||||
|
$ngrok_prefix = $this->container->getParameter('dev_ngrok_prefix');
|
||||||
|
|
||||||
|
$base_url = $this->container->getParameter('prod_prefix');
|
||||||
|
|
||||||
|
$this->url_prefix = ($env == "dev" && !empty($ngrok_prefix)) ? $ngrok_prefix : $base_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPurchase($user_email, $items, $cbFormatter)
|
private function setApiKey()
|
||||||
{
|
{
|
||||||
$apiKey = $this->container->getParameter('stripe_api_key_secret');
|
$apiKey = $this->container->getParameter('stripe_api_key_secret');
|
||||||
|
|
||||||
\Stripe\Stripe::setApiKey($apiKey);
|
\Stripe\Stripe::setApiKey($apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPurchase($customer, $items, $cbFormatter)
|
||||||
|
{
|
||||||
|
$this->setApiKey();
|
||||||
|
|
||||||
$line_items = [];
|
$line_items = [];
|
||||||
|
|
||||||
foreach ($items as $item) $line_items[] = $cbFormatter($item);
|
if (empty($customer->getStripeCustomerId()))
|
||||||
|
{
|
||||||
|
$stripeCustomer = \Stripe\Customer::create(array(
|
||||||
|
"description" => "Customer for ".$customer->getUsername(),
|
||||||
|
"email" => $customer->getUsername(),
|
||||||
|
"metadata" => [
|
||||||
|
"Prénom" => $customer->getFirstname(),
|
||||||
|
"Nom" => $customer->getLastname(),
|
||||||
|
"Entreprise" => $customer->getCompany()
|
||||||
|
]
|
||||||
|
));
|
||||||
|
|
||||||
$ngrok_url = $this->container->getParameter('dev_ngrok_prefix');
|
$customerId = $stripeCustomer["id"];
|
||||||
|
$customer->setStripeCustomerId($customerId);
|
||||||
|
$this->manager->persist($customer);
|
||||||
|
$this->manager->flush();
|
||||||
|
|
||||||
|
$stripeCustomerId = $customerId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$stripeCustomerId = $customer->getStripeCustomerId();
|
||||||
|
|
||||||
|
foreach ($items as $item) $line_items[] = $cbFormatter($item);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
\Stripe\Checkout\Session::create([
|
\Stripe\Checkout\Session::create([
|
||||||
'customer_email' => $user_email,
|
'customer' => $stripeCustomerId,
|
||||||
'payment_method_types' => $this->container->getParameter('payment_method'),
|
'payment_method_types' => $this->container->getParameter('payment_method'),
|
||||||
'line_items' => $line_items,
|
'line_items' => $line_items,
|
||||||
'success_url' => $ngrok_url . $this->container->getParameter('stripe_success_url'),
|
'success_url' => $this->url_prefix . $this->container->getParameter('stripe_success_url'),
|
||||||
'cancel_url' => $ngrok_url . $this->container->getParameter('stripe_cancel_url'),
|
'cancel_url' => $this->url_prefix . $this->container->getParameter('stripe_cancel_url'),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function confirmPurchase($paimentIntent)
|
||||||
|
{
|
||||||
|
$infoIntent = $this->retrievePurchase($paimentIntent);
|
||||||
|
|
||||||
|
return ($infoIntent['amount'] == $infoIntent['amount_received'] && $infoIntent['amount_capturable'] == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function retrievePurchase($paimentIntent)
|
||||||
|
{
|
||||||
|
$this->setApiKey();
|
||||||
|
|
||||||
|
return \Stripe\PaymentIntent::retrieve($paimentIntent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue