This repository was archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArbController.php
More file actions
103 lines (78 loc) · 3.7 KB
/
ArbController.php
File metadata and controls
103 lines (78 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Problematic\AuthNetBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Problematic\AuthNetBundle\AuthorizeNet\API\ARB\AuthorizeNetSubscription;
use Problematic\AuthNetBundle\AuthorizeNet\API\ARB\AuthorizeNetARB;
use Problematic\AuthNetBundle\Entity\Subscription;
use Problematic\AuthNetBundle\Form\SubscriptionType;
use Problematic\AuthNetBundle\Event\FilterArbSubscriptionEvent;
class ArbController extends Controller
{
public function createSubscriptionAction()
{
$em = $this->getDoctrine()->getEntityManager();
$request = $this->getRequest();
$subscription = new AuthorizeNetSubscription();
$form = $this->createForm(new SubscriptionType(), $subscription);
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
$event = new FilterArbSubscriptionEvent($subscription, $request->request->get($form->getName()));
$this->get('event_dispatcher')->dispatch('auth_net.arb.preCreateSubscription', $event);
$subscription = $event->getSubscription();
$create_request = $this->createARB();
$create_request->setRefId($subscription->customerId);
$response = $create_request->createSubscription($subscription);
if ($response->isOk()) {
$subscription = new Subscription();
$subscription->setSubscriptionId($response->getSubscriptionId());
$subscription->setRefId($response->getRefID());
$subscription->setStatus($response->getSubscriptionStatus());
$em->persist($subscription);
$em->flush();
} else {
}
}
// todo: redirect to success page
}
return $this->render('ProblematicAuthNetBundle:Arb:createSubscription.html.twig', array(
'form' => $form->createView(),
));
}
public function updateSubscriptionAction()
{
}
public function getSubscriptionStatusAction(Subscription $subscription)
{
$em = $this->getDoctrine()->getEntityManager();
$status_request = $this->createARB();
$response = $status_request->getSubscriptionStatus($subscription->getSubscriptionId());
if ($response->isOk()) {
$status = $response->getSubscriptionStatus();
$subscription->setStatus($status);
$em->flush();
} else {
}
return new \Symfony\Component\HttpFoundation\Response();
}
public function cancelSubscriptionAction(Subscription $subscription)
{
$em = $this->getDoctrine()->getEntityManager();
$cancellation_request = $this->createARB();
$cancellation_request->setRefId($subscription->getRefId());
$response = $cancellation_request->cancelSubscription($subscription->getSubscriptionId());
if ($response->isOk()) {
$subscription->setStatus($response->getSubscriptionStatus());
$em->flush();
} else {
}
return new \Symfony\Component\HttpFoundation\Response();
}
protected function createARB()
{
return new AuthorizeNetArb($this->container->getParameter('auth_net.api_login'),
$this->container->getParameter('auth_net.transaction_key'),
$this->container->getParameter('auth_net.sandbox_mode'));
}
}