fix: use isTypeOf for SAT status request checking
The StatusRequest class has an isTypeOf method that properly checks the status. Using getValue() and comparing numbers was unreliable. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -114,29 +114,21 @@ export async function verifySatRequest(
|
|||||||
): Promise<VerifyResult> {
|
): Promise<VerifyResult> {
|
||||||
try {
|
try {
|
||||||
const result = await service.verify(requestId);
|
const result = await service.verify(requestId);
|
||||||
|
const statusRequest = result.getStatusRequest();
|
||||||
|
|
||||||
const statusCode = result.getStatusRequest().getValue();
|
// Usar isTypeOf para determinar el estado
|
||||||
let status: VerifyResult['status'];
|
let status: VerifyResult['status'];
|
||||||
|
if (statusRequest.isTypeOf('Finished')) {
|
||||||
// Los valores del SAT para estado de solicitud (getValue retorna número o string)
|
|
||||||
const codeNum = typeof statusCode === 'string' ? parseInt(statusCode, 10) : statusCode;
|
|
||||||
switch (codeNum) {
|
|
||||||
case 1:
|
|
||||||
status = 'pending';
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
status = 'processing';
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
status = 'ready';
|
status = 'ready';
|
||||||
break;
|
} else if (statusRequest.isTypeOf('InProgress')) {
|
||||||
case 4:
|
status = 'processing';
|
||||||
|
} else if (statusRequest.isTypeOf('Accepted')) {
|
||||||
|
status = 'pending';
|
||||||
|
} else if (statusRequest.isTypeOf('Failure')) {
|
||||||
status = 'failed';
|
status = 'failed';
|
||||||
break;
|
} else if (statusRequest.isTypeOf('Rejected')) {
|
||||||
case 5:
|
|
||||||
status = 'rejected';
|
status = 'rejected';
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
status = 'pending';
|
status = 'pending';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user