Create a refund
POST
/v2/refunds Refund a charge that has previously been created but not yet refunded.
Parameters
chargestringrequiredThe identifier of the charge to refund.
amountintegerA positive integer representing how much to refund. Defaults to the entire charge.
reasonstringThe reason for the refund.
{
"charge": "string",
"amount": 0,
"reason": "duplicate"
}Code samples
cURL
curl -X POST "https://api.ledgerline.dev/v2/refunds" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d '{"charge":"string","amount":0,"reason":"duplicate"}'Ruby
require 'net/http'
require 'uri'
uri = URI('https://api.ledgerline.dev/v2/refunds')
req = Net::HTTP::Post.new(uri)
req['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = '{"charge":"string","amount":0,"reason":"duplicate"}'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(req)
end
puts res.bodyPython
import requests
res = requests.request(
"POST",
"https://api.ledgerline.dev/v2/refunds",
headers={
"Content-Type": "application/x-www-form-urlencoded",
},
json={"charge": "string", "amount": 0, "reason": "duplicate"},
)
data = res.json()TypeScript
const res = await fetch('https://api.ledgerline.dev/v2/refunds', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({"charge":"string","amount":0,"reason":"duplicate"}),
});
const data = await res.json();Go
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
req, _ := http.NewRequest("POST", "https://api.ledgerline.dev/v2/refunds", strings.NewReader(`{"charge":"string","amount":0,"reason":"duplicate"}`))
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))
}Java
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/refunds"))
.header("Content-Type", "application/x-www-form-urlencoded")
.method("POST", BodyPublishers.ofString("{\"charge\":\"string\",\"amount\":0,\"reason\":\"duplicate\"}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.ledgerline.dev/v2/refunds');
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, '{"charge":"string","amount":0,"reason":"duplicate"}');
$response = curl_exec($ch);
curl_close($ch);
echo $response;C#
using System.Net.Http;
using System.Text;
var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.ledgerline.dev/v2/refunds");
request.Content = new StringContent("{\"charge\":\"string\",\"amount\":0,\"reason\":\"duplicate\"}", Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());Response
{
"id": "re_1Nispe2eZvKYlo2C",
"object": "refund",
"amount": 1000,
"charge": "ch_3MmlLrLkdIwHu7ix0snN0B15",
"status": "succeeded"
}Was this page helpful?