Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Process Refund

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

To access the commercepayments API, you need the PaymentPlatform org permission.
  1. Get the referenced refund request object from the PaymentGatewayContext Class.
    1commercepayments.ReferencedRefundRequest = (commercepayments.ReferencedRefundRequest)gatewayContext.getPaymentRequest();
  2. Set the HTTP request object.
    1HttpRequest req = new HttpRequest();
    2req.setHeader('Content-Type', 'application/json');
  3. Read the parameters from the ReferencedRefundRequest object and prepare the HTTP request body.
  4. Make the HTTP call to the gateway using thePaymentsHttp Class.
    1commercepayments.PaymentsHttp http = new commercepayments.PaymentsHttp();
    2HttpResponse res = http.send(req);
  5. Parse the httpResponse and prepare the ReferencedRefundResponse object.
    1commercepayments.ReferencedRefundResponse referencedRefundResponse = new commercepayments.ReferencedRefundResponse();
    2referencedRefundResponse.setGatewayResultCode(“”);
    3referencedRefundResponse.setGatewayResultCodeDescription(“”);
    4referencedRefundResponse.setGatewayReferenceNumber(“”);
    5referencedRefundResponse.setSalesforceResultCodeInfo(getSalesforceResultCodeInfo(commercepayments.SalesforceResultCode.SUCCESS.name())); 
    6referencedRefundResponse.setGatewayReferenceDetails(“”);
    7referencedRefundResponse.setAmount(double.valueOf(100);
  6. Return the referencedRefundResponse.