Assinaturas
Cobrar Proporcional
POST
/v1/subscriptions/:subscriptionId/prorataBase URL Produção:
https://api.validapay.com.brBase URL Sandbox:
https://sandbox.validapay.com.brAutenticação
bearerAuthorizationstring · header · obrigatório
Envie no header:
Authorization: Bearer {{token}}Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| subscriptionId | string | Required | Subscriptionid |
Gera uma cobrança pelo valor proporcional ao período já utilizado no mês, útil quando o cliente muda de plano no meio do ciclo.
Calcular pró-rata (sem cobrar)
| Campo | Obrig. | Tipo |
|---|---|---|
old.priceId | ✅ | string |
old.quantity | ❌ | number |
new.priceId | ✅ | string |
new.quantity | ❌ | number |
Body
application/json
Content-Type:application/json
{
"old": {
"priceId": "price_xxx",
"quantity": 1
},
"new": {
"priceId": "price_yyy",
"quantity": 1
}
}Schema
| Field | Type | Required | Description |
|---|---|---|---|
old | object | - | - |
new | object | - | - |
Headers
| Name | Type | Value | Required |
|---|---|---|---|
| Content-Type | - | application/json | Optional |
const url = 'https://sandbox.validapay.com.br/v1/subscriptions/:subscriptionId/prorata';
const options = {
method: 'POST',
headers: {
'Authorization': 'Bearer {{token}}',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"old": {
"priceId": "price_xxx",
"quantity": 1
},
"new": {
"priceId": "price_yyy",
"quantity": 1
}
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));Response Examples
200200
{
"subscriptionId": "sub_xxx",
"currentAmount": 99.9,
"newAmount": 199.9,
"prorataAmount": 45.48,
"remainingDays": 15,
"cycleDays": 31,
"currentCredit": 48.34,
"nextCycleChargeDate": "2024-02-15"
}404404 old
{
"code": "OLD_PRICE_NOT_FOUND"
}404404 new
{
"code": "NEW_PRICE_NOT_FOUND"
}404404 sub
{
"code": "SUBSCRIPTION_NOT_FOUND"
}