Calculate
Endpoint para calcular pricing baseado em score de credito e parametros do emprestimo.
Endpoint
| Método | Endpoint | Descrição | Permissão |
|---|---|---|---|
| POST | /api/v1/calculate | Calcular pricing | PRICING_CALCULATE |
Request
| Campo | Tipo | Obrigatório | Descrição |
|---|---|---|---|
productId | string (UUID) | Sim | ID do produto |
creditScore | integer | Sim | Score de credito (0-1000) |
requestedAmount | number | Sim | Valor solicitado |
numberOfInstallments | integer | Sim | Número de parcelas (1-360) |
customerId | string (UUID) | Não | ID do cliente |
context | object | Não | Contexto adicional para regras de decisão |
Response
| Campo | Tipo | Descrição |
|---|---|---|
riskBand | object | Faixa de risco aplicada |
pricingRule | object | Regra de pricing utilizada |
interestRate | number | Taxa de juros final |
baseRate | number | Taxa base |
rateSpread | number | Spread aplicado |
fees | array | Detalhamento das taxas |
totalFees | number | Total de taxas |
commissions | array | Detalhamento das comissoes |
totalCommissions | number | Total de comissoes |
insurances | array | Detalhamento dos seguros |
totalInsurance | number | Total de premios de seguro |
effectiveAnnualRate | number | Taxa efetiva anual (CET) |
approved | boolean | Se o pricing foi aprovado |
rejectionReason | string | Motivo da rejeicao (se nao aprovado) |
decisionTraceId | string | ID do trace do Decision Engine (se aplicável) |
Calcular Pricing
POST /api/v1/calculate
Calcula o pricing para um emprestimo baseado no score e parametros informados.
- cURL
- JavaScript
curl -X POST 'https://pricing.stg.catalisa.app/api/v1/calculate' \
-H 'Authorization: Bearer SEU_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"data": {
"type": "pricing-calculations",
"attributes": {
"productId": "550e8400-e29b-41d4-a716-446655440000",
"creditScore": 750,
"requestedAmount": 10000,
"numberOfInstallments": 12
}
}
}'
const response = await fetch('https://pricing.stg.catalisa.app/api/v1/calculate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: {
type: 'pricing-calculations',
attributes: {
productId: '550e8400-e29b-41d4-a716-446655440000',
creditScore: 750,
requestedAmount: 10000,
numberOfInstallments: 12,
},
},
}),
});
const { data } = await response.json();
if (data.attributes.approved) {
console.log(`Taxa aprovada: ${(data.attributes.interestRate * 100).toFixed(2)}% a.m.`);
console.log(`Total de taxas: R$ ${data.attributes.totalFees.toFixed(2)}`);
} else {
console.log(`Rejeitado: ${data.attributes.rejectionReason}`);
}
Response (200 OK) - Aprovado
{
"data": {
"type": "pricing-calculations",
"attributes": {
"riskBand": {
"id": "550e8400-e29b-41d4-a716-446655440001",
"name": "LOW_RISK",
"minScore": 700,
"maxScore": 850
},
"pricingRule": {
"id": "550e8400-e29b-41d4-a716-446655440002",
"name": "Standard Personal Loan",
"ruleType": "DB_RULE"
},
"interestRate": 0.0199,
"baseRate": 0.0149,
"rateSpread": 0.005,
"fees": [
{
"feeType": "REGISTRATION",
"name": "Taxa de Cadastro",
"amount": 150.00,
"calculationMethod": "FIXED",
"isFinanced": true
},
{
"feeType": "ANALYSIS",
"name": "Taxa de Analise",
"amount": 250.00,
"calculationMethod": "PERCENTAGE_OF_PRINCIPAL",
"isFinanced": false
}
],
"totalFees": 400.00,
"commissions": [
{
"commissionType": "SALES",
"name": "Comissao Vendedor",
"amount": 150.00
}
],
"totalCommissions": 150.00,
"insurances": [
{
"insuranceType": "LIFE",
"name": "Seguro Prestamista",
"monthlyPremium": 5.00,
"totalPremium": 60.00
}
],
"totalInsurance": 60.00,
"effectiveAnnualRate": 0.2668,
"approved": true
}
}
}
Response (200 OK) - Rejeitado
{
"data": {
"type": "pricing-calculations",
"attributes": {
"riskBand": null,
"pricingRule": null,
"interestRate": 0,
"baseRate": 0,
"rateSpread": 0,
"fees": [],
"totalFees": 0,
"approved": false,
"rejectionReason": "Score abaixo do mínimo aceito para este produto"
}
}
}
Calculo com Contexto Adicional
Para regras baseadas em Decision Engine, voce pode passar contexto adicional:
const response = await fetch('https://pricing.stg.catalisa.app/api/v1/calculate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: {
type: 'pricing-calculations',
attributes: {
productId: 'product-uuid',
creditScore: 750,
requestedAmount: 25000,
numberOfInstallments: 24,
customerId: 'customer-uuid',
context: {
employmentType: 'CLT',
monthlyIncome: 8000,
timeAtCurrentJob: 36,
existingCustomer: true,
},
},
},
}),
});
O campo context e passado ao Decision Engine para avaliação de regras dinamicas.
Exemplo de Fluxo Completo
// Funcao para calcular pricing e exibir detalhes
async function calculateLoanPricing(productId, creditScore, amount, installments) {
const response = await fetch('https://pricing.stg.catalisa.app/api/v1/calculate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: {
type: 'pricing-calculations',
attributes: {
productId,
creditScore,
requestedAmount: amount,
numberOfInstallments: installments,
},
},
}),
});
const { data } = await response.json();
const result = data.attributes;
if (!result.approved) {
return {
approved: false,
reason: result.rejectionReason,
};
}
// Calcular valores finais
const principal = amount + (result.fees.filter(f => f.isFinanced).reduce((sum, f) => sum + f.amount, 0));
const monthlyRate = result.interestRate;
// PMT = P * [r(1+r)^n] / [(1+r)^n - 1]
const pmt = principal * (monthlyRate * Math.pow(1 + monthlyRate, installments)) /
(Math.pow(1 + monthlyRate, installments) - 1);
return {
approved: true,
riskBand: result.riskBand.name,
monthlyRate: `${(result.interestRate * 100).toFixed(2)}%`,
effectiveAnnualRate: `${(result.effectiveAnnualRate * 100).toFixed(2)}%`,
totalFees: result.totalFees,
monthlyPayment: pmt.toFixed(2),
totalPayment: (pmt * installments).toFixed(2),
totalInsurance: result.totalInsurance || 0,
};
}
// Uso
const pricing = await calculateLoanPricing(
'product-uuid',
750, // score
10000, // valor
12 // parcelas
);
console.log(pricing);
// {
// approved: true,
// riskBand: "LOW_RISK",
// monthlyRate: "1.99%",
// effectiveAnnualRate: "26.68%",
// totalFees: 400,
// monthlyPayment: "932.06",
// totalPayment: "11184.72",
// totalInsurance: 60
// }
Erros Comuns
| Código | Erro | Descrição |
|---|---|---|
| 400 | VALIDATION | Campos obrigatorios ausentes ou inválidos |
| 404 | NOT_FOUND | Produto nao encontrado |
| 422 | UNPROCESSABLE_ENTITY | Nenhuma risk band ou pricing rule encontrada para os parametros |