---
schema_version: "1"
id: ffc931fab70ba372a18d3cac004c2245beb326f4dffcdf75c31d841325a31fc7
title: TokenizeNotification Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_commercepayments_TokenizeNotification.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6058e77fc2d916a7a621836ac5fc5439aee38601c9fef06acaa040ce467703dc
description: When a payment gateway sends a notification for a payment method tokenization, the payment gateway adapter creates the TokenizeNotification object to store information about notification.Sets the amount.Sets the AVS (address verification system) result code information that the gateway returned. Maximum length of 64 characters.Sets the date that the sale occurred. Some gateways don’t send this value.Sets error messages that the gateway returned for the sale request. Maximum length of 255 characters.Sets additional data that you can use for payment tokenization. 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.Sets the unique gateway reference number for the transaction that the gateway returned. Maximum length of 255 characters.Sets a gateway-specific result code. The code may be mapped to a Salesforce-specific result code. Maximum length of 64 characters.Sets a description of the gateway-specific result code that a payment gateway returned. Maximum length of 1000 characters.Sets the gateway token that the gateway returned.Sets an unencrypted unique token ID generated by the payment gateway to represent the saved payment method. Set the value of the gatewayTokenEncrypted field on a SavedPaymentMethod object.Sets the ID of a notification sent by the payment gateway.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.Sets the notification status value on the notification object.
---
# TokenizeNotification Class

When a payment gateway sends a notification for a payment method tokenization, the payment gateway adapter creates the TokenizeNotification object to store information about notification.

## 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

TokenizeNotification is used in asynchronous payment gateway adapters. Specify the CommercePayments namespace when creating an instance of this class. The constructor of this class takes no arguments. For example: commercePayments.TokenizeNotification Notification = new commercepayments.TokenizeNotification();

## Example

global commercepayments.GatewayNotificationResponse processNotification(commercepayments.PaymentGatewayNotificationContext gatewayNotificationContext) {
    commercepayments.PaymentGatewayNotificationRequest gatewayNotificationRequest = gatewayNotificationContext.getPaymentGatewayNotificationRequest();
    Blob request = gatewayNotificationRequest.getRequestBody();
    AdyenNotificationRequest notificationRequest = AdyenNotificationRequest.parse(request.toString().replace('currency', 'currencyCode'));
    List < AdyenNotificationRequest.NotificationItems > notificationItems = notificationRequest.notificationItems;
    AdyenNotificationRequest.NotificationRequestItem notificationRequestItem = notificationItems\[0\].NotificationRequestItem;

    Boolean success = Boolean.valueOf(notificationRequestItem.success);
    String pspReference = notificationRequestItem.pspReference;
    String eventCode = notificationRequestItem.eventCode;
    Double amount = notificationRequestItem.amount.value;
    String reason = notificationRequestItem.reason;
    Datetime eventDate = notificationRequestItem.eventDate;

    commercepayments.NotificationStatus notificationStatus = null;
    if (success) {
        notificationStatus = commercepayments.NotificationStatus.Success;
    } else {
        notificationStatus = commercepayments.NotificationStatus.Failed;
    }

    commercepayments.BaseNotification notification = null;
    if ('RECURRING\_CONTRACT'.equals(eventCode)) {
        // NOTE: if you are consuming RECURRING\_CONTRACT instead of AUTHORISATION for token webhook, use originalReference instead of pspReference
        commercepayments.TokenizeNotification tokenizeNotification = new commercepayments.TokenizeNotification();
        String gatewayToken = pspReference;
        tokenizeNotification.setGatewayTokenEncrypted(gatewayToken);
        notification = tokenizeNotification;
        String originalReference = notificationRequestItem.originalReference;
        notification.setGatewayReferenceNumber(originalReference);
    } else {
        system.debug('handling unknown event : ' + eventCode);
        commercepayments.GatewayNotificationResponse unknownEventResponse = new commercepayments.GatewayNotificationResponse();
        unknownEventResponse.setStatusCode(200);
        unknownEventResponse.setResponseBody(Blob.valueOf('\[not allowed\]'));
        return unknownEventResponse;
    }

    notification.setStatus(notificationStatus);
    notification.setAmount(amount / 100);
    notification.setGatewayResultCodeDescription(reason);
    notification.setGatewayDate(eventDate);

    commercepayments.NotificationSaveResult saveResult = commercepayments.NotificationClient.record(notification);

    commercepayments.GatewayNotificationResponse gnr = new commercepayments.GatewayNotificationResponse();
    if (saveResult.isSuccess()) {
        gnr.setStatusCode(200);
    } else {
        gnr.setStatusCode(400);
    }
    gnr.setResponseBody(Blob.valueOf(saveResult.toString()));
    return gnr;
}

- **[TokenizeNotification Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_methods)**

## TokenizeNotification Methods

The following are methods for TokenizeNotification.

- **[setAmount(amount)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setAmount)**  
    Sets the amount.
- **[setGatewayAvsCode(gatewayAvsCode)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayAvsCode)**  
    Sets the AVS (address verification system) result code information that the gateway returned. Maximum length of 64 characters.
- **[setGatewayDate(gatewayDate)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayDate)**  
    Sets the date that the sale occurred. Some gateways don’t send this value.
- **[setGatewayMessage(gatewayMessage)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayMessage)**  
    Sets error messages that the gateway returned for the sale request. Maximum length of 255 characters.
- **[setGatewayReferenceDetails(gatewayReferenceDetails)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayReferenceDetails)**  
    Sets additional data that you can use for payment tokenization. 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.
- **[setGatewayReferenceNumber(gatewayReferenceNumber)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayReferenceNumber)**  
    Sets the unique gateway reference number for the transaction that the gateway returned. Maximum length of 255 characters.
- **[setGatewayResultCode(gatewayResultCode)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayResultCode)**  
    Sets a gateway-specific result code. The code may be mapped to a Salesforce-specific result code. Maximum length of 64 characters.
- **[setGatewayResultCodeDescription(gatewayResultCodeDescription)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayResultCodeDescription)**  
    Sets a description of the gateway-specific result code that a payment gateway returned. Maximum length of 1000 characters.
- **[setGatewayToken(gatewayToken)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayToken)**  
    Sets the gateway token that the gateway returned.
- **[setGatewayTokenEncrypted(gatewayTokenEncrypted)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setGatewayTokenEncrypted)**  
    Sets an unencrypted unique token ID generated by the payment gateway to represent the saved payment method. Set the value of the gatewayTokenEncrypted field on a SavedPaymentMethod object.
- **[setId(id)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setId)**  
    Sets the ID of a notification sent by the payment gateway.
- **[setSalesforceResultCodeInfo(salesforceResultCodeInfo)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setSalesforceResultCodeInfo)**  
    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.
- **[setStatus(status)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_TokenizeNotification.htm#apex_commercepayments_TokenizeNotification_setStatus)**  
    Sets the notification status value on the notification object.

### setAmount(amount)

Sets the amount.

#### Signature

public void setAmount(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.")

#### 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

public void setGatewayAvsCode(String gatewayAvsCode)

#### Parameters

- **gatewayAvsCode**:
    
    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.")
    
    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 sale occurred. Some gateways don’t send this value.

#### Signature

public void setGatewayDate(Datetime gatewayDate)

#### Parameters

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

#### Return Value

Type: void

### setGatewayMessage(gatewayMessage)

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

#### Signature

public void setGatewayMessage(String gatewayMessage)

#### Parameters

- **gatewayMessage**:
    
    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.")

#### Return Value

Type: void

### setGatewayReferenceDetails(gatewayReferenceDetails)

Sets additional data that you can use for payment tokenization. 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

public void setGatewayReferenceDetails(String gatewayReferenceDetails)

#### Parameters

- **gatewayReferenceDetails**:
    
    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.")

#### 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

public void setGatewayReferenceNumber(String gatewayReferenceNumber)

#### Parameters

- **gatewayReferenceNumber**:
    
    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.")

#### Return Value

Type: void

### setGatewayResultCode(gatewayResultCode)

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

#### Signature

public void setGatewayResultCode(String gatewayResultCode)

#### Parameters

- **gatewayResultCode**:
    
    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.")

#### 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

public void setGatewayResultCodeDescription(String gatewayResultCodeDescription)

#### Parameters

- **gatewayResultCodeDescription**:
    
    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.")
    
    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

### setGatewayToken(gatewayToken)

Sets the gateway token that the gateway returned.

#### Signature

public void setGatewayToken(String gatewayToken)

#### Parameters

- **gatewayToken**:
    
    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.")

#### Return Value

Type: void

### setGatewayTokenEncrypted(gatewayTokenEncrypted)

Sets an unencrypted unique token ID generated by the payment gateway to represent the saved payment method. Set the value of the gatewayTokenEncrypted field on a SavedPaymentMethod object.

#### Signature

public void setGatewayTokenEncrypted(String gatewayTokenEncrypted)

#### Parameters

- **gatewayTokenEncrypted**:
    
    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.")

#### Return Value

Type: void

### setId(id)

Sets the ID of a notification sent by the payment gateway.

#### Signature

public void setId(String id)

#### Parameters

- **id**:
    
    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.")

#### 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

public void setSalesforceResultCodeInfo(commercepayments.SalesforceResultCodeInfo salesforceResultCodeInfo)

#### Parameters

- **salesforceResultCodeInfo**:
    
    Type: commercepayments.[SalesforceResultCodeInfo](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_commercepayments_SalesforceResultCode.htm "Defines the gateway call status values in Salesforce based on the call status values that the payment gateway returned.")

#### Return Value

Type: void

### setStatus(status)

Sets the notification status value on the notification object.

#### Signature

public void setStatus(commercepayments.NotificationStatus status)

#### Parameters

- **status**:
    
    Type: commercepayments.[NotificationStatus](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_commercepayments_NotificationStatus.htm "Shows whether the payments platform successfully received the notification from the gateway.")

#### Return Value

Type: void