Process Payments

Process a payment in the payment gateway.
Available in: Salesforce Spring ’20

To access commercepayments API, you need the PaymentPlatform org permission.
  1. Get the payment capture request object from the PaymentGatewayContext Class.
    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 object and prepare the HTTP request body.
  4. Make the HTTP call to the gateway using the PaymentsHttp Class.
    commercepayments.PaymentsHttp http = new commercepayments.PaymentsHttp();
    HttpResponse res = http.send(req);
  5. Parse the httpResponse and prepare the 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.