Collections Charge card
Charge card
Charges a saved card against an open payment intent, server to server. Use it for repeat charges after the payer saved a card. The card must be saved under the intent's `client_customer_id`.
Api-Key
Charges a saved card against an open payment intent, server to server. Use it for repeat charges after the payer saved a card. The card must be saved under the intent's client_customer_id.
You can charge a saved card at most 5 times in 24 hours, and each charge can be at most 3 times the card's first payment. A declined charge returns HTTP 400 with a sentence such as The card has insufficient funds: payment declined.
Headers
NameDescription
Idempotency-KeyRequired for POST requests. Reuse it only to retry the same request. Gravv stores a 400 with the key for 24 hours, so use a new key after you fix a rejected body.
X-Device-IdOptional ID of the payer's device. On a payment intent, Gravv stores it and reuses it for later saved-card charges.
Body parameters
NameDescription
payment_intent_idThe
intent_id, with its pi_ prefixcard_tokenA card token saved under the intent's
client_customer_idfirst_namelast_nameemailphone_numberE.164 format
date_of_birthYYYY-MM-DD, MM/DD/YYYY or DD/MM/YYYYbilling_address1billing_citybilling_statebilling_zipChecked against the billing country
billing_countryISO 3166-1 alpha-2
Response
Returns 200 OK. The charge went through, or 3D Secure is needed. For requires_action, send the payer to next_action_url.
NameDescription
dataShow 6 child attributesobject
payment_intent_idstatusPossible values:
succeeded, requires_actiontransaction_idThe collection's
transaction_id. Left out when 3D Secure is needed.requires_actionnext_action_typePossible values:
redirect_to_urlnext_action_urlThe 3D Secure page to send the payer to
errorErrors
| Status | Meaning |
|---|---|
| 200 | The charge went through, or 3D Secure is needed. For requires_action, send the payer to next_action_url. |
| 400 | The charge failed or was declined. Read the decline code from GET /v1/collections/{id} or the failed webhook. |
Was this page helpful? Yes No
Previous
Next
Request
cURLJavaScriptPythonGoRubyPHPJavaC#cURL
curl --request POST \
--url 'https://api.gravv.xyz/v1/collections/cards/payment-intents/charge' \
--header 'Api-Key: <api-key>' \
--header 'Idempotency-Key: order_789_attempt_1' \
--header 'X-Device-Id: device-7f3a9c' \
--header 'Content-Type: application/json' \
--data '{
"payment_intent_id": "pi_429f578b-675a-4b68-abe3-856cd976257f",
"card_token": "tokn_80aebb6ea2594a74bc",
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@example.com",
"billing_address1": "123 Market St",
"billing_city": "San Francisco",
"billing_state": "CA",
"billing_zip": "94105",
"billing_country": "US"
}'
const response = await fetch('https://api.gravv.xyz/v1/collections/cards/payment-intents/charge', {
method: 'POST',
headers: {
'Api-Key': '<api-key>',
'Idempotency-Key': 'order_789_attempt_1',
'X-Device-Id': 'device-7f3a9c',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"payment_intent_id": "pi_429f578b-675a-4b68-abe3-856cd976257f",
"card_token": "tokn_80aebb6ea2594a74bc",
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@example.com",
"billing_address1": "123 Market St",
"billing_city": "San Francisco",
"billing_state": "CA",
"billing_zip": "94105",
"billing_country": "US"
}),
});
const data = await response.json();
console.log(response.status, data);
import requests
url = "https://api.gravv.xyz/v1/collections/cards/payment-intents/charge"
headers = {
"Api-Key": "<api-key>",
"Idempotency-Key": "order_789_attempt_1",
"X-Device-Id": "device-7f3a9c",
}
payload = {
"payment_intent_id": "pi_429f578b-675a-4b68-abe3-856cd976257f",
"card_token": "tokn_80aebb6ea2594a74bc",
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@example.com",
"billing_address1": "123 Market St",
"billing_city": "San Francisco",
"billing_state": "CA",
"billing_zip": "94105",
"billing_country": "US",
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(response.json())
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{
"payment_intent_id": "pi_429f578b-675a-4b68-abe3-856cd976257f",
"card_token": "tokn_80aebb6ea2594a74bc",
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@example.com",
"billing_address1": "123 Market St",
"billing_city": "San Francisco",
"billing_state": "CA",
"billing_zip": "94105",
"billing_country": "US"
}`)
req, err := http.NewRequest("POST", "https://api.gravv.xyz/v1/collections/cards/payment-intents/charge", bytes.NewReader(payload))
if err != nil {
panic(err)
}
req.Header.Set("Api-Key", "<api-key>")
req.Header.Set("Idempotency-Key", "order_789_attempt_1")
req.Header.Set("X-Device-Id", "device-7f3a9c")
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(res.Status)
fmt.Println(string(body))
}
require "json"
require "net/http"
require "uri"
uri = URI("https://api.gravv.xyz/v1/collections/cards/payment-intents/charge")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
request = Net::HTTP::Post.new(uri)
request["Api-Key"] = "<api-key>"
request["Idempotency-Key"] = "order_789_attempt_1"
request["X-Device-Id"] = "device-7f3a9c"
request["Content-Type"] = "application/json"
request.body = JSON.generate({
"payment_intent_id" => "pi_429f578b-675a-4b68-abe3-856cd976257f",
"card_token" => "tokn_80aebb6ea2594a74bc",
"first_name" => "Jane",
"last_name" => "Doe",
"email" => "jane@example.com",
"billing_address1" => "123 Market St",
"billing_city" => "San Francisco",
"billing_state" => "CA",
"billing_zip" => "94105",
"billing_country" => "US",
})
response = http.request(request)
puts response.code
puts response.body
<?php
$payload = [
'payment_intent_id' => 'pi_429f578b-675a-4b68-abe3-856cd976257f',
'card_token' => 'tokn_80aebb6ea2594a74bc',
'first_name' => 'Jane',
'last_name' => 'Doe',
'email' => 'jane@example.com',
'billing_address1' => '123 Market St',
'billing_city' => 'San Francisco',
'billing_state' => 'CA',
'billing_zip' => '94105',
'billing_country' => 'US',
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.gravv.xyz/v1/collections/cards/payment-intents/charge',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Api-Key: <api-key>',
'Idempotency-Key: order_789_attempt_1',
'X-Device-Id: device-7f3a9c',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
echo $status, PHP_EOL, $response, PHP_EOL;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"payment_intent_id": "pi_429f578b-675a-4b68-abe3-856cd976257f",
"card_token": "tokn_80aebb6ea2594a74bc",
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@example.com",
"billing_address1": "123 Market St",
"billing_city": "San Francisco",
"billing_state": "CA",
"billing_zip": "94105",
"billing_country": "US"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.gravv.xyz/v1/collections/cards/payment-intents/charge"))
.header("Api-Key", "<api-key>")
.header("Idempotency-Key", "order_789_attempt_1")
.header("X-Device-Id", "device-7f3a9c")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}
using System.Net.Http;
using System.Text;
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://api.gravv.xyz/v1/collections/cards/payment-intents/charge");
request.Headers.TryAddWithoutValidation("Api-Key", "<api-key>");
request.Headers.TryAddWithoutValidation("Idempotency-Key", "order_789_attempt_1");
request.Headers.TryAddWithoutValidation("X-Device-Id", "device-7f3a9c");
request.Content = new StringContent(
"""
{
"payment_intent_id": "pi_429f578b-675a-4b68-abe3-856cd976257f",
"card_token": "tokn_80aebb6ea2594a74bc",
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@example.com",
"billing_address1": "123 Market St",
"billing_city": "San Francisco",
"billing_state": "CA",
"billing_zip": "94105",
"billing_country": "US"
}
""",
Encoding.UTF8,
"application/json");
using var response = await client.SendAsync(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(await response.Content.ReadAsStringAsync());
Responseapplication/json
200400OK
{
"data": {
"transaction_id": "90950347-d40b-4ab9-aa77-f1882750477c",
"payment_intent_id": "pi_429f578b-675a-4b68-abe3-856cd976257f",
"status": "succeeded"
},
"error": null
}
{
"data": null,
"error": "The card has insufficient funds: payment declined"
}