1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller\Braintree; |
4
|
|
|
|
5
|
|
|
use Braintree\Exception\NotFound; |
6
|
|
|
use Braintree\Transaction; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class PaymentsController |
13
|
|
|
* |
14
|
|
|
* @package App\Controller\Braintree |
15
|
|
|
* |
16
|
|
|
* @Route("/braintree/payments", name="braintree-payments-") |
17
|
|
|
*/ |
18
|
|
|
class PaymentsController extends AbstractController |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param string $action |
22
|
|
|
* @param string $description |
23
|
|
|
* @return Response |
24
|
|
|
* |
25
|
|
|
* @Route("/dropui", name="dropui", methods={"GET"}, |
26
|
|
|
* defaults={"description" = "DropUI", "action" = "dropui"}) |
27
|
|
|
* @Route("/hosted-fields", name="hosted-fields", methods={"GET"}, |
28
|
|
|
* defaults={"description" = "Hosted Fields", "action" = "hosted-fields"}) |
29
|
|
|
* @Route("/apm", name="apm", methods={"GET"}, |
30
|
|
|
* defaults={"description" = "Alternative Payments", "action" = "apm"}) |
31
|
|
|
* @Route("/3ds", name="three-ds", methods={"GET"}, |
32
|
|
|
* defaults={"description" = "3D Secure", "action" = "3ds"}) |
33
|
|
|
* @Route("/vault", name="vault", methods={"GET"}, |
34
|
|
|
* defaults={"description" = "Vault API", "action" = "vault"}) |
35
|
|
|
* @Route("/request", name="request", methods={"GET"}, |
36
|
|
|
* defaults={"description" = "PaymentRequestAPI", "action" = "request"}) |
37
|
|
|
*/ |
38
|
|
|
public function payments(string $action, string $description) |
39
|
|
|
{ |
40
|
|
|
$clientToken = $this->braintreeService->getPaymentService()->getClientToken(); |
41
|
|
|
return $this->render('braintree/payments/' . $action . '.html.twig', [ |
42
|
|
|
'paypalClientId' => $this->getParameter('PAYPAL_SDK_CLIENT_ID'), |
43
|
|
|
'clientToken' => $clientToken, |
44
|
|
|
'name' => $description |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Route("/payload", name="payload", methods={"POST"}) |
50
|
|
|
* |
51
|
|
|
* @return Response |
52
|
|
|
*/ |
53
|
|
|
public function paymentsPayload() |
54
|
|
|
{ |
55
|
|
|
$request = Request::createFromGlobals(); |
56
|
|
|
$payload = $request->request->all(); |
57
|
|
|
return $this->render('default/dump.html.twig', [ |
58
|
|
|
'result' => (object) $payload, |
59
|
|
|
'raw_result' => false, |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @Route("/transaction", name="create", methods={"POST"}) |
65
|
|
|
* |
66
|
|
|
* @return Response |
67
|
|
|
*/ |
68
|
|
|
public function createTransaction() |
69
|
|
|
{ |
70
|
|
|
$request = Request::createFromGlobals(); |
71
|
|
|
$paymentNonce = $request->request->get('payment_nonce'); |
72
|
|
|
$amount = $request->request->get('amount'); |
73
|
|
|
$deviceData = $request->request->get('device_data'); |
74
|
|
|
$sale = $this->braintreeService->getPaymentService()->createSale($amount, $paymentNonce, $deviceData); |
75
|
|
|
/** @var Transaction $transaction */ |
76
|
|
|
$transaction = $sale->transaction; |
77
|
|
|
return $this->render('default/dump-input-id.html.twig', [ |
78
|
|
|
'result' => $sale, |
79
|
|
|
'raw_result' => false, |
80
|
|
|
'result_id' => $transaction->id |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @Route("/transaction/{transactionId}/capture", name="capture", methods={"POST"}) |
86
|
|
|
* |
87
|
|
|
* @param string $transactionId |
88
|
|
|
* |
89
|
|
|
* @return Response |
90
|
|
|
*/ |
91
|
|
|
public function captureTransaction(string $transactionId) |
92
|
|
|
{ |
93
|
|
|
$request = Request::createFromGlobals(); |
94
|
|
|
$amount = $request->request->get('amount'); |
95
|
|
|
$capture = $this->braintreeService->getPaymentService()->captureSale($transactionId, $amount); |
96
|
|
|
return $this->render('default/dump.html.twig', [ |
97
|
|
|
'result' => (object) $capture, |
98
|
|
|
'raw_result' => false, |
99
|
|
|
]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @Route("/{transactionId}", name="get", methods={"GET"}) |
104
|
|
|
* |
105
|
|
|
* @param string $transactionId |
106
|
|
|
* @return Response |
107
|
|
|
* @throws NotFound |
108
|
|
|
*/ |
109
|
|
|
public function getTransaction(string $transactionId) |
110
|
|
|
{ |
111
|
|
|
$transaction = $this->braintreeService->getPaymentService()->getTransaction($transactionId); |
112
|
|
|
return $this->render('default/dump.html.twig', [ |
113
|
|
|
'result' => (object) $transaction, |
114
|
|
|
'raw_result' => false, |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|