Extend the webhook framework
Learn how to extend the webhook framework.
The Salesforce Lightning—Digital River Connector App comes with a webhook framework that is capable of accepting and consuming any webhook that can be configured in the Digital River Dashboard. For OOTB (out-of-the-box) webhook events, see the set up webhooks section.
You can always extend this framework to implement custom code that will fire upon receipt of a Webhook from Digital River. The event needs to be added to the previously-created webhook in the Digital River Dashboard.

Extending the webhook

To implement the custom business logic for your organization, write the subscriber code that extends the default Webhook Framework Extension point class digitalriverv3.DRB2B_WebhookHandler.
For example, suppose you want to implement custom business logic for the event refund.pending
    In your organization, create an Apex class that extends the extension point class digitalriverv3.DRB2B_WebhookHandler global with sharing class DRB2B_RefundPendingWebhook extends the digitalriverv3.DRB2B_WebhookHandler { }
    Inside the class definition, override the method processWebhookEvent of the extension point class digitalriverv3.DRB2B_WebhookHandler. This method will have the Event Payload as one of its Input parameters.
1
global class DRB2B_RefundPendingWebhook extends
2
digitalriverv3.DRB2B_WebhookHandler {
3
4
global override void processWebhookEvent(RestResponse response,
5
String webhookEventPayload) {
6
// Custom Implementation
7
}
8
9
}
Copied!
    Inside your method override, add your custom business logic. Ensure the RestResponse status code is set to 200 as shown in the sample implementation for the refund.pending webhook event below.

DRB2B_RefundPendingWebhook

1
global class DRB2B_RefundPendingWebhook extends
2
digitalriverv3.DRB2B_WebhookHandler {
3
4
private static final digitalriverv3.DCM_Logger
5
logger = digitalriverv3.DCM_Logger.getInstance('Webhook Event');
6
7
global override void processWebhookEvent(RestResponse response,
8
String
9
webhookEventPayload) {
10
// Log the event to DCM Application log object
11
logger.debug('Event: refund.pending; Refund Pending Webhook
12
Event Payload: ' + webhookEventPayload);
13
14
Messaging.SingleEmailMessage email = new
15
Messaging.SingleEmailMessage();
16
email.setSubject('Process Webhook for event: refund.pending');
17
email.setToAddresses(new List<String>
19
email.setHtmlBody(webhookEventPayload + '<br/> <br/>');
20
Messaging.sendEmail(new Messaging.SingleEmailMessage[]
21
{ email });
22
23
response.statusCode = 200;
24
}
25
26
}
Copied!
Save your class and resolve any compilation errors.

Configuring the Apex class

Your Apex class must be configured so that the Connector is aware and executes this Custom Webhook handler implementation whenever it receives the event refund.pending from Digital River.
    1.
    Go to the Custom Metadata Type digitalriverv3_DR_Webhook_Configuration_
    mdt and click Manage Records.
    2.
    Create a new Metadata Type Record for the DR Webhook Configuration.
      Label: Refund Pending Webhook Handler
      DR Webhook Configuration Name: Refund_Pending_Webhook_Handler
      Webhook Event Name: refund.pending (This is the event type of the webhook.)
      Webhook Handler Name: DRB2B_RefundPendingWebhook (Custom Class Name)
    3.
    Click Save.
    4.
    Set up the webhook for the Event Type refund.pending in the Dashboard.
    5.
    Configure the webhook for this event by going to Webhooks and click the Webhooks endpoint that was previously configured for your organization. It will have an address of https://<<SF_My_Domain_Name>>/services/apexrest/digitalriverv3/webhooks
    6.
    Select the event refund.pending for the Webhook Endpoint selected in the previous step.

Webhook framework extension (example 2)

This section details another example of how to extend the webhook framework, this time for the refund.complete event. In this example, an email is sent with the event payload.

DRB2B_RefundCompleteWebhook

1
global class DRB2B_RefundCompleteWebhook extends
2
digitalriverv3.DRB2B_WebhookHandler {
3
4
private static final digitalriverv3.DCM_Logger logger =
5
digitalriverv3.DCM_Logger.getInstance('Webhook Event');
6
7
global override void processWebhookEvent(RestResponse response,
8
String webhookEventPayload) {// Log the event to Application log object
9
logger.debug('Event: refund.complete; Refund Complete Webhook Event
10
Payload: ' + webhookEventPayload);
11
12
// Send Email
13
Messaging.SingleEmailMessage email =
14
new Messaging.SingleEmailMessage();
15
email.setSubject('Process Webhook for event: refund.complete');
16
email.setToAddresses(new List<String>
18
email.setHtmlBody(webhookEventPayload + '<br/> <br/>');
19
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
20
21
response.statusCode = 200;
22
}
23
24
}
25
Copied!
Continue with the steps detailed in Configuring the Apex class to complete the configuration of the webhook extension.
Last modified 1mo ago