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
|
|
|
* @Route("/", name="index", methods={"GET"}) |
22
|
|
|
* |
23
|
|
|
* @return Response |
24
|
|
|
*/ |
25
|
|
|
public function payments() |
26
|
|
|
{ |
27
|
|
|
$clientToken = $this->braintreeService->getPaymentService()->getClientToken(); |
28
|
|
|
return $this->render('braintree/payments/payments.html.twig', [ |
29
|
|
|
'clientToken' => $clientToken, |
30
|
|
|
]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @Route("/payload", name="payload", methods={"POST"}) |
35
|
|
|
* |
36
|
|
|
* @return Response |
37
|
|
|
*/ |
38
|
|
|
public function paymentsPayload() |
39
|
|
|
{ |
40
|
|
|
$request = Request::createFromGlobals(); |
41
|
|
|
$payload = $request->request->all(); |
42
|
|
|
return $this->render('default/dump.html.twig', [ |
43
|
|
|
'result' => (object) $payload, |
44
|
|
|
'raw_result' => false, |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Route("/transaction", name="create", methods={"POST"}) |
50
|
|
|
* |
51
|
|
|
* @return Response |
52
|
|
|
*/ |
53
|
|
|
public function createTransaction() |
54
|
|
|
{ |
55
|
|
|
$request = Request::createFromGlobals(); |
56
|
|
|
$paymentNonce = $request->request->get('payment_nonce'); |
57
|
|
|
$amount = $request->request->get('amount'); |
58
|
|
|
$deviceData = $request->request->get('device_data'); |
59
|
|
|
$sale = $this->braintreeService->getPaymentService()->createSale($amount, $paymentNonce, $deviceData); |
60
|
|
|
/** @var Transaction $transaction */ |
61
|
|
|
$transaction = $sale->transaction; |
62
|
|
|
return $this->render('default/dump-input-id.html.twig', [ |
63
|
|
|
'result' => $sale, |
64
|
|
|
'raw_result' => false, |
65
|
|
|
'result_id' => $transaction->id |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Route("/transaction/{transactionId}/capture", name="capture", methods={"POST"}) |
71
|
|
|
* |
72
|
|
|
* @param string $transactionId |
73
|
|
|
* |
74
|
|
|
* @return Response |
75
|
|
|
*/ |
76
|
|
|
public function captureTransaction(string $transactionId) |
77
|
|
|
{ |
78
|
|
|
$request = Request::createFromGlobals(); |
79
|
|
|
$amount = $request->request->get('amount'); |
80
|
|
|
$capture = $this->braintreeService->getPaymentService()->captureSale($transactionId, $amount); |
81
|
|
|
return $this->render('default/dump.html.twig', [ |
82
|
|
|
'result' => (object) $capture, |
83
|
|
|
'raw_result' => false, |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @Route("/{transactionId}", name="get", methods={"GET"}) |
89
|
|
|
* |
90
|
|
|
* @param string $transactionId |
91
|
|
|
* @return Response |
92
|
|
|
* @throws NotFound |
93
|
|
|
*/ |
94
|
|
|
public function getTransaction(string $transactionId) |
95
|
|
|
{ |
96
|
|
|
$transaction = $this->braintreeService->getPaymentService()->getTransaction($transactionId); |
97
|
|
|
return $this->render('default/dump.html.twig', [ |
98
|
|
|
'result' => (object) $transaction, |
99
|
|
|
'raw_result' => false, |
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|