curl --request POST \
--url https://api.fintoc.com/v1/charges \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"amount": 5000,
"currency": "CLP",
"subscription_id": "sub_m7N9rAWJS9dWDKEe",
"metadata": {
"order_id": "0001"
}
}
'import requests
url = "https://api.fintoc.com/v1/charges"
payload = {
"amount": 5000,
"currency": "CLP",
"subscription_id": "sub_m7N9rAWJS9dWDKEe",
"metadata": { "order_id": "0001" }
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
amount: 5000,
currency: 'CLP',
subscription_id: 'sub_m7N9rAWJS9dWDKEe',
metadata: {order_id: '0001'}
})
};
fetch('https://api.fintoc.com/v1/charges', 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.fintoc.com/v1/charges",
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([
'amount' => 5000,
'currency' => 'CLP',
'subscription_id' => 'sub_m7N9rAWJS9dWDKEe',
'metadata' => [
'order_id' => '0001'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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.fintoc.com/v1/charges"
payload := strings.NewReader("{\n \"amount\": 5000,\n \"currency\": \"CLP\",\n \"subscription_id\": \"sub_m7N9rAWJS9dWDKEe\",\n \"metadata\": {\n \"order_id\": \"0001\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<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.post("https://api.fintoc.com/v1/charges")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": 5000,\n \"currency\": \"CLP\",\n \"subscription_id\": \"sub_m7N9rAWJS9dWDKEe\",\n \"metadata\": {\n \"order_id\": \"0001\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fintoc.com/v1/charges")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": 5000,\n \"currency\": \"CLP\",\n \"subscription_id\": \"sub_m7N9rAWJS9dWDKEe\",\n \"metadata\": {\n \"order_id\": \"0001\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "ch_o9YDuRzUez2GqV4x",
"object": "charge",
"amount": 5000,
"created_at": "2021-05-17T17:04:10.284Z",
"currency": "CLP",
"failure_code": null,
"metadata": {
"order_id": "0001"
},
"mode": "live",
"status": "pending",
"subscription_id": "sub_m7N9rAWJS9dWDKEe"
}{
"error": {
"type": "invalid_request_error",
"code": "missing_parameter",
"param": "subscription_id",
"message": "Missing required param: subscription_id",
"doc_url": "https://docs.fintoc.com/reference/errors"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "Invalid API Key: invalid-*oken"
}
}{
"error": {
"type": "invalid_request_error",
"code": "forbidden_request",
"param": null,
"message": "Can not create charge if subscription is not active",
"doc_url": "https://docs.fintoc.com/reference/errors"
}
}{
"error": {
"type": "invalid_request_error",
"code": "missing_resource",
"param": "id",
"message": "No such subscription: sub_LDcjBFqGpKuj8FPV",
"doc_url": "https://docs.fintoc.com/reference/errors"
}
}Create a charge
Creates a charge on an active subscription. The charge starts with status pending, and Fintoc collects the charge from the subscription’s bank account on the next collection cycle. In test mode, Fintoc simulates the collection and updates the charge status asynchronously after creation.
curl --request POST \
--url https://api.fintoc.com/v1/charges \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"amount": 5000,
"currency": "CLP",
"subscription_id": "sub_m7N9rAWJS9dWDKEe",
"metadata": {
"order_id": "0001"
}
}
'import requests
url = "https://api.fintoc.com/v1/charges"
payload = {
"amount": 5000,
"currency": "CLP",
"subscription_id": "sub_m7N9rAWJS9dWDKEe",
"metadata": { "order_id": "0001" }
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
amount: 5000,
currency: 'CLP',
subscription_id: 'sub_m7N9rAWJS9dWDKEe',
metadata: {order_id: '0001'}
})
};
fetch('https://api.fintoc.com/v1/charges', 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.fintoc.com/v1/charges",
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([
'amount' => 5000,
'currency' => 'CLP',
'subscription_id' => 'sub_m7N9rAWJS9dWDKEe',
'metadata' => [
'order_id' => '0001'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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.fintoc.com/v1/charges"
payload := strings.NewReader("{\n \"amount\": 5000,\n \"currency\": \"CLP\",\n \"subscription_id\": \"sub_m7N9rAWJS9dWDKEe\",\n \"metadata\": {\n \"order_id\": \"0001\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<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.post("https://api.fintoc.com/v1/charges")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": 5000,\n \"currency\": \"CLP\",\n \"subscription_id\": \"sub_m7N9rAWJS9dWDKEe\",\n \"metadata\": {\n \"order_id\": \"0001\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fintoc.com/v1/charges")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": 5000,\n \"currency\": \"CLP\",\n \"subscription_id\": \"sub_m7N9rAWJS9dWDKEe\",\n \"metadata\": {\n \"order_id\": \"0001\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "ch_o9YDuRzUez2GqV4x",
"object": "charge",
"amount": 5000,
"created_at": "2021-05-17T17:04:10.284Z",
"currency": "CLP",
"failure_code": null,
"metadata": {
"order_id": "0001"
},
"mode": "live",
"status": "pending",
"subscription_id": "sub_m7N9rAWJS9dWDKEe"
}{
"error": {
"type": "invalid_request_error",
"code": "missing_parameter",
"param": "subscription_id",
"message": "Missing required param: subscription_id",
"doc_url": "https://docs.fintoc.com/reference/errors"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "Invalid API Key: invalid-*oken"
}
}{
"error": {
"type": "invalid_request_error",
"code": "forbidden_request",
"param": null,
"message": "Can not create charge if subscription is not active",
"doc_url": "https://docs.fintoc.com/reference/errors"
}
}{
"error": {
"type": "invalid_request_error",
"code": "missing_resource",
"param": "id",
"message": "No such subscription: sub_LDcjBFqGpKuj8FPV",
"doc_url": "https://docs.fintoc.com/reference/errors"
}
}Cuerpo
Respuesta
The created charge, with status pending. In test mode, the charge status updates asynchronously after creation to simulate the collection.
A charge is a single collection from the bank account of a subscription. You create a charge on an active subscription, and Fintoc collects the charge from the subscription's bank account on the next collection cycle. A charge starts as pending and ends as succeeded, failed, or canceled.
Reason why the charge failed. Always null unless status is failed. One of insufficient_funds (the bank account did not have enough funds), subscription_inactive (the subscription is no longer active at the bank), charge_amount_limit_exceeded (the amount exceeds the bank's per-charge limit), bank_account_unavailable (the bank account is closed, blocked, or could not be found), or other.
insufficient_funds, subscription_inactive, charge_amount_limit_exceeded, bank_account_unavailable, other, null "insufficient_funds"
¿Esta página le ayudó?