1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tahoe\Bundle\MultiTenancyBundle\Controller; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Tahoe\Bundle\MultiTenancyBundle\Form\Type\SubscriptionType; |
9
|
|
|
|
10
|
|
|
class SubscriptionController extends Controller |
11
|
|
|
{ |
12
|
|
|
public function indexAction(Request $request) |
13
|
|
|
{ |
14
|
|
|
$tenant = $this->get('tahoe.multi_tenancy.tenant_resolver')->getTenant(); |
15
|
|
|
if ($this->get('tahoe.multi_tenancy.gateway.recurly')->subscriptionExists($tenant)) { |
16
|
|
|
return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription_details')); |
17
|
|
|
} |
18
|
|
|
$form = $this->createForm(new SubscriptionType(), new \Recurly_BillingInfo()); |
19
|
|
|
$form->handleRequest($request); |
20
|
|
|
|
21
|
|
View Code Duplication |
if ($form->isValid()) { |
|
|
|
|
22
|
|
|
$this->get('tahoe.multi_tenancy.gateway.recurly')->createSubscription($tenant, $form->getData()); |
23
|
|
|
|
24
|
|
|
$this->get('session')->getFlashBag()->add('success', 'The subscription has been created successfully'); |
25
|
|
|
|
26
|
|
|
return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription')); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return $this->render('TahoeMultiTenancyBundle:Subscription:index.html.twig', array( |
30
|
|
|
'form' => $form->createView() |
31
|
|
|
)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function detailsAction(Request $request) |
35
|
|
|
{ |
36
|
|
|
$tenant = $this->get('tahoe.multi_tenancy.tenant_resolver')->getTenant(); |
37
|
|
|
$subscription = $this->get('tahoe.multi_tenancy.gateway.recurly')->getSubscription($tenant); |
38
|
|
|
if (null === $subscription) { |
39
|
|
|
return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription')); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$billingInfo = $this->get('tahoe.multi_tenancy.gateway.recurly')->getBillingInfo($tenant); |
43
|
|
|
|
44
|
|
|
$form = $this->createForm(new SubscriptionType(), $billingInfo); |
45
|
|
|
$form->handleRequest($request); |
46
|
|
|
|
47
|
|
View Code Duplication |
if ($form->isValid()) { |
|
|
|
|
48
|
|
|
$this->get('tahoe.multi_tenancy.gateway.recurly')->updateBillingInfo($tenant, $form->getData()); |
49
|
|
|
$this->get('session')->getFlashBag()->add('success', 'Your billing information has been updated successfully'); |
50
|
|
|
|
51
|
|
|
return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $this->render('TahoeMultiTenancyBundle:Subscription:index.html.twig', array( |
55
|
|
|
'form' => $form->createView(), |
56
|
|
|
'update' => true |
57
|
|
|
)); |
58
|
|
|
} |
59
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.