---
schema_version: "1"
id: 555c451acf6e3950ef400dcf9d41e820cd1d560d2505d739d59c8177b4767d6f
title: AuthorizationRequest Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_commercepayments_AuthorizationRequest.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: d615ea5b1eb11bbe659252ab3260667a0767088b17ad4be2ed18f12ca7d4d78e
description: Sends information about an authorization request to a gateway adapter during a service call. This class extends the BaseRequest class and inherits all its methods. Constructor for building the amount in an authorization request. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.The customer account where the authorization is performed.The total amount of the authorization. Can be positive or negative.Comments about the authorization. Users can enter comments to provide additional information.The ISO currency code for the authorization request.The payment method used to process the authorization in the authorization request.Payment method data used in the authorize payment request. Maintains the integrity of lists of type AuthorizationRequest by determining the equality of external objects in a list. This method is dynamic and based on the equals method in Java.Maintains the integrity of lists of type AuthorizationRequest by determining the uniqueness of the external object in a list.Converts a date to a string.
---
# AuthorizationRequest Class

Sends information about an authorization request to a gateway adapter during a service call. This class extends the BaseRequest class and inherits all its methods.

## Namespace

[CommercePayments](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_commercepayments.htm "Use the CommercePayments namespace to provide a safe and customizable platform for managing customer payments and refunds.")

## Usage

This class contains information about a transaction authorization request. The gateway adapter reads fields from this class while constructing an authorization JSON request to send to the payment gateway. An object of this class is available by calling getPaymentRequest() in the [PaymentGatewayContext Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm#apex_class_commerce_payments_PaymentGatewayContext "Wraps the information related to a payment request.").

## Example

Creating a buildAuthRequest class to store information about the authorization request.

private String buildAuthRequest(commercepayments.AuthorizationRequest authRequest) {
        // Multiply amount by 100.0 to convert to cents
        String requestBody = createRequestBody(String.ValueOf((authRequest.amount\*100.0).intValue()), authRequest);
        return requestBody;

        private String createRequestBody(String amount, commercepayments.AuthorizationRequest authRequest) {
        JSONGenerator jsonGeneratorInstance = JSON.createGenerator(true);
        String currencyIso = authRequest.currencyIsoCode;
        commercepayments.AuthApiPaymentMethodRequest paymentMethod = authRequest.paymentMethod;
        commercepayments.GatewayErrorResponse error;
        // Write data to the JSON string.
        jsonGeneratorInstance.writeStartObject();
        jsonGeneratorInstance.writeStringField('merchantAccount', '{!$Credential.Username}');
        jsonGeneratorInstance.writeStringField('reference', authRequest.comments == null ? 'randomstring' : authRequest.comments);

        if(currencyIso == null) {
            currencyIso = UserInfo.getDefaultCurrency();
        }

        jsonGeneratorInstance.writeFieldName('amount');
        jsonGeneratorInstance.writeStartObject();
        jsonGeneratorInstance.writeStringField('value', amount);
        jsonGeneratorInstance.writeStringField('currency', currencyIso);
        jsonGeneratorInstance.writeEndObject();

        commercepayments.CardPaymentMethodRequest cardPaymentMethod;
        if(paymentMethod != null) {
            cardPaymentMethod = paymentMethod.cardPaymentMethod;
            if (cardPaymentMethod != null) {
                if (cardPaymentMethod.CardCategory != null) {
                    if (commercepayments.CardCategory.CreditCard == cardPaymentMethod.CardCategory) {
                        jsonGeneratorInstance.writeFieldName('card');
                        jsonGeneratorInstance.writeStartObject();
                        if (cardPaymentMethod.cvv != null)
                            jsonGeneratorInstance.writeStringField('cvc', String.ValueOf(cardPaymentMethod.cvv));
                        if (cardPaymentMethod.cardholdername != null)
                            jsonGeneratorInstance.writeStringField('holderName', cardPaymentMethod.cardholdername);
                        if (cardPaymentMethod.cardnumber != null)
                            jsonGeneratorInstance.writeStringField('number', cardPaymentMethod.cardnumber);
                        if (cardPaymentMethod.expiryMonth != null && cardPaymentMethod.expiryYear != null ) {
                            String expMonth = ((String.ValueOf(cardPaymentMethod.expiryMonth)).length() == 1 ? '0' : '') + String.ValueOf(cardPaymentMethod.expiryMonth);
                            jsonGeneratorInstance.writeStringField('expiryMonth', expMonth);
                            jsonGeneratorInstance.writeStringField('expiryYear', String.ValueOf(cardPaymentMethod.expiryYear));
                        }
                        jsonGeneratorInstance.writeEndObject();
                    } else {
                    //Support for other card type
                    }
                } else {
                    throw new SampleValidationException('Required Field Missing : CardCategory');
                }
            } else {
                throw new SampleValidationException('Required Field Missing : CardPaymentMethod');
            }
        } else {
            throw new SampleValidationException('Required Field Missing : PaymentMethod');
        }
        jsonGeneratorInstance.writeEndObject();
        return jsonGeneratorInstance.getAsString();
    }

- **[AuthorizationRequest Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_constructors)**
- **[AuthorizationRequest Properties](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_properties)**
- **[AuthorizationRequest Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_methods)**

## AuthorizationRequest Constructors

The following are constructors for AuthorizationRequest.

- **[AuthorizationRequest(amount)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_ctor)**  
    Constructor for building the amount in an authorization request. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

### AuthorizationRequest(amount)

Constructor for building the amount in an authorization request. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

#### Signature

global AuthorizationRequest(Double amount)

#### Parameters

- **amount**:
    
    Type: [Double](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_methods_system_double "Contains methods for the Double primitive data type.")
    
    The amount of the authorization.

## AuthorizationRequest Properties

The following are properties for AuthorizationRequest.

- **[accountId](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_accountId)**  
    The customer account where the authorization is performed.
- **[amount](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_amount)**  
    The total amount of the authorization. Can be positive or negative.
- **[comments](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_comments)**  
    Comments about the authorization. Users can enter comments to provide additional information.
- **[currencyIsoCode](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_currencyIsoCode)**  
    The ISO currency code for the authorization request.
- **[paymentMethod](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_paymentMethod)**  
    The payment method used to process the authorization in the authorization request.
- **[paymentMethodData](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_paymentMethodData)**  
    Payment method data used in the authorize payment request.

### accountId

The customer account where the authorization is performed.

#### Signature

global String accountId {get; set;}

#### Property Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

### amount

The total amount of the authorization. Can be positive or negative.

#### Signature

global Double amount {get; set;}

#### Property Value

Type: [Double](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_methods_system_double "Contains methods for the Double primitive data type.")

### comments

Comments about the authorization. Users can enter comments to provide additional information.

#### Signature

global String comments {get; set;}

#### Property Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

### currencyIsoCode

The ISO currency code for the authorization request.

#### Signature

global String currencyIsoCode {get; set;}

#### Property Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

### paymentMethod

The payment method used to process the authorization in the authorization request.

#### Signature

global AuthApiPaymentMethodRequest paymentMethod {get; set;}

#### Property Value

Type: [AuthApiPaymentMethodRequest](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthApiPaymentMethodRequest.htm#apex_class_commercepayments_AuthApiPaymentMethodRequest "Sends information about a payment method to a gateway adapter during an authorization service call.")

### paymentMethodData

Payment method data used in the authorize payment request.

This field is populated when AuthorizationInput specifies a saved payment method. Accessible using paymentMethodData on AuthorizationRequest. The map contains these fields from SavedPaymentMethod: GatewayToken, Type, GatewayReference, and StandardEntryCode for direct gateway interaction without querying the database. This field is supported only for saved payment methods of type card.

#### Signature

public Map<String,String> paymentMethodData {get; set;}

#### Property Value

Type: Map<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type."),[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>

## AuthorizationRequest Methods

The following are methods for AuthorizationRequest.

- **[equals(obj)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_equals)**  
    Maintains the integrity of lists of type AuthorizationRequest by determining the equality of external objects in a list. This method is dynamic and based on the equals method in Java.
- **[hashCode()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_hashCode)**  
    Maintains the integrity of lists of type AuthorizationRequest by determining the uniqueness of the external object in a list.
- **[toString()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_AuthorizationRequest.htm#apex_commercepayments_AuthorizationRequest_toString)**  
    Converts a date to a string.

### equals(obj)

Maintains the integrity of lists of type AuthorizationRequest by determining the equality of external objects in a list. This method is dynamic and based on the equals method in Java.

#### Signature

global Boolean equals(Object obj)

#### Parameters

- **obj**:
    
    Type:
    
    Object External object whose key is to be validated.

#### Return Value

Type: [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")

### hashCode()

Maintains the integrity of lists of type AuthorizationRequest by determining the uniqueness of the external object in a list.

#### Signature

global Integer hashCode()

#### Return Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

### toString()

Converts a date to a string.

#### Signature

global String toString()

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")