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.
GatewayErrorResponse Class
Use to respond with an error indication following errors from the
PaymentGateway adapter, such as request-forbidden
responses, custom validation errors, or expired API tokens.
Namespace
Usage
Use GatewayErrorResponse to
create an object that stores information about error responses sent by the payment gateway
adapter.
Example
If GatewayResponse
receives an exception rather than a valid request, it calls GatewayErrorResponse to create an error object with information about the
exception.
1global commercepayments.GatewayResponse processRequest(commercepayments.paymentGatewayContext gatewayContext) {
2 commercepayments.RequestType requestType = gatewayContext.getPaymentRequestType();
3 commercepayments.GatewayResponse response;
4 try {
5 if (requestType == commercepayments.RequestType.Authorize) {
6 response = createAuthResponse((commercepayments.AuthorizationRequest)gatewayContext.getPaymentRequest());
7 } else if (requestType == commercepayments.RequestType.Capture) {
8 response = createCaptureResponse((commercepayments.CaptureRequest)gatewayContext.getPaymentRequest()) ;
9 } else if (requestType == commercepayments.RequestType.ReferencedRefund) {
10 response = createRefundResponse((commercepayments.ReferencedRefundRequest)gatewayContext.getPaymentRequest());
11 }
12 return response;
13 } catch(SalesforceValidationException e) {
14 commercepayments.GatewayErrorResponse error = new commercepayments.GatewayErrorResponse('400', e.getMessage());
15 return error;
16 }
17 }GatewayErrorResponse Constructors
The following are constructors for GatewayErrorResponse.
GatewayErrorResponse(errorCode, errorMessage)
Signature
global GatewayErrorResponse(String errorCode, String errorMessage)
Parameters
-
errorCode: Type: String Should match with the HTTP status code to be returned to the user. Here are a few examples.
- If the status code is for a bad request, the errorCode should be 400.
- If the status code is for a forbidden request, errorCode should be 403.
- If errorCode isn’t a valid HTTP status code, a 500 internal server error is returned.
- errorMessage: Type: String The message response to users following an error.