Skip to content

Commit 710323f

Browse files
committed
Added payroll support
1 parent 071d163 commit 710323f

44 files changed

Lines changed: 1575 additions & 203 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Official Java SDK for FiscalAPI - a Mexican CFDI electronic invoicing service (SAT integration). Provides CFDI 4.0 invoicing, certificate management, mass downloads, payroll, and SAT catalog queries.
8+
9+
## Build Commands
10+
11+
```bash
12+
mvn clean compile # Compile
13+
mvn test # Run tests
14+
mvn package # Create JAR
15+
mvn clean deploy -Prelease # Deploy to Maven Central (requires GPG)
16+
```
17+
18+
## Architecture
19+
20+
### Entry Point
21+
`FiscalApiClient.create(FiscalApiSettings)` - Factory method creating the main client with all services.
22+
23+
### Service Layer Pattern
24+
```
25+
IFiscalApiClient (facade)
26+
├── getInvoiceService() → IInvoiceService extends IFiscalApiService<Invoice>
27+
├── getPersonService() → IPersonService extends IFiscalApiService<Person>
28+
├── getProductService() → IProductService extends IFiscalApiService<Product>
29+
├── getTaxFileService() → ITaxFileService extends IFiscalApiService<TaxFile>
30+
├── getCatalogService() → ICatalogService extends IFiscalApiService<CatalogDto>
31+
└── ... (other services)
32+
```
33+
34+
### Generic CRUD Base
35+
All services extend `BaseFiscalApiService<T>` which implements standard CRUD:
36+
- `getList(pageNumber, pageSize)``ApiResponse<PagedList<T>>`
37+
- `getById(id, details)``ApiResponse<T>`
38+
- `create(model)``ApiResponse<T>`
39+
- `update(model)``ApiResponse<T>`
40+
- `delete(id)``ApiResponse<Boolean>`
41+
42+
Subclasses must implement `getTypeParameterClass()` to return the entity type for Jackson deserialization.
43+
44+
### DTO Hierarchy
45+
```
46+
SerializableDto → AuditableDto (createdAt, updatedAt) → BaseDto (id)
47+
```
48+
All models extend `BaseDto`. Responses wrapped in `ApiResponse<T>`.
49+
50+
### HTTP Layer
51+
- `OkHttpClientFactory` - Creates/caches OkHttpClient instances with auth headers (X-API-KEY, X-TENANT-KEY, X-API-VERSION, X-TIMEZONE)
52+
- `FiscalApiHttpClient` - Wraps OkHttp with Jackson, handles request/response logging in debug mode
53+
54+
### Key Packages
55+
- `abstractions/` - Service interfaces
56+
- `common/` - ApiResponse, PagedList, settings
57+
- `http/` - HTTP client implementation
58+
- `models/` - All DTOs (invoicing/, downloading/ subpackages)
59+
- `services/` - Service implementations
60+
61+
## Configuration
62+
63+
```java
64+
FiscalApiSettings settings = new FiscalApiSettings();
65+
settings.setApiUrl("https://test.fiscalapi.com"); // or https://live.fiscalapi.com
66+
settings.setApiKey("sk_test_...");
67+
settings.setTenant("...");
68+
settings.setDebugMode(true); // Logs requests/responses
69+
FiscalApiClient client = FiscalApiClient.create(settings);
70+
```
71+
72+
## API Endpoint Pattern
73+
74+
`{apiUrl}/api/{apiVersion}/{resource}/{id?}/{action?}`
75+
76+
Example: `POST api/v4/invoices`, `GET api/v4/invoices/{id}?details=true`
77+
78+
## Dependencies
79+
80+
- OkHttp3 4.12.0 (HTTP)
81+
- Jackson 2.14.2 (JSON)
82+
- Java 8+ (source/target)

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- Coordenadas del proyecto -->
88
<groupId>com.fiscalapi</groupId>
99
<artifactId>fiscalapi</artifactId>
10-
<version>4.0.273</version>
10+
<version>4.0.306</version>
1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<description>Genera facturas CFDI válidas ante el SAT consumiendo la API de https://www.fiscalapi.com</description>
1313
<url>https://www.fiscalapi.com</url>
@@ -97,7 +97,7 @@
9797
<executions>
9898
<execution>
9999
<id>sign-artifacts</id>
100-
<phase>verify</phase>
100+
<phase>vegpghrify</phase>
101101
<goals>
102102
<goal>sign</goal>
103103
</goals>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fiscalapi;
2+
3+
import java.time.LocalDateTime;
4+
import java.time.ZonedDateTime;
5+
import java.time.format.DateTimeParseException;
6+
7+
import static com.fiscalapi.models.invoicing.InvoiceConstants.SAT_DATE_FORMAT_IN;
8+
9+
public class OptUtil {
10+
public static LocalDateTime formatInputDateToSATFormat(String stringDate) {
11+
LocalDateTime parsedDate = LocalDateTime.MIN;
12+
if (stringDate == null || stringDate.isEmpty()) {
13+
return parsedDate;
14+
}
15+
16+
try {
17+
// Intenta primero parsearlo como LocalDateTime
18+
parsedDate = LocalDateTime.parse(stringDate, SAT_DATE_FORMAT_IN);
19+
} catch (DateTimeParseException e) {
20+
try {
21+
// Si falla, intenta parsearlo como ZonedDateTime y convertirlo a LocalDateTime
22+
ZonedDateTime zdt = ZonedDateTime.parse(stringDate);
23+
parsedDate = zdt.toLocalDateTime();
24+
} catch (DateTimeParseException e2) {
25+
throw new IllegalArgumentException("Formato de fecha inválido: " + stringDate +
26+
" (debe ser compatible con el formato yyyy-MM-ddTHH:mm:ss)", e);
27+
}
28+
}
29+
return parsedDate;
30+
}
31+
}

src/main/java/com/fiscalapi/abstractions/IFiscalApiClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public interface IFiscalApiClient {
1010
IDownloadCatalogService getDownloadCatalogService();
1111
IDownloadRuleService getDownloadRuleService();
1212
IDownloadRequestService getDownloadRequestService();
13+
IStampService getStampService();
1314
// ... etc
1415
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.fiscalapi.abstractions;
22

33
import com.fiscalapi.models.Person;
4+
import com.fiscalapi.services.EmployeeService;
5+
import com.fiscalapi.services.EmployerService;
46

57
/**
68
* Define el contrato específico para operaciones con "Person".
79
* Hereda las operaciones básicas (CRUD) de IFiscalApiService&lt;Person&gt;.
810
*/
911
public interface IPersonService extends IFiscalApiService<Person> {
12+
EmployerService employer = null;
1013

11-
// other specific methods
14+
EmployeeService getEmployeeService();
15+
EmployerService getEmployerService();
1216
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.fiscalapi.abstractions;
2+
3+
import com.fiscalapi.common.ApiResponse;
4+
import com.fiscalapi.models.StampTransaction;
5+
import com.fiscalapi.models.StampTransactionParams;
6+
7+
public interface IStampService extends IFiscalApiService<StampTransaction>{
8+
ApiResponse<Boolean> TransferStamps(StampTransactionParams requestModel);
9+
ApiResponse<Boolean> WithdrawStamps(StampTransactionParams requestModel);
10+
}

src/main/java/com/fiscalapi/models/Person.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class Person extends BaseDto {
2323
private String zipCode;
2424
private String base64Photo;
2525
private String taxPassword;
26-
private Double availableBalance;
27-
private Double committedBalance;
26+
private java.math.BigDecimal availableBalance;
27+
private java.math.BigDecimal committedBalance;
2828
private String tenantId;
2929
// private String phoneNumber;
3030
// private LocalDateTime validTo;
@@ -146,19 +146,19 @@ public void setTaxPassword(String taxPassword) {
146146
this.taxPassword = taxPassword;
147147
}
148148

149-
public Double getAvailableBalance() {
149+
public java.math.BigDecimal getAvailableBalance() {
150150
return availableBalance;
151151
}
152152

153-
public void setAvailableBalance(Double availableBalance) {
153+
public void setAvailableBalance(java.math.BigDecimal availableBalance) {
154154
this.availableBalance = availableBalance;
155155
}
156156

157-
public Double getCommittedBalance() {
157+
public java.math.BigDecimal getCommittedBalance() {
158158
return committedBalance;
159159
}
160160

161-
public void setCommittedBalance(Double committedBalance) {
161+
public void setCommittedBalance(java.math.BigDecimal committedBalance) {
162162
this.committedBalance = committedBalance;
163163
}
164164

@@ -169,4 +169,4 @@ public String getTenantId() {
169169
public void setTenantId(String tenantId) {
170170
this.tenantId = tenantId;
171171
}
172-
}
172+
}

src/main/java/com/fiscalapi/models/Product.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Product extends BaseDto {
2929
/**
3030
* Precio unitario del producto sin impuestos (requerido).
3131
*/
32-
private double unitPrice;
32+
private java.math.BigDecimal unitPrice;
3333

3434
/**
3535
* Código de la unidad de medida. Catálogo del SAT c_ClaveUnidad.
@@ -101,7 +101,7 @@ public void setDescription(String description) {
101101
*
102102
* @return el precio unitario.
103103
*/
104-
public double getUnitPrice() {
104+
public java.math.BigDecimal getUnitPrice() {
105105
return unitPrice;
106106
}
107107

@@ -110,7 +110,7 @@ public double getUnitPrice() {
110110
*
111111
* @param unitPrice el precio unitario a establecer.
112112
*/
113-
public void setUnitPrice(double unitPrice) {
113+
public void setUnitPrice(java.math.BigDecimal unitPrice) {
114114
this.unitPrice = unitPrice;
115115
}
116116

src/main/java/com/fiscalapi/models/ProductTax.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ProductTax extends BaseDto {
3131
/**
3232
* Tasa del impuesto. El valor debe estar entre 0.00000 y 1.000000 (ej: 0.160000).
3333
*/
34-
private double rate;
34+
private java.math.BigDecimal rate;
3535

3636
/**
3737
* Código del impuesto según el catálogo del SAT (valores: "001", "002", "003").
@@ -93,7 +93,7 @@ public void setProductId(String productId) {
9393
*
9494
* @return la tasa del impuesto.
9595
*/
96-
public double getRate() {
96+
public java.math.BigDecimal getRate() {
9797
return rate;
9898
}
9999

@@ -102,7 +102,7 @@ public double getRate() {
102102
*
103103
* @param rate la tasa a establecer.
104104
*/
105-
public void setRate(double rate) {
105+
public void setRate(java.math.BigDecimal rate) {
106106
this.rate = rate;
107107
}
108108

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.fiscalapi.models;
2+
3+
import com.fiscalapi.common.BaseDto;
4+
5+
public class StampTransaction extends BaseDto {
6+
private int consecutive;
7+
8+
public int getConsecutive() {
9+
return consecutive;
10+
}
11+
12+
public void setConsecutive(int consecutive) {
13+
this.consecutive = consecutive;
14+
}
15+
16+
public UserLookupDto getFromPerson() {
17+
return fromPerson;
18+
}
19+
20+
public void setFromPerson(UserLookupDto fromPerson) {
21+
this.fromPerson = fromPerson;
22+
}
23+
24+
public UserLookupDto getToPerson() {
25+
return toPerson;
26+
}
27+
28+
public void setToPerson(UserLookupDto toPerson) {
29+
this.toPerson = toPerson;
30+
}
31+
32+
public int getAmount() {
33+
return amount;
34+
}
35+
36+
public void setAmount(int amount) {
37+
this.amount = amount;
38+
}
39+
40+
public int getTransactionType() {
41+
return transactionType;
42+
}
43+
44+
public void setTransactionType(int transactionType) {
45+
this.transactionType = transactionType;
46+
}
47+
48+
public String getReferenceId() {
49+
return referenceId;
50+
}
51+
52+
public void setReferenceId(String referenceId) {
53+
this.referenceId = referenceId;
54+
}
55+
56+
public String getComments() {
57+
return comments;
58+
}
59+
60+
public void setComments(String comments) {
61+
this.comments = comments;
62+
}
63+
64+
private UserLookupDto fromPerson;
65+
private UserLookupDto toPerson;
66+
private int amount;
67+
private int transactionType;
68+
private String referenceId;
69+
private String comments;
70+
}

0 commit comments

Comments
 (0)