---
schema_version: "1"
id: 9742459e3d55aeb4d22158b5ce11b9549136a64f81fb5ccb5c004c4a6f32a911
title: Idempotency Guidelines
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_commercepayments_idempotency_guidelines.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_commercepayments_idempotency_guidelines.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7849c7c319f024e7dcd8b8de3a67ba290f2e9d5937d8a71b9377aa39556c63e5
description: An idempotent payment gateway recognizes duplicate requests, submitted in error or maliciously, and processes them without charging twice. When your gateway supports idempotency, check for duplicates in your adapter before you send a callout.
---
# Idempotency Guidelines

An idempotent payment gateway recognizes duplicate requests, submitted in error or maliciously, and processes them without charging twice. When your gateway supports idempotency, check for duplicates in your adapter before you send a callout.

<table class="editionTable" border="0" summary="Salesforce editions needed for the documented functionality" width="100%"><tbody class="tbody"><tr><td class="subHead">Available in: Salesforce Spring ’20</td></tr></tbody></table>

  

To access the commercepayments API, you need the PaymentPlatform org permission.

Your payment gateway adapter is linked to a PaymentGatewayProvider record. The Salesforce payments platform can detect when the same payment request is submitted more than once. For example, a user clicks Pay twice, or a client retries after a timeout. If your gateway can handle those retries without charging twice, set IdempotencySupported to Yes on the PaymentGatewayProvider record. For an example, see [Set Up a Synchronous Payment Gateway Adapter](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_commercepayments_sync_adapter_setup.htm "For payments transactions, you can configure Salesforce to interface with a synchronous payment gateway adapter.").

When the payments platform detects a duplicate and the gateway provider supports idempotency, it still calls your adapter’s processRequest method and sets the request’s duplicate property to true. Check that property before you send a callout to the payment processor. You can also read idempotencyKey and include it in the outbound request so the processor can reject a later retry. These properties are available on capture requests and on other request types, such as authorization and refund.

This example shows the check for a capture request.

global commercepayments.GatewayResponse processRequest(
        commercepayments.PaymentGatewayContext gatewayContext) {
    commercepayments.CaptureRequest request =
        (commercepayments.CaptureRequest) gatewayContext.getPaymentRequest();

    Boolean isDuplicate = request.duplicate;
    String idempotencyKey = request.idempotencyKey;

    if (isDuplicate) {
        // Salesforce detected a retry of this capture. Do not send a new
        // capture to the payment gateway.
    } else {
        // First request. Include idempotencyKey in the outbound call so
        // the processor can reject a later retry of the same capture.
    }
}