Newer Version Available
SaleNotification Class
Namespace
Usage
SaleNotification 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.SaleNotification saleNotification = new commercepayments.SaleNotification();
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 ('AUTHORISATION'.equals(eventCode) && amount > 0) {
24 notification = new commercepayments.SaleNotification();
25 notification.setGatewayReferenceNumber(pspReference);
26 } else {
27 system.debug('handling unknown event : ' + eventCode);
28 commercepayments.GatewayNotificationResponse unknownEventResponse = new commercepayments.GatewayNotificationResponse();
29 unknownEventResponse.setStatusCode(200);
30 unknownEventResponse.setResponseBody(Blob.valueOf('[not allowed]'));
31 return unknownEventResponse;
32 }
33
34 notification.setStatus(notificationStatus);
35 notification.setAmount(amount / 100);
36 notification.setGatewayResultCodeDescription(reason);
37 notification.setGatewayDate(eventDate);
38
39 commercepayments.NotificationSaveResult saveResult = commercepayments.NotificationClient.record(notification);
40
41 commercepayments.GatewayNotificationResponse gnr = new commercepayments.GatewayNotificationResponse();
42 if (saveResult.isSuccess()) {
43 gnr.setStatusCode(200);
44 } else {
45 gnr.setStatusCode(400);
46 }
47 gnr.setResponseBody(Blob.valueOf(saveResult.toString()));
48 return gnr;
49}SaleNotification Methods
The following are methods for SaleNotification.
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
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