Pular para o conteúdo principal

Calculate

Endpoint para calcular pricing baseado em score de credito e parametros do emprestimo.

Endpoint

MétodoEndpointDescriçãoPermissão
POST/api/v1/calculateCalcular pricingPRICING_CALCULATE

Request

CampoTipoObrigatórioDescrição
productIdstring (UUID)SimID do produto
creditScoreintegerSimScore de credito (0-1000)
requestedAmountnumberSimValor solicitado
numberOfInstallmentsintegerSimNúmero de parcelas (1-360)
customerIdstring (UUID)NãoID do cliente
contextobjectNãoContexto adicional para regras de decisão

Response

CampoTipoDescrição
riskBandobjectFaixa de risco aplicada
pricingRuleobjectRegra de pricing utilizada
interestRatenumberTaxa de juros final
baseRatenumberTaxa base
rateSpreadnumberSpread aplicado
feesarrayDetalhamento das taxas
totalFeesnumberTotal de taxas
commissionsarrayDetalhamento das comissoes
totalCommissionsnumberTotal de comissoes
insurancesarrayDetalhamento dos seguros
totalInsurancenumberTotal de premios de seguro
effectiveAnnualRatenumberTaxa efetiva anual (CET)
approvedbooleanSe o pricing foi aprovado
rejectionReasonstringMotivo da rejeicao (se nao aprovado)
decisionTraceIdstringID 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 -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
}
}
}'

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ódigoErroDescrição
400VALIDATIONCampos obrigatorios ausentes ou inválidos
404NOT_FOUNDProduto nao encontrado
422UNPROCESSABLE_ENTITYNenhuma risk band ou pricing rule encontrada para os parametros