GatewayResponse Interface

Generic payment gateway response interface. This class extends the CaptureResponse, AbstractTransactionResponse, and AbstractResponse classes and inherits all their properties. It has no unique methods or parameters.

Namespace

CommercePayments

GatewayResponse Example Implementation

This is an example implementation of the commercepayments.GatewayResponse interface.

1/**
2     * Abstract function to build gateway response for a Transaction
3     * The input is the response from gateway
4     * It creates and returns GatewayResponse from the HttpResponse
5     */
6    public abstract commercepayments.GatewayResponse buildResponse(HttpResponse response);
7
8    /**
9     * Function to process transaction requests
10     * Steps involved are:
11     * 1. Build HttpRequest with the input Request from gateway context
12     * 2. Send request and get the response from gateway
13     * 3. Parse the response from gateway and return GatewayResponse
14     */
15    public commercepayments.GatewayResponse execute(){
16                HttpRequest req;
17        try{
18            //Building a new request
19            req = buildRequest();
20        } catch(PayeezeValidationException e) {
21            return getValidationExceptionError(e);
22        }
23        commercepayments.PaymentsHttp http = new commercepayments.PaymentsHttp();
24        HttpResponse res = null;
25        try{
26            //Sending the request
27            res = http.send(req);
28        } catch(CalloutException ce) {
29            return getCalloutExceptionError(ce);
30        }
31        try{
32            //Parsing the response from gateway
33            return buildResponse(res);
34        } catch(Exception e) {
35            return getParseExceptionError(e);
36        }
37    }

For additional context, review the complete Sample Gateway Adapter in the CommercePayments Gateway Reference Implementation.