Namespace
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.
global commercepayments.GatewayResponse processRequest(commercepayments.paymentGatewayContext gatewayContext) { commercepayments.RequestType requestType = gatewayContext.getPaymentRequestType(); commercepayments.GatewayResponse response; try { if (requestType == commercepayments.RequestType.Tokenize) { response = createTokenizeResponse((commercepayments.PaymentMethodTokenizationRequest)gatewayContext.getPaymentRequest()); } //Add other else if statements for different request types as needed. return response; } catch(SalesforceValidationException e) { commercepayments.GatewayErrorResponse error = new commercepayments.GatewayErrorResponse('400', e.getMessage()); return error; } }
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.
public commercepayments.GatewayResponse createTokenizeResponse(commercepayments.PaymentMethodTokenizationRequest tokenizeRequest) { commercepayments.PaymentMethodTokenizationResponse tokenizeResponse = new commercepayments.PaymentMethodTokenizationResponse(); tokenizeResponse.setGatewayTokenEncrypted(encryptedValue); tokenizeResponse.setGatewayTokenDetails(tokenDetails); tokenizeResponse.setGatewayAvsCode(avsCode); tokenizeResponse.setGatewayMessage(gatewayMessage); tokenizeResponse.setGatewayResultCode(resultcode); tokenizeResponse.setGatewayResultCodeDescription(resultCodeDescription); tokenizeResponse.setSalesforceResultCodeInfo(resultCodeInfo); tokenizeResponse.setGatewayDate(system.now()); return tokenizeResponse; }
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)
Signature
global PaymentMethodTokenizationRequest(String paymentGatewayId)
Parameters
-
paymentGatewayId:
Type: String
The payment method’s payment gateway ID that will be tokenized.
PaymentMethodTokenizationRequest Properties
The following are properties for PaymentMethodTokenizationRequest.
address
Signature
global commercepayments.AddressRequest address {get; set;}
Property Value
Type: AddressRequest
bankPaymentMethod
Signature
public commercepayments.BankPaymentMethodRequest bankPaymentMethod {get; set;}
Property Value
Type: commercepayments.BankPaymentMethodRequest
cardPaymentMethod
Signature
global commercepayments.CardPaymentMethodRequest cardPaymentMethod {get; set;}
Property Value
Type: CardPaymentMethodRequest
savedByMerchant
Signature
public Boolean savedByMerchant {get; set;}
Property Value
Type: Boolean
PaymentMethodTokenizationRequest Methods
The following are methods for PaymentMethodTokenizationRequest.
equals(obj)
Signature
global Boolean equals(Object obj)
Parameters
-
obj:
Type:
Object External object whose key is to be validated.
Return Value
Type: Boolean
hashCode()
Signature
global Integer hashCode()
Return Value
Type: Integer