Skip to content

Capturing converts part or all of an authorization's reserved funds into an actual charge. You can capture less than the full authorized amount, and you can capture multiple times against the same authorization (e.g. as a multi-shipment order goes out in parts) as long as the total captured never exceeds what was authorized. See the official documentation for capturing a transaction.

Request

CaptureRequest needs only the amount you're capturing now, item-level detail is optional and mainly useful for partial captures where you want Ratepay's records to reflect exactly what shipped.

import com.ratepay.sdk.CaptureOutcome;
import com.ratepay.sdk.model.api.payment.CaptureRequest;
import com.ratepay.sdk.model.api.payment.Item;
import java.math.BigDecimal;
import java.util.List;

CaptureRequest request = new CaptureRequest(
    new BigDecimal("249.00"), // grossAmount, capturing the full authorized amount here
    List.of(
        new Item(
            new BigDecimal("249.00"), "Ergonomic Office Chair", BigDecimal.ONE, new BigDecimal("19"),
            "SKU-2050", null, null, null, null, null, null, null, null
        )
    ),
    null, // partnerInvoiceId
    null, // partnerOperationId
    null, // partnerShopId
    null, // partnerTransactionId
    null, // shopTransactionId
    null, // specialItems
    null  // vats
);

CaptureOutcome outcome = client.capture(ratepayTransactionId, request, null);

if (outcome.isAccepted()) {
    var accepted = (CaptureOutcome.Accepted) outcome;
    System.out.println("Captured " + accepted.getRatepayCaptureId());
} else {
    var declined = (CaptureOutcome.Declined) outcome;
    System.out.println("Capture declined: " + declined.getDecline().getCategory());
}

Outcome

KindMeaning
ACCEPTEDThe capture succeeded; ratepayCaptureId identifies it for later shipping-information calls or refunds.
DECLINEDThe capture was rejected most commonly because the requested amount exceeds what's left to capture on the authorization. Inspect Declined.decline.

Every outcome type also offers isAccepted() / isDeclined() helpers (and isOtpRequired() on AuthorizeOutcome), handy in Java before Java 21 pattern matching.

Exceptions

ExceptionHTTP Status Code
RatepayAuthException401/403
RatepayValidationException400
RatepayTransactionNotFoundException404
RatepayNetworkException5xx/transport

Next