Build the Offer Disqualification Scenario

This section describes how to build an offer disqualification scenario for the user, when the user fails to qualify for an offer. This section includes the following topics:

Build the Offer Disqualification Scenario

Build the Offer Disqualification Scenario

1.0. Integrate the Disqualification Status Webhook and Display the Disqualification Notification

This section details how to integrate the Disqualification Status webhook into your application, and use it to display the offer disqualification notification to your users. This section includes the following topics:

Build the Offer Disqualification Scenario

Build the Offer Disqualification Scenario

Build the Offer Disqualification Scenario

Build the Offer Disqualification Scenario

Build the Offer Disqualification Scenario

1.1. Integrate the Disqualification Status Webhook

Use the following code snippet to integrate the IQL Disqualification webhook into your application's backend.

@api_view(['POST'])
def qualification_webhook(request):
   try:
       original_data = request.data
       payload_data = format_webhook_payload(original_data)
       driver_id = payload_data['user']
       driver = User.objects.get(driver_id=driver_id)
       push_service = PushService()
       push_service.send_disqualification_push(driver)

       return Response(status=status.HTTP_200_OK)

   except User.DoesNotExist:
       logger.error("Disqualification web-hook was sent for a non-existent user"
                    + driver_id)
       return Response(status=status.HTTP_400_BAD_REQUEST)
   except PushService.Error as e:
       logger.exception(e)
       return Response(status=status.HTTP_200_OK)

1.2. Send a Push Notification Upon Receipt of Webhook

Use the following code snippet to dispatch a push notification to your application's backend when you receive the qualification webhook.

class PushService:
   def send_disqualification_push(self, driver):
       message = {
           "title":
           "Thank you for completing your test drive",
           "body":
           "Unfortunately, no qualified offers are currently available. We are always looking for new ways to reward safe driving. Keep driving, we will notify you when new offers are available to you."
       }
       self.send_push(
           driver,
           message=message,
           extra={
               "type": "no_offer_generated",
"msg_txt": message
           })

   def send_push(self, driver, message, extra, is_silent=False):
       gcm_devices = GCMDevice.objects.filter(user=driver)
       apns_devices = APNSDevice.objects.filter(user=driver)
       if gcm_devices.exists() or apns_devices.exists():
           try:
               if not is_silent and 'title' in message and 'body' in message:
                   gcm_devices.send_message(
                       message=message['body'],
                       title=message['title'],
                       extra=extra)
               else:
                   gcm_devices.send_message(message=None, extra=extra)
           except Exception:
               raise PushService.GCMError(
                   "Unable to send push notification to Android devices of user, {}."
                   .format(driver.driver_id))
           try:
               # Remote pushes to iOS devices will show an alert as well as wake up the app in the background.
               apns_devices.send_message(
                   message=message,
                   content_available=(1 if is_silent else 0),
                   extra=extra)
           except Exception:
               raise PushService.APNSError(
                   "Unable to send push notification to iOS devices of user, {}."
                   .format(driver.driver_id))
       else:
           raise PushService.NoRegisteredDevicesError(
               "{} does not have any registered device token.".format(
                   driver.driver_id))

   class Error(Exception):
       """
       Base exception for PushService.
       """

   class NoRegisteredDevicesError(Error):
       """
       Raised if the user doesn't have any registered device tokens.
       """

   class GCMError(Error):
       """
       Raised upon failure to send push to Android devices.
       """

   class APNSError(Error):
       """
       Raised upon failure to send push to iOS devices.
       """

1.3. Display the Disqualification Notification

Display notification to the user informing them of offer disqualification, whenever a disqualification webhook is received.

1.4. Display Offer Disqualification Screen Upon User Tap

Open the application and display the Offer Disqualification screen when the user taps on the disqualification notification.

1.5. Display Disqualification Band Using driverStatus API

Webhook delivery might fail owing to network issues, or if the user has turned off notifications. In such cases, it is important to ensure that users are still notified of their test drive status. For this reason, you need to use the IQL driverStatus API to check if the user has qualified for an offer after the test drive period has ended.

Refer to the following design sequence to build offer disqualification UI.

2.0. QL Reference Application UX Design

Here is the overall design implementation for the IQL Reference Application: