Create a charge
POST
https://api.ledgerline.dev /v2/charges Charge a payment source. If your API key is in a sandbox, the source won't actually be charged.
Request body application/x-www-form-urlencoded
amountintegerrequiredAmount intended to be collected, in the smallest currency unit (e.g. 100 cents to charge $1.00). The minimum is $0.50 US or equivalent.
currencystringrequiredThree-letter ISO currency code, in lowercase.
customerstringThe ID of an existing customer to charge.
descriptionstringAn arbitrary string attached to the object, shown in the Dashboard and on receipts.
receipt_emailstringThe email address to send this charge's receipt to.
metadataobjectSet of key-value pairs that you can attach to an object.
capturebooleanWhether to capture the charge immediately. Defaults to true.
{
"amount": 4800,
"currency": "usd",
"customer": "string",
"description": "string",
"receipt_email": "string",
"metadata": {},
"capture": true
}Code samples
cURL
curl -X POST "https://api.ledgerline.dev/v2/charges" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d '{"amount":4800,"currency":"usd","customer":"string","description":"string","receipt_email":"string","metadata":{},"capture":true}'TypeScript
const res = await fetch('https://api.ledgerline.dev/v2/charges', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({"amount":4800,"currency":"usd","customer":"string","description":"string","receipt_email":"string","metadata":{},"capture":true}),
});
const data = await res.json();Python
import requests
res = requests.request(
"POST",
"https://api.ledgerline.dev/v2/charges",
headers={
"Content-Type": "application/x-www-form-urlencoded",
},
json={"amount": 4800, "currency": "usd", "customer": "string", "description": "string", "receipt_email": "string", "metadata": {}, "capture": True},
)
data = res.json()Go
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
req, _ := http.NewRequest("POST", "https://api.ledgerline.dev/v2/charges", strings.NewReader(`{"amount":4800,"currency":"usd","customer":"string","description":"string","receipt_email":"string","metadata":{},"capture":true}`))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.ledgerline.dev/v2/charges');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"amount":4800,"currency":"usd","customer":"string","description":"string","receipt_email":"string","metadata":{},"capture":true}');
$response = curl_exec($ch);
curl_close($ch);
echo $response;Ruby
require 'net/http'
require 'uri'
uri = URI('https://api.ledgerline.dev/v2/charges')
req = Net::HTTP::Post.new(uri)
req['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = '{"amount":4800,"currency":"usd","customer":"string","description":"string","receipt_email":"string","metadata":{},"capture":true}'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(req)
end
puts res.bodyJava
import java.net.URI;
import java.net.http.*;
import java.net.http.HttpRequest.BodyPublishers;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ledgerline.dev/v2/charges"))
.header("Content-Type", "application/x-www-form-urlencoded")
.method("POST", BodyPublishers.ofString("{\"amount\":4800,\"currency\":\"usd\",\"customer\":\"string\",\"description\":\"string\",\"receipt_email\":\"string\",\"metadata\":{},\"capture\":true}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());Responses
200 Returns the object if the request succeeded.
{
"id": "ch_3MmlLrLkdIwHu7ix0snN0B15",
"object": "charge",
"amount": 4800,
"amount_refunded": 0,
"currency": "usd",
"customer": "cus_Qm8xT2vLp0aZ",
"description": "Canvas tote",
"captured": true,
"paid": true,
"status": "succeeded",
"created": 1791787234,
"livemode": false
}402 The request was valid but failed (for example, the card was declined).
Updated
Was this page helpful?