curl --request POST \
--url https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [
{}
]
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions"
payload = {
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [{}]
}
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',
productVersionId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
anchor: '2023-11-07T05:31:56Z',
items: [{}]
})
};
fetch('https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions', 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/products/{productID}/subscriptions",
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',
'productVersionId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'anchor' => '2023-11-07T05:31:56Z',
'items' => [
[
]
]
]),
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/products/{productID}/subscriptions"
payload := strings.NewReader("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\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/products/{productID}/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions")
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 \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"subscription": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "trialing",
"billingCycle": "weekly",
"collectionMethod": "charge_automatically",
"billingMode": "arrears",
"anchor": "2023-11-07T05:31:56Z",
"nextBillingDate": "2023-11-07T05:31:56Z",
"startedAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z",
"items": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "recurring_fee",
"timing": "advance",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"createdAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z"
}
]
},
"period": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"status": "open",
"invoiceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"errors": [
{
"field": "<string>",
"value": "<string>",
"constraint": "<string>",
"description": "<string>"
}
]
}Criar assinatura
Cria uma assinatura do cliente no produto e abre o primeiro período de cobrança. A resposta traz a assinatura e esse período.
customerId é o id da inscrição do cliente no produto (de POST /metering/products/{productID}/customers), não o id do cliente.
curl --request POST \
--url https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [
{}
]
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions"
payload = {
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [{}]
}
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',
productVersionId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
anchor: '2023-11-07T05:31:56Z',
items: [{}]
})
};
fetch('https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions', 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/products/{productID}/subscriptions",
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',
'productVersionId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'anchor' => '2023-11-07T05:31:56Z',
'items' => [
[
]
]
]),
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/products/{productID}/subscriptions"
payload := strings.NewReader("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\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/products/{productID}/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions")
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 \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"subscription": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "trialing",
"billingCycle": "weekly",
"collectionMethod": "charge_automatically",
"billingMode": "arrears",
"anchor": "2023-11-07T05:31:56Z",
"nextBillingDate": "2023-11-07T05:31:56Z",
"startedAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z",
"items": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "recurring_fee",
"timing": "advance",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"createdAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z"
}
]
},
"period": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"status": "open",
"invoiceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<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.
Cabeçalhos
Chave única por operação (um UUID serve). Repetir com a mesma chave devolve a resposta original.
Parâmetros de caminho
ID do produto.
Corpo
Id da inscrição do cliente neste produto.
Versão do produto que a assinatura cobra. Se omitido, usa a versão publicada mais recente.
Data de início do ciclo, que define o dia das próximas cobranças. Se omitido, é o momento da criação.
O que a assinatura cobra, item a item. Cada item tem kind: recurring_fee (mensalidade fixa, com timing advance para cobrar no início do período ou arrears para cobrar no fim; o padrão é advance), credit_grant (créditos liberados a cada ciclo) ou metered_usage (uso medido, cobrado no fim do período). Só recurring_fee aceita timing. Se omitido, os itens seguem o modelo de preço do produto: um produto pré-pago cobra a mensalidade no início e libera créditos; os demais cobram a mensalidade e o uso no fim do período.
Show child attributes
Show child attributes