Newer Version Available

This content describes an older version of this product. View Latest

AuthorizationResponse Class

Response sent by the payment gateway adapter for an authorization service.

Namespace

CommercePayments

Usage

The constructor of this class takes no arguments. For example:

CommercePayments.AuthorizationResponse authr = new CommercePayments.AuthorizationResponse();

Contains information about the payment gateway’s response following an authorization transaction. The gateway adapter uses the payment gateway’s response to populate the AuthorizationResponse fields. The payments platform uses the information from this class to construct the authorization gateway response shown to the user.

Example

1private commercepayments.GatewayResponse createAuthResponse(HttpResponse response, Double amount) {
2        Map<String, Object> mapOfResponseValues = (Map
3                            <String, Object>) JSON.deserializeUntyped(response.getBody());
4
5        commercepayments.AuthorizationResponse authResponse = new commercepayments.AuthorizationResponse();
6
7        String resultCode = (String)mapOfResponseValues.get('resultCode');
8
9        if(resultCode != null){
10            system.debug('Response - success');
11            if(resultCode.equals('Authorised')){
12                system.debug('status - authorised');
13                authResponse.setGatewayAuthCode((String)mapOfResponseValues.get('authCode'));
14                authResponse.setSalesforceResultCodeInfo(new commercepayments.SalesforceResultCodeInfo(commercepayments.SalesforceResultCode.Success));
15            } else {
16                //Sample returns 200 with refused status in some cases
17                system.debug('status - refused');
18                authResponse.setGatewayResultCodeDescription((String)mapOfResponseValues.get('refusalReason'));
19                authResponse.setSalesforceResultCodeInfo(new commercepayments.SalesforceResultCodeInfo(commercepayments.SalesforceResultCode.Decline));
20            }
21            authResponse.setGatewayReferenceNumber((String)mapOfResponseValues.get('pspReference'));
22            authResponse.setAmount(amount);
23            authResponse.setGatewayDate(system.now());
24            return authResponse;
25        } else {
26            system.debug('Response - failed');
27            system.debug('Validation error');
28            String statusCode = (String)mapOfResponseValues.get('errorType');
29            String message = (String)mapOfResponseValues.get('message');
30            commercepayments.GatewayErrorResponse error = new commercepayments.GatewayErrorResponse(statusCode, message);
31            return error;
32        }
33    }

AuthorizationResponse Methods

The following are methods for AuthorizationResponse.

setAmount(amount)

Sets the amount of the authorization. Must be a non-zero value.

Signature

global void setAmount(Double amount)

Parameters

amount
Type: Double

Return Value

Type: void

setAuthorizationExpirationDate(authExpDate)

Sets the expiration date of the authorization request.

Signature

global void setAuthorizationExpirationDate(Datetime authExpDate)

Parameters

authExpDate
Type: Datetime

Return Value

Type: void

setGatewayAuthCode(gatewayAuthCode)

Sets the authorization code that the gateway returned. Maximum length of 64 characters.

Signature

global void setGatewayAuthCode(String gatewayAuthCode)

Parameters

gatewayAuthCode
Type: String
The authorization code returned by the gateway.

Return Value

Type: void

setGatewayAvsCode(gatewayAvsCode)

Sets the AVS (address verification system) result code information that the gateway returned. Maximum length of 64 characters.

Signature

global void setGatewayAvsCode(String gatewayAvsCode)

Parameters

gatewayAvsCode
Type: String
Used to verify the address mapped to a payment method when the payments platform requests tokenization from the payment gateway.

Return Value

Type: void

setGatewayDate(gatewayDate)

Sets the date that the authorization occurred. Some gateways don’t send this value.

Signature

global void setGatewayDate(Datetime gatewayDate)

Parameters

gatewayDate
Type: Datetime

Return Value

Type: void

setGatewayMessage(gatewayMessage)

Sets error messages that the gateway returned for the authorization request. Maximum length of 255 characters.

Signature

global void setGatewayMessage(String gatewayMessage)

Parameters

gatewayMessage
Type: String

Return Value

Type: void

setGatewayReferenceDetails(gatewayReferenceDetails)

Stores data that you can use for subsequent authorizations. You can use any data that isn’t normalized in financial entities. This field has a maximum length of 1000 characters and can store data as JSON or XML.

Signature

global void setGatewayReferenceDetails(String gatewayReferenceDetails)

Parameters

gatewayReferenceDetails
Type: String

Return Value

Type: void

setGatewayReferenceNumber(gatewayReferenceNumber)

Sets the unique gateway reference number for the transaction that the gateway returned. Maximum length of 255 characters.

Signature

global void setGatewayReferenceNumber(String gatewayReferenceNumber)

Parameters

gatewayReferenceNumber
Type: String
Unique authorization ID created by the payment gateway.

Return Value

Type: void

setGatewayResultCode(gatewayResultCode)

Sets a gateway-specific result code. The code can be mapped to a Salesforce-specific result code. Maximum length of 64 characters.

Signature

global void setGatewayResultCode(String gatewayResultCode)

Parameters

gatewayResultCode
Type: String
Gateway-specific result code. Must be used to map a Salesforce-specific result code.

Return Value

Type: void

setGatewayResultCodeDescription(gatewayResultCodeDescription)

Sets a description of the gateway-specific result code that a payment gateway returned. Maximum length of 1000 characters.

Signature

global void setGatewayResultCodeDescription(String gatewayResultCodeDescription)

Parameters

gatewayResultCodeDescription
Type: String
Description of the gateway’s result code. Use this field to learn more about why the gateway returned a certain result code.

Return Value

Type: void

setPaymentMethodTokenizationResponse(paymentMethodTokenizationResponse)

Sets information from the gateway about the tokenized payment method.

Signature

global void setPaymentMethodTokenizationResponse(commercepayments.PaymentMethodTokenizationResponse paymentMethodTokenizationResponse)

Parameters

paymentMethodTokenizationResponse
PaymentMethodTokenizationResponse
Gateway response sent by payment gateway adapters for the payment method tokenization request.

Return Value

Type: void

setSalesforceResultCodeInfo(salesforceResultCodeInfo)

Sets the Salesforce-specific result code information. Payment gateways have many response codes for payment calls. Salesforce uses the result code information to map payment gateway codes to a predefined set of standard Salesforce result codes.

Signature

global void setSalesforceResultCodeInfo(commercepayments.SalesforceResultCodeInfo salesforceResultCodeInfo)

Parameters

salesforceResultCodeInfo
Type: SalesforceResultCodeInfo
Description of the Salesforce result code value.

Return Value

Type: void