Newer Version Available

This content describes an older version of this product. View Latest

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

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

1global commercepayments.GatewayNotificationResponse processNotification(commercepayments.PaymentGatewayNotificationContext gatewayNotificationContext) {
2    commercepayments.PaymentGatewayNotificationRequest gatewayNotificationRequest = gatewayNotificationContext.getPaymentGatewayNotificationRequest();
3    Blob request = gatewayNotificationRequest.getRequestBody();
4    AdyenNotificationRequest notificationRequest = AdyenNotificationRequest.parse(request.toString().replace('currency', 'currencyCode'));
5    List < AdyenNotificationRequest.NotificationItems > notificationItems = notificationRequest.notificationItems;
6    AdyenNotificationRequest.NotificationRequestItem notificationRequestItem = notificationItems[0].NotificationRequestItem;
7
8    Boolean success = Boolean.valueOf(notificationRequestItem.success);
9    String pspReference = notificationRequestItem.pspReference;
10    String eventCode = notificationRequestItem.eventCode;
11    Double amount = notificationRequestItem.amount.value;
12    String reason = notificationRequestItem.reason;
13    Datetime eventDate = notificationRequestItem.eventDate;
14
15    commercepayments.NotificationStatus notificationStatus = null;
16    if (success) {
17        notificationStatus = commercepayments.NotificationStatus.Success;
18    } else {
19        notificationStatus = commercepayments.NotificationStatus.Failed;
20    }
21
22    commercepayments.BaseNotification notification = null;
23    if ('RECURRING_CONTRACT'.equals(eventCode)) {
24        // NOTE: if you are consuming RECURRING_CONTRACT instead of AUTHORISATION for token webhook, use originalReference instead of pspReference
25        commercepayments.TokenizeNotification tokenizeNotification = new commercepayments.TokenizeNotification();
26        String gatewayToken = pspReference;
27        tokenizeNotification.setGatewayTokenEncrypted(gatewayToken);
28        notification = tokenizeNotification;
29        String originalReference = notificationRequestItem.originalReference;
30        notification.setGatewayReferenceNumber(originalReference);
31    } else {
32        system.debug('handling unknown event : ' + eventCode);
33        commercepayments.GatewayNotificationResponse unknownEventResponse = new commercepayments.GatewayNotificationResponse();
34        unknownEventResponse.setStatusCode(200);
35        unknownEventResponse.setResponseBody(Blob.valueOf('[not allowed]'));
36        return unknownEventResponse;
37    }
38
39    notification.setStatus(notificationStatus);
40    notification.setAmount(amount / 100);
41    notification.setGatewayResultCodeDescription(reason);
42    notification.setGatewayDate(eventDate);
43
44    commercepayments.NotificationSaveResult saveResult = commercepayments.NotificationClient.record(notification);
45
46    commercepayments.GatewayNotificationResponse gnr = new commercepayments.GatewayNotificationResponse();
47    if (saveResult.isSuccess()) {
48        gnr.setStatusCode(200);
49    } else {
50        gnr.setStatusCode(400);
51    }
52    gnr.setResponseBody(Blob.valueOf(saveResult.toString()));
53    return gnr;
54}

TokenizeNotification Methods

The following are methods for TokenizeNotification.

setAmount(amount)

Sets the amount.

Signature

public void setAmount(Double amount)

Parameters

amount
Type: Double

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

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

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

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

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

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

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

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

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

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

Return Value

Type: void