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

Process a payment 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</td></tr></tbody></table>

  

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

1. Get the payment capture 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.CaptureRequest = (commercepayments.CaptureRequest)gatewayContext.getPaymentRequest()
2. Set the HTTP request object.
    
    HttpRequest req = new HttpRequest();
    req.setHeader('Content-Type', 'application/json');
3. Read the parameters from the [CaptureRequest](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_commercepayments_CaptureRequest.htm#apex_class_commerce_payments_CaptureRequest) 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 [CaptureResponse](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_commercepayments_CaptureResponse.htm#apex_class_commerce_payments_CaptureResponse) object.
    
    commercepayments.CaptureResponse captureResponse = new commercepayments.CaptureResponse();
    captureResponse.setGatewayResultCode(“”); captureResponse.setGatewayResultCodeDescription(“”); captureResponse.setGatewayReferenceNumber(“”);
    captureResponse.setSalesforceResultCodeInfo(getSalesforceResultCodeInfo(commercepayments.SalesforceResultCode.SUCCESS.name())); 
    captureResponse.setGatewayReferenceDetails(“”);
    captureResponse.setAmount(double.valueOf(100);
6. Return the captureResponse.