|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Braintree; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
8
|
|
|
use Exception; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class CustomersController |
|
12
|
|
|
* |
|
13
|
|
|
* @package App\Controller\Braintree |
|
14
|
|
|
* |
|
15
|
|
|
* @Route("/braintree/customers", name="braintree-customers-") |
|
16
|
|
|
*/ |
|
17
|
|
|
class CustomersController extends AbstractController |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @Route("/", name="list", methods={"GET"}) |
|
21
|
|
|
* |
|
22
|
|
|
* @return Response |
|
23
|
|
|
*/ |
|
24
|
|
|
public function listCustomers() |
|
25
|
|
|
{ |
|
26
|
|
|
$customers = $this->braintreeService->getCustomerService()->listCustomers(); |
|
27
|
|
|
return $this->render('braintree/payments/vault/customer-group-item.html.twig', [ |
|
28
|
|
|
'customers' => $customers |
|
29
|
|
|
]); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @Route("/", name="create", methods={"POST"}) |
|
34
|
|
|
* |
|
35
|
|
|
* @return Response |
|
36
|
|
|
*/ |
|
37
|
|
|
public function createCustomer() |
|
38
|
|
|
{ |
|
39
|
|
|
$request = Request::createFromGlobals(); |
|
40
|
|
|
$customerData = $request->request->all(); |
|
41
|
|
|
$customer = $this->braintreeService->getCustomerService()->createCustomer($customerData); |
|
42
|
|
|
$customer instanceof Exception ? $customerId = null : $customerId = $customer->customer->id; |
|
43
|
|
|
return $this->render('default/dump-input-id.html.twig', [ |
|
44
|
|
|
'raw_result' => false, |
|
45
|
|
|
'result' => $customer, |
|
46
|
|
|
'result_id' => $customerId, |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @Route("/{customerId}/token", name="get-cutomer-token", methods={"GET"}) |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $customerId |
|
54
|
|
|
* @return Response |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getCustomerToken(string $customerId) |
|
57
|
|
|
{ |
|
58
|
|
|
$clientToken = $this->braintreeService->getPaymentService()->getClientToken($customerId); |
|
59
|
|
|
|
|
60
|
|
|
return new Response($clientToken); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|