Skip to content

Commit 2a7c627

Browse files
authored
Merge pull request #31 from romeritoCL/sandbox_bt_features
added v2 sandbox query, added braintree features
2 parents 741735f + c009b5f commit 2a7c627

File tree

19 files changed

+214
-58
lines changed

19 files changed

+214
-58
lines changed

assets/js/braintree/api/api.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import listCustomer from './vault/list.js';
2+
3+
function addApiButtonEvent(action, starter)
4+
{
5+
let button = document.getElementById(action);
6+
button.addEventListener('click', function (event) {
7+
event.preventDefault();
8+
let apiFormDiv = document.getElementById('bt-api-action-list');
9+
let url = button.getAttribute('href');
10+
$.get(
11+
url,
12+
function (data) {
13+
apiFormDiv.innerHTML = data;
14+
starter.start();
15+
}
16+
);
17+
});
18+
}
19+
20+
addApiButtonEvent('listCustomer', listCustomer);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function start()
2+
{
3+
$('.btn-customer-get').each(function () {
4+
$(this).click(function (event) {
5+
event.preventDefault();
6+
let getCustomerUrl = $(this).attr('href');
7+
$.get(
8+
getCustomerUrl,
9+
function (data) {
10+
document.getElementById('bt-api-action-get').innerHTML = data;
11+
}
12+
);
13+
});
14+
});
15+
}
16+
17+
module.exports = {
18+
start,
19+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Controller\Braintree;
4+
5+
use Symfony\Component\Routing\Annotation\Route;
6+
use Symfony\Component\HttpFoundation\Response;
7+
8+
/**
9+
* Class ApiController
10+
*
11+
* @package App\Controller\Braintree
12+
*
13+
* @Route("/braintree/api", name="braintree-api-")
14+
*/
15+
class ApiController extends AbstractController
16+
{
17+
/**
18+
* @Route("/", name="index", methods={"GET"})
19+
*
20+
* @return Response
21+
*/
22+
public function index(): Response
23+
{
24+
return $this->render('braintree/api/base.html.twig');
25+
}
26+
}

src/Controller/Braintree/ApiDumpController.php

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace App\Controller\Braintree\Vault;
4+
5+
use App\Controller\Braintree\AbstractController;
6+
use Braintree\Exception\NotFound;
7+
use Symfony\Component\Routing\Annotation\Route;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
/**
11+
* Class VaultController
12+
*
13+
* @package App\Controller\Braintree\Vault
14+
*
15+
* @Route("/braintree/vault", name="braintree-vault-")
16+
*/
17+
class VaultController extends AbstractController
18+
{
19+
/**
20+
* @Route("/", name="customer-list", methods={"GET"})
21+
*
22+
* @return Response
23+
*/
24+
public function listCustomer(): Response
25+
{
26+
$customers = $this->braintreeService->getCustomerService()->listCustomers();
27+
return $this->render('braintree/api/vault/list.html.twig', [
28+
'customers' => $customers
29+
]);
30+
}
31+
32+
/**
33+
* @Route("/vault/{customerId}", name="customer-get", methods={"GET"})
34+
*
35+
* @param $customerId
36+
* @return Response
37+
* @throws NotFound
38+
*/
39+
public function getCustomer($customerId): Response
40+
{
41+
$customer = $this->braintreeService->getCustomerService()->getCustomer($customerId);
42+
return $this->render('default/dump.html.twig', [
43+
'raw_result' => false,
44+
'result' => $customer
45+
]);
46+
}
47+
}

src/Controller/Paypal/SessionController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public function sandboxCredentialsCreate()
2424
$request = Request::createFromGlobals();
2525
$clientId = $request->request->get('client_id', null);
2626
$clientSecret = $request->request->get('client_secret', null);
27-
if ($clientId && $clientSecret) {
28-
$this->paypalService->getSessionService()->updateCredentials($clientId, $clientSecret);
27+
$extra = $request->request->get('extra', null);
28+
if (($clientId && $clientSecret) || $extra) {
29+
$this->paypalService->getSessionService()->updateCredentials($clientId, $clientSecret, $extra);
2930
}
3031
return $this->redirectToRoute('paypal-index');
3132
}

src/Service/Paypal/AbstractPaypalService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function __construct(
6060
) {
6161
$sessionClientId = $sessionService->session->get('PAYPAL_SDK_CLIENT_ID');
6262
$sessionClientSecret = $sessionService->session->get('PAYPAL_SDK_CLIENT_SECRET');
63+
$sessionSDKExtra = $sessionService->session->get('PAYPAL_SDK_EXTRA');
6364
$this->clientId = $sessionClientId ?? $clientId;
6465
$this->clientSecret = $sessionClientSecret ?? $clientSecret;
6566
$this->logger = $logger;

src/Service/Paypal/SessionService.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ public function getRefreshToken(): ?string
8585
* @param string $clientId
8686
* @param string $clientSecret
8787
*/
88-
public function updateCredentials(string $clientId, string $clientSecret): void
88+
public function updateCredentials(?string $clientId, ?string $clientSecret, ?string $extra): void
8989
{
90-
$this->session->set('PAYPAL_SDK_CLIENT_ID', $clientId);
91-
$this->session->set('PAYPAL_SDK_CLIENT_SECRET', $clientSecret);
90+
if ($clientId) {
91+
$this->session->set('PAYPAL_SDK_CLIENT_ID', $clientId);
92+
}
93+
if ($clientSecret) {
94+
$this->session->set('PAYPAL_SDK_CLIENT_SECRET', $clientSecret);
95+
}
96+
if ($extra) {
97+
$this->session->set('PAYPAL_SDK_EXTRA', $extra);
98+
}
9299
}
93100

94101
/**
@@ -98,5 +105,6 @@ public function removeCredentials(): void
98105
{
99106
$this->session->remove('PAYPAL_SDK_CLIENT_ID');
100107
$this->session->remove('PAYPAL_SDK_CLIENT_SECRET');
108+
$this->session->remove('PAYPAL_SDK_EXTRA');
101109
}
102110
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{% extends 'braintree/base.html.twig' %}
2+
{% block stylesheets %}
3+
{{ parent() }}
4+
{{ encore_entry_link_tags('braintree-api') }}
5+
{% endblock %}
6+
{% block content %}
7+
<div class="hyperwallet-font">
8+
<div class="row braintree-font-header">
9+
<h3>API Examples</h3>
10+
</div>
11+
<hr>
12+
<div class="row">
13+
<h5>Vault API</h5>
14+
</div>
15+
<div>
16+
<p>You can store, list and get information from your customers on BrainTree. Also check their available payment methods</p>
17+
</div>
18+
</div>
19+
<div class="row mt-2 d-inline-block">
20+
<a class="m-2 d-inline btn bg-braintree text-light btn-block col-2" id="listCustomer" href="{{ path('braintree-vault-customer-list') }}">List Customers</a>
21+
</div>
22+
<hr>
23+
<div class="row mt-5 braintree-font" id="bt-api-action-list"></div>
24+
<div class="row mt-5 braintree-font" id="bt-api-action-get"></div>
25+
{% endblock %}
26+
{% block javascripts %}
27+
{{ parent() }}
28+
{{ encore_entry_script_tags('braintree-api') }}
29+
{% endblock %}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<div class="container" id="searchContainer">
2+
<div class="table-responsive">
3+
<table class="table table-hover table-striped table-bordered">
4+
<thead class="thead-dark">
5+
<tr>
6+
<th scope="col">#</th>
7+
<th scope="col">Full Name</th>
8+
<th scope="col">Email</th>
9+
<th scope="col">Available PaymentMethods</th>
10+
<th scope="col" style="width: 30%">Actions</th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
{% for customer in customers %}
15+
<tr>
16+
<th scope="row">{{ customer.id }}</th>
17+
<td>{{ customer.full_name }}</td>
18+
<td>{{ customer.email }}</td>
19+
<td>{{ customer.available_payment_methods }}</td>
20+
<td>
21+
<a class="btn btn-secondary btn-customer-get" href="{{ path('braintree-vault-customer-get', {'customerId': customer.id}) }}">View Details</a>
22+
</td>
23+
</tr>
24+
{% endfor %}
25+
</tbody>
26+
</table>
27+
</div>
28+
</div>

0 commit comments

Comments
 (0)