---
schema_version: "1"
id: c32ef34bc32c524290ff61c618c95088673631bec28a8aa5e1ba4f63b794eaff
title: Process Refund
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_commercepayments_process_refund.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_commercepayments_process_refund.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: c7e284363814657e7c59c4b125fdad7ced0e321f8f9baced048b76c423937f3c
description: Process a refund in the payment gateway.
---
# Process Refund

Process a refund in the payment gateway.

<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 and later</td></tr><tr><td class="subHead">Available in: API 48.0 and later</td></tr></tbody></table>

  

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

1. Get the referenced refund request object from the [PaymentGatewayContext Class](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm#apex_class_commerce_payments_PaymentGatewayContext).
    
    commercepayments.ReferencedRefundRequest = (commercepayments.ReferencedRefundRequest)gatewayContext.getPaymentRequest();
2. Set the HTTP request object.
    
    HttpRequest req = new HttpRequest();
    req.setHeader('Content-Type', 'application/json');
3. Read the parameters from the [ReferencedRefundRequest](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_commercepayments_ReferencedRefundRequest.htm#apex_class_commerce_payments_ReferencedRefundRequest) object and prepare the HTTP request body.
4. Make the HTTP call to the gateway using the[PaymentsHttp Class](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_commercepayments_PaymentsHttp.htm#apex_class_commerce_payments_PaymentsHttp).
    
    commercepayments.PaymentsHttp http = new commercepayments.PaymentsHttp();
    HttpResponse res = http.send(req);
5. Parse the httpResponse and prepare the [ReferencedRefundResponse](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_commercepayments_ReferencedRefundResponse.htm#apex_class_commerce_payments_ReferencedRefundResponse) object.
    
    commercepayments.ReferencedRefundResponse referencedRefundResponse = new commercepayments.ReferencedRefundResponse();
    referencedRefundResponse.setGatewayResultCode(“”);
    referencedRefundResponse.setGatewayResultCodeDescription(“”);
    referencedRefundResponse.setGatewayReferenceNumber(“”);
    referencedRefundResponse.setSalesforceResultCodeInfo(getSalesforceResultCodeInfo(commercepayments.SalesforceResultCode.SUCCESS.name())); 
    referencedRefundResponse.setGatewayReferenceDetails(“”);
    referencedRefundResponse.setAmount(double.valueOf(100);
6. Return the referencedRefundResponse.