Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,6 @@ public class App {
//A esta le pasamos la UrlApi y el token de la cuenta a consultar

AccountBalance account = new AccountBalance("https://api.test.sw.com.mx", "token", null, 0);
AccountBalanceResponse res = account.getBalance();
AccountBalanceResponse response = account.getBalance();
System.out.println("Estado: " + response.getStatus());
System.out.println("ID Usuario: " + response.getData().getIdUser());
Expand Down Expand Up @@ -1161,6 +1160,73 @@ public class App {
```
</details>

<details>
<summary>
Consultar saldo por Id de la subcuenta
</summary>
Este metodo permite revisar el detalle de los timbres disponibles en una subcuenta filtrando por ID.


**Ejemplo de consumo de la libreria para consultar el saldo por Id mediante token**
```java
import mx.com.sw.services.account.balance.AccountBalance;
import mx.com.sw.services.account.balance.responses.AccountBalanceResponse;

public class App {

public static void main(String[] args)
{
try
{
//Creamos una instancia de tipo BalanceAccount
//A esta le pasamos la UrlApi, el token de la cuenta administradora y el ID de la subcuenta a consultar

AccountBalance account = new AccountBalance("https://api.test.sw.com.mx", "token", null, 0);
AccountBalanceResponse response = account.getBalanceById(UUID.fromString("fafb2ac2-62ca-49f8-91de-14cea73b01eb"));
System.out.println("Estado: " + response.getStatus());
System.out.println("ID Usuario: " + response.getData().getIdUser());
System.out.println("ID Balance Usuario: " + response.getData().getIdUserBalance());
System.out.println("Stamps Asignados: " + response.getData().getStampsAssigned());
System.out.println("Stamps Usados: " + response.getData().getStampsUsed());
System.out.println("Saldo Stamps: " + response.getData().getStampsBalance());
System.out.println("Es Ilimitado: " + response.getData().isUnlimited());
System.out.println("Fecha Expiración: " + response.getData().getExpirationDate());
if (response.getData().getLastTransaction() != null) {
System.out.println("Folio: " + response.getData().getLastTransaction().getFolio());
System.out.println("ID Usuario: " + response.getData().getLastTransaction().getIdUser());
System.out
.println("ID Usuario Receptor: " + response.getData().getLastTransaction().getIdUserReceiver());
System.out.println("Nombre Receptor: " + response.getData().getLastTransaction().getNameReceiver());
System.out.println("Stamps In: "
+ (response.getData().getLastTransaction().getStampsIn() != null
? response.getData().getLastTransaction().getStampsIn()
: "null"));
System.out.println("Stamps Out: "
+ (response.getData().getLastTransaction().getStampsOut() != null
? response.getData().getLastTransaction().getStampsOut()
: "null"));
System.out.println("Stamps Current: "
+ (response.getData().getLastTransaction().getStampsCurrent() != null
? response.getData().getLastTransaction().getStampsCurrent()
: "null"));
System.out.println("Comentario: " + response.getData().getLastTransaction().getComment());
System.out.println("Fecha: " + response.getData().getLastTransaction().getDate());
System.out.println("Email Enviado: " +
(response.getData().getLastTransaction().isEmailSent() ? "Sí" : "No"));

} else {
System.out.println("No hay transacción registrada.");
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}
```
</details>

<details>
<summary>
Añadir saldo
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>mx.com.sw</groupId>
<artifactId>sdk-java18</artifactId>
<version>0.0.19.1</version>
<version>0.0.20.1</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AccountBalance extends AccountBalanceService {
// Rutas de API para operaciones de saldo.
private static final String MANAGEMENT_API_BALANCE_PATH = "management/v2/api/dealers/users/";
private static final String SERVICE_BALANCE_PATH = "management/v2/api/users/balance";
private static final String SERVICE_BALANCE_ID_PATH = "management/v2/api/dealers/balance/users/";

// Manejadores de respuesta para consultas y acciones.
private final AccountBalanceResponseHandler handler;
Expand Down Expand Up @@ -96,7 +97,7 @@ public AccountBalanceActionResponse removeStamps(UUID idUser, int stamps, String
public AccountBalanceResponse getBalanceById(UUID idUser) throws ServicesException {
Map<String, String> headers = getHeaders(); // Obtener encabezados.
RequestConfig config = GeneralHelpers.setProxyAndTimeOut(getProxy(), getProxyPort()); // Configurar proxy.
String path = String.format(MANAGEMENT_API_BALANCE_PATH, idUser.toString()); // Ruta del usuario.
String path = SERVICE_BALANCE_ID_PATH + idUser.toString();

// Consultar saldo.
return handler.getHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), path, headers, config, AccountBalanceResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AccountBalanceTest() {
}

/**
* Método de UT con usuario y password.
* Método de consulta saldo con usuario y password.
*/
@Test
public void testGetBalance() {
Expand Down Expand Up @@ -112,6 +112,76 @@ public void testGetBalanceBadToken() {
}
}

/**
* Método de UT consultar saldo por ID con usuario y password.
*/
@Test
public void testGetBalanceById() {
try {
AccountBalance account = new AccountBalance(settings.getUrlSW(), settings.getUrlServicesSW(),
settings.getUserSW(),
settings.getPasswordSW(), null, 0);
AccountBalanceResponse res = account.getBalanceById(UUID.fromString("fafb2ac2-62ca-49f8-91de-14cea73b01eb"));
Assertions.assertNotNull(res);
Assertions.assertTrue("success".equals(res.getStatus()));
Assertions.assertNotNull(res.getData());
Assertions.assertNotNull(res.getData().getStampsBalance() > 0);
} catch (ServicesException ex) {
Assertions.assertNotNull(ex);
}
}

/**
* Método de UT consultar saldo por ID con token.
*/
@Test
public void testGetBalanceByIdToken() {
try {
AccountBalance account = new AccountBalance(settings.getUrlServicesSW(), settings.getTokenSW(), null, 0);
AccountBalanceResponse response = account.getBalanceById(UUID.fromString("fafb2ac2-62ca-49f8-91de-14cea73b01eb"));
Assertions.assertNotNull(response);
Assertions.assertTrue("success".equals(response.getStatus()));
Assertions.assertNotNull(response.getData());
System.out.println("Estado: " + response.getStatus());
System.out.println("ID Usuario: " + response.getData().getIdUser());
System.out.println("ID Balance Usuario: " + response.getData().getIdUserBalance());
System.out.println("Stamps Asignados: " + response.getData().getStampsAssigned());
System.out.println("Stamps Usados: " + response.getData().getStampsUsed());
System.out.println("Saldo Stamps: " + response.getData().getStampsBalance());
System.out.println("Es Ilimitado: " + response.getData().isUnlimited());
System.out.println("Fecha Expiración: " + response.getData().getExpirationDate());
if (response.getData().getLastTransaction() != null) {
System.out.println("Folio: " + response.getData().getLastTransaction().getFolio());
System.out.println("ID Usuario: " + response.getData().getLastTransaction().getIdUser());
System.out
.println("ID Usuario Receptor: " + response.getData().getLastTransaction().getIdUserReceiver());
System.out.println("Nombre Receptor: " + response.getData().getLastTransaction().getNameReceiver());
System.out.println("Stamps In: "
+ (response.getData().getLastTransaction().getStampsIn() != null
? response.getData().getLastTransaction().getStampsIn()
: "null"));
System.out.println("Stamps Out: "
+ (response.getData().getLastTransaction().getStampsOut() != null
? response.getData().getLastTransaction().getStampsOut()
: "null"));
System.out.println("Stamps Current: "
+ (response.getData().getLastTransaction().getStampsCurrent() != null
? response.getData().getLastTransaction().getStampsCurrent()
: "null"));
System.out.println("Comentario: " + response.getData().getLastTransaction().getComment());
System.out.println("Fecha: " + response.getData().getLastTransaction().getDate());
System.out.println("Email Enviado: " +
(response.getData().getLastTransaction().isEmailSent() ? "Sí" : "No"));

} else {
System.out.println("No hay transacción registrada.");
}

} catch (ServicesException ex) {
Assertions.assertNotNull(ex);
}
}

/**
* Método de UT AgregarTimbres con token incorrecto.
*/
Expand Down