curl --request POST \
--url https://api-sandbox.beinfi.com/billing/coupons \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"percentOff": "<string>",
"durationInCycles": 123,
"maxRedemptions": 123,
"redeemBy": "2023-11-07T05:31:56Z"
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/coupons"
payload = {
"code": "<string>",
"percentOff": "<string>",
"durationInCycles": 123,
"maxRedemptions": 123,
"redeemBy": "2023-11-07T05:31:56Z"
}
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({
code: '<string>',
percentOff: '<string>',
durationInCycles: 123,
maxRedemptions: 123,
redeemBy: '2023-11-07T05:31:56Z'
})
};
fetch('https://api-sandbox.beinfi.com/billing/coupons', 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/coupons",
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([
'code' => '<string>',
'percentOff' => '<string>',
'durationInCycles' => 123,
'maxRedemptions' => 123,
'redeemBy' => '2023-11-07T05:31:56Z'
]),
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/coupons"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"percentOff\": \"<string>\",\n \"durationInCycles\": 123,\n \"maxRedemptions\": 123,\n \"redeemBy\": \"2023-11-07T05:31:56Z\"\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/coupons")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"percentOff\": \"<string>\",\n \"durationInCycles\": 123,\n \"maxRedemptions\": 123,\n \"redeemBy\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/coupons")
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 \"code\": \"<string>\",\n \"percentOff\": \"<string>\",\n \"durationInCycles\": 123,\n \"maxRedemptions\": 123,\n \"redeemBy\": \"2023-11-07T05:31:56Z\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"code": "<string>",
"percentOff": "<string>",
"duration": "once",
"timesRedeemed": 123,
"status": "active",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"durationInCycles": 123,
"maxRedemptions": 123,
"redeemBy": "2023-11-07T05:31:56Z"
}{
"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 cupom
Cria um cupom de desconto percentual. O comprador digita o code no checkout para aplicá-lo à fatura.
curl --request POST \
--url https://api-sandbox.beinfi.com/billing/coupons \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"percentOff": "<string>",
"durationInCycles": 123,
"maxRedemptions": 123,
"redeemBy": "2023-11-07T05:31:56Z"
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/coupons"
payload = {
"code": "<string>",
"percentOff": "<string>",
"durationInCycles": 123,
"maxRedemptions": 123,
"redeemBy": "2023-11-07T05:31:56Z"
}
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({
code: '<string>',
percentOff: '<string>',
durationInCycles: 123,
maxRedemptions: 123,
redeemBy: '2023-11-07T05:31:56Z'
})
};
fetch('https://api-sandbox.beinfi.com/billing/coupons', 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/coupons",
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([
'code' => '<string>',
'percentOff' => '<string>',
'durationInCycles' => 123,
'maxRedemptions' => 123,
'redeemBy' => '2023-11-07T05:31:56Z'
]),
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/coupons"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"percentOff\": \"<string>\",\n \"durationInCycles\": 123,\n \"maxRedemptions\": 123,\n \"redeemBy\": \"2023-11-07T05:31:56Z\"\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/coupons")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"percentOff\": \"<string>\",\n \"durationInCycles\": 123,\n \"maxRedemptions\": 123,\n \"redeemBy\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/coupons")
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 \"code\": \"<string>\",\n \"percentOff\": \"<string>\",\n \"durationInCycles\": 123,\n \"maxRedemptions\": 123,\n \"redeemBy\": \"2023-11-07T05:31:56Z\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"code": "<string>",
"percentOff": "<string>",
"duration": "once",
"timesRedeemed": 123,
"status": "active",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"durationInCycles": 123,
"maxRedemptions": 123,
"redeemBy": "2023-11-07T05:31:56Z"
}{
"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.
Corpo
Dados de um novo cupom.
Código do cupom: de 3 a 32 caracteres entre letras maiúsculas, números, _ e - (ex.: BLACKFRIDAY-20).
Percentual de desconto, em texto decimal, maior que 0 e até 100.
once (só na primeira fatura), repeating (durante durationInCycles ciclos) ou forever (em todas as faturas).
once, repeating, forever Obrigatório (1 ou mais) quando duration é repeating; omita nos demais casos.
Limite total de usos. Omita para não limitar.
Prazo final para aplicar o cupom. Omita para não ter prazo.
Resposta
Criado.
Um desconto percentual que o comprador aplica no checkout com o code. Em assinaturas, duration define por quantos ciclos o desconto vale.
O código que o comprador digita no checkout.
Percentual de desconto, em texto decimal ("15" = 15%).
once (só na primeira fatura), repeating (durante durationInCycles ciclos) ou forever (em todas as faturas).
once, repeating, forever Quantas vezes o cupom já foi usado.
active (aceito no checkout) ou archived (não aceito mais).
active, archived Quantos ciclos o desconto vale. Só em cupons repeating.
Quantas vezes o cupom pode ser usado no total. null = sem limite.
Até quando o cupom pode ser aplicado. null = sem prazo.