|
|
@@ -588,35 +588,16 @@
|
|
|
return { state: 'success', data: body };
|
|
|
}
|
|
|
const code = body?.code ?? body?.error;
|
|
|
- const fallbackMessage = body?.data?.message ?? body?.message ?? body?.msg ?? raw ?? 'Falha ao confirmar pagamento.';
|
|
|
+ const backendMessage = body?.message ?? body?.msg ?? body?.data?.message ?? raw ?? '';
|
|
|
if (code === 'E_PAYMENT_PENDING' || body?.data?.status === 0) {
|
|
|
return { state: 'pending', message: 'Pagamento pendente. Assim que confirmado, você será avisado.' };
|
|
|
}
|
|
|
- const message = mapPaymentError(code, res.status, fallbackMessage);
|
|
|
+ const normalizedBackendMessage = typeof backendMessage === 'string' ? backendMessage.trim() : '';
|
|
|
+ const normalizedRaw = typeof raw === 'string' ? raw.trim() : '';
|
|
|
+ const message = normalizedBackendMessage || normalizedRaw || 'Não foi possível confirmar o pagamento.';
|
|
|
return { state: 'error', message };
|
|
|
}
|
|
|
|
|
|
- function mapPaymentError(code, status, fallback) {
|
|
|
- const normalized = code?.toUpperCase?.();
|
|
|
- switch (normalized) {
|
|
|
- case 'E_VALIDATE':
|
|
|
- return 'Payment_id inválido. Registre uma nova CPR para gerar outro QR Code.';
|
|
|
- case 'E_NOT_FOUND':
|
|
|
- return 'Pagamento não encontrado. Gere um novo QR Code.';
|
|
|
- case 'E_PAYMENT_STATUS':
|
|
|
- return 'Pagamento em status inválido. Gere um novo QR Code.';
|
|
|
- case 'E_CPR_NOT_FOUND':
|
|
|
- return 'CPR não vinculada ao pagamento. Entre em contato com o suporte.';
|
|
|
- case 'E_EXTERNAL':
|
|
|
- return 'Erro externo ao confirmar pagamento. Tente novamente em instantes.';
|
|
|
- default:
|
|
|
- if (status === 502) {
|
|
|
- return 'Erro externo ao confirmar pagamento. Tente novamente em instantes.';
|
|
|
- }
|
|
|
- return fallback ?? 'Não foi possível confirmar o pagamento.';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
function handlePaymentConfirmationSuccess(payload) {
|
|
|
const message = payload?.data?.message ?? payload?.message ?? 'Pagamento confirmado com sucesso.';
|
|
|
submitSuccess = message;
|