Adding Payments
HTTP POST to register an invoice or checkout with Branta.
Adds a new payment to Branta. Expires after ttl seconds.
Authorization header with Bearer token is required to authorize the request. Format: Bearer {your_api_key}. This API key is unique to each client and must be included in the header of every request. Failure to provide a valid API key will result in an unauthorized error.
Keep your API key confidential.
Branta will remove the payment after ttl seconds.
86400Payment DescriptionOptional stringified JSON to show the user.
{"Name": "S*****", "Email": "s******.com"}Payment created successfully
No content
Unauthorized
Unprocessable Content
POST /v2/payments HTTP/1.1
Host: staging.branta.pro
Authorization: text
Content-Type: application/json
Accept: */*
Content-Length: 244
{
"destinations": [
{
"value": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
"zk": false
},
{
"value": "n2s5RV76sAMnQIOTMeRLsKkbS53g2v4gFUnH7i/RtRg4ZpIrDQq8WohDP9obSLLBGVrSnc8dR9TUC89veSg=",
"zk": true
}
],
"description": "Example Description (Optional)",
"ttl": "86400"
}No content
Encryption
To encrypt an address as Zero-Knowledge, use the AES encryption algorithm below.
async function encrypt(value, secret) {
const keyData = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(secret));
const key = await crypto.subtle.importKey('raw', keyData, { name: 'AES-GCM' }, false, ['encrypt']);
const iv = crypto.getRandomValues(new Uint8Array(12));
const encrypted = await crypto.subtle.encrypt(
{ name: 'AES-GCM', iv: iv },
key,
new TextEncoder().encode(value)
);
const combined = new Uint8Array(iv.length + encrypted.byteLength);
combined.set(iv, 0);
combined.set(new Uint8Array(encrypted), iv.length);
return btoa(String.fromCharCode(...combined));
}TTL
Each payment has a Time-to-Live (TTL) in seconds associated with it. Branta will remove the payment from our system after TTL seconds from posting.
Minimum TTL: 30 seconds (Requests below this range will default to 30 seconds)
Maximum TTL: 31536000 seconds (Requests above this range will default to 1 year)
Invalid TTLs will be set to 7 days.
Some common values are:
15 minutes
900
60 minutes
3600
1 day
86400
7 days
604800
30 days
2592000
1 year
31536000
Javascript
const url = "https://staging.branta.pro/v2/payments";
const apiToken = "your token here";
const payload = {
"destinations": [
{
"value": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
"zk": false
},
{
// Use encryption algorithm from above
"value": await encrypt("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", "my-secret"),
"zk": true
}
],
"ttl": "86400"
}
const options = {
method: "POST",
headers: {
"API_KEY": apiToken,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
};
fetch(url, options)
.then(response => {
console.log("Response Status Code:", response.status);
})
.catch(error => {
console.error("An error occurred:", error);
});Python
import requests
url = "https://staging.branta.pro/v2/payments"
api_token = "your token here"
payload = {
"destinations": [
{
"value": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
"zk": False,
}
],
"ttl": "86400"
}
headers = {
"API_KEY": api_token,
"Content-Type": "application/json"
}
try:
response = requests.post(url, json=payload, headers=headers)
print("Response:", response.status_code)
except requests.exceptions.RequestException as e:
print("An error occurred:", e)Ruby
require 'net/http'
require 'uri'
require 'json'
url = URI.parse("https://staging.branta.pro/v1/payments")
api_token = "your token here"
payload = {
"destinations": [
{
"payment": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
"zk": true
}
],
"ttl": "86400"
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.path, {
"API_KEY" => api_token,
"Content-Type" => "application/json"
})
request.body = payload.to_json
begin
response = http.request(request)
puts "Response Status Code: #{response.code}"
rescue => e
puts "An error occurred: #{e.message}"
endLast updated