PaymentMethodTokenizationResponse Class
Namespace
Usage
The constructor of this class takes no arguments. For example:
CommercePayments.PaymentMethodTokenizationResponse pmtr = new CommercePayments.PaymentMethodTokenizationResponse();After the payment gateway processes a tokenization request, the fields of PaymentMethodTokenizationResponse receive and store information from the gateway's response. The gateway's response shows whether the tokenization request was successful, the token value, and any additional messages or information about the tokenization process. You can then pass an instance of PaymentMethodTokenizationResponse to an authorization response or a sale response. This class is mapped to a response class in the Java layer.
Example
This constructor builds a new instance of the PaymentMethodTokenizationResponse class.
commercepayments.PaymentMethodTokenizationResponse tokenizeResponse = new commercepayments.PaymentMethodTokenizationResponse();
PaymentMethodTokenizationResponse contains only setter methods. Each setter accepts a value from the payment gateway and use it to set an attribute of PaymentMethodTokenizationResponse.
The most important method in PaymentMethodTokenizationResponse is setGatewayTokenEncrypted, which uses Salesforce encryption to set an encrypted token value for a payment method. The setGatewayTokenEncrypted method is available in Salesforce API v52.0 and later. We recommend using it to ensure your tokenized payment method values are encrypted and secure. While the setGatewayToken method (available in earlier API versions) also returns a payment method token, the tokenized value isn't encrypted.
If the instantiated class already has a gateway token, setGatewayTokenEncrypted throws an error.
/** @description Method to set Gateway token to persist in Encrypted Text */
global void setGatewayTokenEncrypted(String gatewayTokenEncrypted) {
if (gatewayTokenSet) {
throwTokenError();
}
this.delegate.setGatewayTokenEncrypted(gatewayTokenEncrypted);
gatewayTokenEncryptedSet = true;
}
public commercepayments.GatewayResponse createTokenizeResponse(commercepayments.PaymentMethodTokenizationRequest tokenizeRequest) {
commercepayments.PaymentMethodTokenizationResponse tokenizeResponse = new commercepayments.PaymentMethodTokenizationResponse();
tokenizeResponse.setGatewayTokenEncrypted(gatewayTokenEncrypted);
tokenizeResponse.setGatewayTokenDetails(gatewayTokenDetails);
tokenizeResponse.setGatewayAvsCode(gatewayAvsCode);
tokenizeResponse.setGatewayMessage(gatewayMessage);
tokenizeResponse.setGatewayResultCode(gatewayResultCode);
tokenizeResponse.setGatewayResultCodeDescription(gatewayResultCodeDescription);
tokenizeResponse.setSalesforceResultCodeInfo(SUCCESS_SALESFORCE_RESULT_CODE_INFO);
tokenizeResponse.setGatewayDate(system.now());
return tokenizeResponse;
}
After you've built a PaymentMethodTokenizationResponse object and set the encrypted gateway token, pass the object to the setPaymentMethodTokenizationResponse method of an authorization response or a sale response.
- Authorization Response
-
public commercepayments.GatewayResponse createAuthResponse(commercepayments.AuthorizationRequest authRequest) { commercepayments.AuthorizationResponse authResponse = new commercepayments.AuthorizationResponse(); commercepayments.PaymentMethodTokenizationResponse paymentMethodTokenizationResponse = new commercepayments.PaymentMethodTokenizationResponse(); if(authRequest.amount!=null ) { authResponse.setAmount(authRequest.amount); } else { throw new SalesforceValidationException('Required Field Missing : Amount'); } authResponse.setGatewayResultCode('00'); authResponse.setGatewayResultCodeDescription('Transaction Normal'); authResponse.setGatewayAuthCode('SF'+getRandomNumber(6)); authResponse.setGatewayReferenceNumber(getRandomNumber(10)); authResponse.setSalesforceResultCodeInfo(SUCCESS_SALESFORCE_RESULT_CODE_INFO); authResponse.setGatewayDate(system.now()); paymentMethodTokenizationResponse.setGatewayTokenEncrypted(gatewayTokenEncrypted); authResponse.setPaymentMethodTokenizationResponse(paymentMethodTokenizationResponse); return authResponse; }
- Sale Response
-
public commercepayments.GatewayResponse createSaleResponse(commercepayments.SaleRequest saleRequest) { commercepayments.SaleResponse saleResponse = new commercepayments.SaleResponse(); commercepayments.PaymentMethodTokenizationResponse paymentMethodTokenizationResponse = new commercepayments.PaymentMethodTokenizationResponse(); if(saleRequest.amount!=null ) { saleResponse.setAmount(saleRequest.amount); } else { throw new SalesforceValidationException('Required Field Missing : Amount'); } system.debug('Response - success'); saleResponse.setGatewayDate(system.now()); saleResponse.setGatewayResultCode('00'); saleResponse.setGatewayResultCodeDescription('Transaction Normal'); saleResponse.setGatewayReferenceNumber('SF'+getRandomNumber(6)); saleResponse.setSalesforceResultCodeInfo(SUCCESS_SALESFORCE_RESULT_CODE_INFO); paymentMethodTokenizationResponse.setGatewayTokenEncrypted(gatewayTokenEncrypted); saleResponse.setPaymentMethodTokenizationResponse(paymentMethodTokenizationResponse); return saleResponse; }
PaymentMethodTokenizationResponse Methods
The following are methods for PaymentMethodTokenizationResponse.
setGatewayAvsCode(gatewayAvsCode)
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)
Signature
global void setGatewayDate(Datetime gatewayDate)
Parameters
- gatewayDate
- Type: Datetime
Return Value
Type: void
setGatewayMessage(gatewayMessage)
Signature
global void setGatewayMessage(String gatewayMessage)
Parameters
- gatewayMessage
- Type: String
Return Value
Type: void
setGatewayResultCode(gatewayResultCode)
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)
Signature
global void setGatewayResultCodeDescription(String gatewayResultCodeDescription)
Parameters
- gatewayResultCodeDescription
- Type: String
- Provides additional information about the result code and why the gateway returned the specific code. Descriptions will vary between different gateways.
Return Value
Type: void
setGatewayToken(gatewayToken)
Signature
global void setGatewayToken(String gatewayToken)
Parameters
- gatewayToken
- Type: String
- The gateway token that the payment gateway sends following a tokenization request.
- For the CardPaymentMethod and DigitalWallet objects, use the gatewyTokenEncrypted parameter, which encrypts the token value.
Return Value
Type: void
setGatewayTokenDetails(gatewayTokenDetails)
Signature
global void setGatewayTokenDetails(String gatewayTokenDetails)
Parameters
- gatewayTokenDetails
- Type: String
Return Value
Type: void
setGatewayTokenEncrypted(gatewayTokenEncrypted)
Signature
global void setGatewayTokenEncrypted(String gatewayTokenEncrypted)
Parameters
- gatewayTokenEncrypted
- Type: String
- The gateway token that the payment gateway sends following a tokenization request. Salesforce Payments uses Salesforce encryption to encrypt the token value.
Return Value
Type: void
setSalesforceResultCodeInfo(salesforceResultCodeInfo)
Signature
global void setSalesforceResultCodeInfo(commercepayments.SalesforceResultCodeInfo salesforceResultCodeInfo)
Parameters
- salesforceResultCodeInfo
- Type: SalesforceResultCodeInfo
- Description of the Salesforce result code value.
Return Value
Type: void