PaymentMethodTokenizationRequest Class

Stores data about a request to tokenize a card payment method. The tokenization process occurs in the payment gateway. This process replaces sensitive customer data, such as a card number or CVV, with unique identification symbols. The symbols are used while the data is handled by Salesforce, the payment gateway, and the customer bank, allowing Salesforce to store the token without storing sensitive customer data.

Namespace

CommercePayments

Usage

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

CommercePayments.PaymentMethodTokenizationRequest pmtr = new CommercePayments.PaymentMethodTokenizationRequest();

This class holds all the required details about the tokenize request. Gateway adapters read the information in this class while constructing a tokenization JSON request, which is sent to the payment gateway.

Example

The following code is used within your payment gateway adapter Apex class.

Use the GatewayResponse class's processRequest method to build responses based on the request type that it receives from an instance of PaymentGatewayContext. If the request type is Tokenize, GatewayResponse calls the createTokenizeResponse method and passes an instance of the PaymentMethodTokenizationRequest class. The passed PaymentMethodTokenizationRequest object contains the address and cardPaymentMethod information that the payment gateway needs to manage the tokenization process. For example:
1global commercepayments.GatewayResponse processRequest(commercepayments.paymentGatewayContext gatewayContext) {
2         commercepayments.RequestType requestType = gatewayContext.getPaymentRequestType();
3         commercepayments.GatewayResponse response;
4         try
5         {
6             if (requestType == commercepayments.RequestType.Tokenize) {
7                     response = createTokenizeResponse((commercepayments.PaymentMethodTokenizationRequest)gatewayContext.getPaymentRequest());
8             }
9             //Add other else if statements for different request types as needed.
10             return response;
11         }
12         catch(SalesforceValidationException e)
13         {
14              commercepayments.GatewayErrorResponse error = new commercepayments.GatewayErrorResponse('400', e.getMessage());
15              return error;
16         }
17     }

Configure the createTokenizeResponse method to accept an instance of PaymentMethodTokenizationRequest. Then, build an instance of PaymentMethodTokenizationResponse based on the values received from the payment gateway.

1public commercepayments.GatewayResponse createTokenizeResponse(commercepayments.PaymentMethodTokenizationRequest tokenizeRequest) {
2         commercepayments.PaymentMethodTokenizationResponse tokenizeResponse = new commercepayments.PaymentMethodTokenizationResponse();
3         tokenizeResponse.setGatewayTokenEncrypted(encryptedValue);
4         tokenizeResponse.setGatewayTokenDetails(tokenDetails);
5         tokenizeResponse.setGatewayAvsCode(avsCode);
6         tokenizeResponse.setGatewayMessage(gatewayMessage);
7         tokenizeResponse.setGatewayResultCode(resultcode);
8         tokenizeResponse.setGatewayResultCodeDescription(resultCodeDescription);
9         tokenizeResponse.setSalesforceResultCodeInfo(resultCodeInfo);
10         tokenizeResponse.setGatewayDate(system.now());
11         return tokenizeResponse;
12     }

The tokenizeResponse contains the results of the gateway's tokenization process, and if successful, the tokenized value.

PaymentMethodTokenizationRequest Constructors

The following are constructors for PaymentMethodTokenizationRequest.

PaymentMethodTokenizationRequest(paymentGatewayId)

Payment gateway ID constructor used with paymentMethodTokenizationRequest. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

Signature

global PaymentMethodTokenizationRequest(String paymentGatewayId)

Parameters

paymentGatewayId
Type: String
The payment method’s payment gateway ID that will be tokenized.

PaymentMethodTokenizationRequest()

The following are constructors for PaymentMethodTokenizationRequest.

Signature

global PaymentMethodTokenizationRequest()

PaymentMethodTokenizationRequest Properties

The following are properties for PaymentMethodTokenizationRequest.

address

The card payment method address to be tokenized.

Signature

global commercepayments.AddressRequest address {get; set;}

Property Value

Type: AddressRequest

bankPaymentMethod

The bank payment method containing data to be tokenized.

Signature

public commercepayments.BankPaymentMethodRequest bankPaymentMethod {get; set;}

Property Value

Type: commercepayments.BankPaymentMethodRequest

cardPaymentMethod

The card payment method containing data to be tokenized.

Signature

global commercepayments.CardPaymentMethodRequest cardPaymentMethod {get; set;}

Property Value

Type: CardPaymentMethodRequest

savedByMerchant

Indicates whether the payment method to be tokenized is saved by the marchant (true) or not (false).

Signature

public Boolean savedByMerchant {get; set;}

Property Value

Type: Boolean

PaymentMethodTokenizationRequest Methods

The following are methods for PaymentMethodTokenizationRequest.

equals(obj)

Maintains the integrity of lists of type PaymentMethodTokenizationRequest by determining the equality of external objects in a list. This method is dynamic and is 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

hashCode()

Maintains the integrity of lists of type PaymentMethodTokenizationRequest by determining the uniquness of the external object records in a list.

Signature

global Integer hashCode()

Return Value

Type: Integer

toString()

Converts a date to a string.

Signature

global String toString()

Return Value

Type: String