Update contract recurring discount
Replaces the custom fields of an active recurring discount of a contract. The invoices that are not locked carry the new values on the discounts that the recurring discount gives them.
Requires the role contracts:write.
curl --request PATCH \
--url https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId} \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"customFields": {
"customField1": "value1",
"customField2": [
"value2",
"value3"
]
}
}
'import requests
url = "https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}"
payload = { "customFields": {
"customField1": "value1",
"customField2": ["value2", "value3"]
} }
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({customFields: {customField1: 'value1', customField2: ['value2', 'value3']}})
};
fetch('https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}', 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.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'customFields' => [
'customField1' => 'value1',
'customField2' => [
'value2',
'value3'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$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.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}"
payload := strings.NewReader("{\n \"customFields\": {\n \"customField1\": \"value1\",\n \"customField2\": [\n \"value2\",\n \"value3\"\n ]\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
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.patch("https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customFields\": {\n \"customField1\": \"value1\",\n \"customField2\": [\n \"value2\",\n \"value3\"\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customFields\": {\n \"customField1\": \"value1\",\n \"customField2\": [\n \"value2\",\n \"value3\"\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"planId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"planChargeId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"targetScope": "invoice",
"method": "fixed",
"amount": 2,
"description": "Desconto de fidelidade",
"startDate": "2023-12-25",
"invoiceCount": 2,
"distributionMode": "proportional",
"isActive": true,
"customFields": {
"customField1": "value1",
"customField2": [
"value2",
"value3"
]
}
}Path Parameters
Body
The custom fields that replace those of the recurring discount.
Response
A discount that a contract applies from a chosen billing cycle, for a number of billings or with no end. It is a fixed amount or a percentage on the invoice, a plan, one plan charge or the contract minimum.
What the discount applies to on each invoice: invoice (the whole invoice), plan (the line items of the plan), plan_charge (the line item of one plan charge of the plan), or contract_minimum_amount (the line item that the contract minimum adds).
invoice, plan, plan_charge, contract_minimum_amount How many billing acts that bill the target the discount applies to, counted from startDate over the open invoices, because an issued invoice keeps its discounts and spends no count. The invoices that one billing act splits among payment accounts spend one count together, so 12 counts on a quarterly fee last 12 quarters. Null means that the discount applies until it is deactivated.
x >= 1Must be a multiple of 1How a fixed discount reaches the invoices that one billing act splits among payment accounts: full takes the whole amount off each invoice, and proportional splits the amount among them in proportion to their totals. A percentage discount always applies to each invoice.
proportional, full curl --request PATCH \
--url https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId} \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"customFields": {
"customField1": "value1",
"customField2": [
"value2",
"value3"
]
}
}
'import requests
url = "https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}"
payload = { "customFields": {
"customField1": "value1",
"customField2": ["value2", "value3"]
} }
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({customFields: {customField1: 'value1', customField2: ['value2', 'value3']}})
};
fetch('https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}', 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.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'customFields' => [
'customField1' => 'value1',
'customField2' => [
'value2',
'value3'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$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.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}"
payload := strings.NewReader("{\n \"customFields\": {\n \"customField1\": \"value1\",\n \"customField2\": [\n \"value2\",\n \"value3\"\n ]\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
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.patch("https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customFields\": {\n \"customField1\": \"value1\",\n \"customField2\": [\n \"value2\",\n \"value3\"\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.useaira.com/v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customFields\": {\n \"customField1\": \"value1\",\n \"customField2\": [\n \"value2\",\n \"value3\"\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"planId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"planChargeId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"targetScope": "invoice",
"method": "fixed",
"amount": 2,
"description": "Desconto de fidelidade",
"startDate": "2023-12-25",
"invoiceCount": 2,
"distributionMode": "proportional",
"isActive": true,
"customFields": {
"customField1": "value1",
"customField2": [
"value2",
"value3"
]
}
}