Capture a payment
Learn how to collect a pre-authorized payment with the Dojo Payments API.
A created pre-authorized payment isn't complete until it has been captured. When completing a payment, you can capture the amount in full, or in partial increments.
You can only capture a payment that hasn't yet been refunded or reversed.
Capture using the Dojo API
To capture a payment, use the endpoint:
POST /payment-intents/{paymentIntentId}/captures
In your request, include:
-
paymentIntentId: This identifies the payment intent to be captured. -
amount: This is the amount to capture.
For the full API specification, see the reference.
Request example
The next example shows the capture of 10.00 GBP.
- cURL
- PowerShell
- Python
- C#
- PHP
# The sandbox API key passed in 'authorization' is public.
# Don't submit any personally identifiable information in any requests made with this key.
# Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
# for secure testing.
curl -v --request POST \
--url https://api.dojo.tech/payment-intents/<paymentIntentId> \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <your_api_key>' \
--header 'Version: 2024-02-05' \
--data '{
"amount": 1000
}'
# The sandbox API key passed in '$publicSandboxKey' is public.
# Don't submit any personally identifiable information in any requests made with this key.
# Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
# for secure testing.
$publicSandboxKey = "sk_sandbox_c8oLGaI__msxsXbpBDpdtwJEz_eIhfQoKHmedqgZPCdBx59zpKZLSk8OPLT0cZolbeuYJSBvzDVVsYvtpo5RkQ"
# Replace <payment_intent_id> with ID of payment intent you want to capture.
Invoke-WebRequest `
-Uri 'https://api.dojo.tech/payment-intents/<paymentIntentId>/captures' `
-Method POST `
-Headers @{
"Version" = "2024-02-05"
"Authorization" = "Basic $publicSandboxKey"
} `
-ContentType 'application/json' `
-Body '{
"amount": 1000
}'
# The sandbox API key passed in 'authorization' is public.
# Don't submit any personally identifiable information in any requests made with this key.
# Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
# for secure testing.
import http.client
conn = http.client.HTTPSConnection("api.dojo.tech")
payload = "{\"amount\":1000}"
headers = {
'Content-Type': "application/json",
'Version': "2024-02-05",
'Authorization': "Basic <your_api_key>"
}
conn.request("POST", f"/payment-intents/{paymentIntentId}/captures", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
conn.close()
// The sandbox API key passed in 'ApiKeyClientAuthorization' is public.
// Don't submit any personally identifiable information in any requests made with this key.
// Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
// for secure testing.
var capturesClient = new Dojo.Net.CapturesClient(new HttpClient(), new ApiKeyClientAuthorization("<your_api_key>"));
var result = await capturesClient.CreateAsync("<paymentIntentId>", new CreateCaptureRequest
{
Amount = 1000
});
<?php
// The sandbox API key used in this example is public.
// Don't submit any personally identifiable information in any requests made with this key.
// Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
// for secure testing.
namespace Test;
require_once "vendor/autoload.php";
use Dojo_PHP\ApiFactory;
use Dojo_PHP\Model\CreateCaptureRequest;
$apiKey = "<your_api_key>";
$apiPaymentIntent = ApiFactory::createCapturesApi($apiKey);
$captureRequest = new CreateCaptureRequest(["amount" => 1000]);
$apiPaymentIntent->capturesCreate(\Dojo_PHP\API_VERSION, "<paymentIntentId>", $captureRequest);
Response example
If your request is successful, the response will return information about the capture.
{
"message": "collect payment for the order 3443",
"captureId": "cp_itIiJMEAvES3ynYF_Yhs2g"
}