TokenizeNotification Class
Namespace
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)
Signature
public void setAmount(Double amount)
Parameters
- amount
- Type: Double
Return Value
Type: void
setGatewayAvsCode(gatewayAvsCode)
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)
Signature
public void setGatewayDate(Datetime gatewayDate)
Parameters
- gatewayDate
- Type: Datetime
Return Value
Type: void
setGatewayMessage(gatewayMessage)
Signature
public void setGatewayMessage(String gatewayMessage)
Parameters
- gatewayMessage
- Type: String
Return Value
Type: void
setGatewayReferenceDetails(gatewayReferenceDetails)
Signature
public void setGatewayReferenceDetails(String gatewayReferenceDetails)
Parameters
- gatewayReferenceDetails
- Type: String
Return Value
Type: void
setGatewayReferenceNumber(gatewayReferenceNumber)
Signature
public void setGatewayReferenceNumber(String gatewayReferenceNumber)
Parameters
- gatewayReferenceNumber
- Type: String
Return Value
Type: void
setGatewayResultCode(gatewayResultCode)
Signature
public void setGatewayResultCode(String gatewayResultCode)
Parameters
- gatewayResultCode
- Type: String
Return Value
Type: void
setGatewayResultCodeDescription(gatewayResultCodeDescription)
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)
Signature
public void setGatewayToken(String gatewayToken)
Parameters
- gatewayToken
- Type: String
Return Value
Type: void
setGatewayTokenEncrypted(gatewayTokenEncrypted)
Signature
public void setGatewayTokenEncrypted(String gatewayTokenEncrypted)
Parameters
- gatewayTokenEncrypted
- Type: String
Return Value
Type: void
setSalesforceResultCodeInfo(salesforceResultCodeInfo)
Signature
public void setSalesforceResultCodeInfo(commercepayments.SalesforceResultCodeInfo salesforceResultCodeInfo)
Parameters
- salesforceResultCodeInfo
- Type: commercepayments.SalesforceResultCodeInfo
Return Value
Type: void
setStatus(status)
Signature
public void setStatus(commercepayments.NotificationStatus status)
Parameters
- status
- Type: commercepayments.NotificationStatus
Return Value
Type: void