curl --request POST \
--url https://api-sandbox.beinfi.com/billing/invoices/from-usage \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"send": true
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/invoices/from-usage"
payload = {
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"send": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customerId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
from: '2023-11-07T05:31:56Z',
to: '2023-11-07T05:31:56Z',
send: true
})
};
fetch('https://api-sandbox.beinfi.com/billing/invoices/from-usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-sandbox.beinfi.com/billing/invoices/from-usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customerId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'from' => '2023-11-07T05:31:56Z',
'to' => '2023-11-07T05:31:56Z',
'send' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-sandbox.beinfi.com/billing/invoices/from-usage"
payload := strings.NewReader("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"send\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-sandbox.beinfi.com/billing/invoices/from-usage")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"send\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/invoices/from-usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"send\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"payerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"invoiceNumber": "<string>",
"status": "draft",
"currency": "<string>",
"subtotal": "<string>",
"tax": "<string>",
"total": "<string>",
"amountDue": "<string>",
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"dueDate": "2023-11-07T05:31:56Z",
"finalizedAt": "2023-11-07T05:31:56Z",
"paidAt": "2023-11-07T05:31:56Z",
"successUrl": "<string>",
"cancelUrl": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"lineItems": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"type": "usage",
"meterId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"priceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"description": "<string>",
"quantity": "<string>",
"unitPrice": "<string>",
"amount": "<string>",
"proration": true
}
]
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"resource": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"errors": [
{
"field": "<string>",
"value": "<string>",
"constraint": "<string>",
"description": "<string>"
}
]
}Faturar uso acumulado
Soma o uso medido de uma inscrição no intervalo [from, to) e gera uma fatura, com os preços da versão publicada do produto (ou da tabela de preços do cliente, se houver). Serve para cobrar uso sem assinatura. Envie send: true para mandar a fatura por e-mail.
customerId aqui é o id da inscrição do cliente no produto, não o id do cliente.
curl --request POST \
--url https://api-sandbox.beinfi.com/billing/invoices/from-usage \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"send": true
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/invoices/from-usage"
payload = {
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"send": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customerId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
from: '2023-11-07T05:31:56Z',
to: '2023-11-07T05:31:56Z',
send: true
})
};
fetch('https://api-sandbox.beinfi.com/billing/invoices/from-usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-sandbox.beinfi.com/billing/invoices/from-usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customerId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'from' => '2023-11-07T05:31:56Z',
'to' => '2023-11-07T05:31:56Z',
'send' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-sandbox.beinfi.com/billing/invoices/from-usage"
payload := strings.NewReader("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"send\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-sandbox.beinfi.com/billing/invoices/from-usage")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"send\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/invoices/from-usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"send\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"payerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"invoiceNumber": "<string>",
"status": "draft",
"currency": "<string>",
"subtotal": "<string>",
"tax": "<string>",
"total": "<string>",
"amountDue": "<string>",
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"dueDate": "2023-11-07T05:31:56Z",
"finalizedAt": "2023-11-07T05:31:56Z",
"paidAt": "2023-11-07T05:31:56Z",
"successUrl": "<string>",
"cancelUrl": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"lineItems": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"type": "usage",
"meterId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"priceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"description": "<string>",
"quantity": "<string>",
"unitPrice": "<string>",
"amount": "<string>",
"proration": true
}
]
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"resource": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"errors": [
{
"field": "<string>",
"value": "<string>",
"constraint": "<string>",
"description": "<string>"
}
]
}Autorizações
Chave secreta da conta: Authorization: Bearer sk_test_… ou sk_live_…. Use só no servidor.
Corpo
Id da inscrição do cliente no produto cujo uso será faturado. Não é o id do cliente.
Início do intervalo (incluído).
Fim do intervalo (não incluído).
true envia a fatura por e-mail assim que ela é criada.
Resposta
Criado.
O que um cliente deve: itens, totais e status. Status: draft → open → paid, ou void / uncollectible.
Id da inscrição do cliente no produto. Preenchido em faturas de produto, uso ou assinatura.
Id do cliente que paga. Preenchido em faturas avulsas.
Assinatura que gerou a fatura
Número sequencial da fatura
draft (em montagem), open (emitida, aguardando pagamento), paid, void (cancelada) ou uncollectible (dada como perdida).
draft, open, paid, void, uncollectible Moeda, em código ISO 4217 (BRL).
Soma dos itens antes de impostos e descontos.
Impostos da fatura.
Valor final da fatura.
Quanto ainda falta pagar.
Início do período cobrado
Fim do período cobrado
Data de vencimento.
Quando a fatura foi emitida.
Quando a fatura foi paga.
Para onde o checkout leva o comprador depois do pagamento.
Para onde o checkout leva o comprador se ele desistir.
Show child attributes
Show child attributes