Events Subscription - AEVI-AppFlow/pos-android-sdk GitHub Wiki

Any application can via the PaymentClient.subscribeToSystemEvents() subscribe to events from FPS. This method will return a stream of FlowEvent objects, each defined by a type. There are currently two main types of events defined;

  • FPS configuration state changes
  • External state changes

The main purpose of providing these events is to allow clients to re-query for relevant data when it has changed. In the v2 PaymentClient, most of this data is wrapped in the PaymentSettings, meaning a call to paymentClient.getPaymentSettings() to update any such cached data would be required to ensure up-to-date information.

FPS configuration changes

Whenever there is a change to the flow configurations or the FpsSettings, an event with type flowStateChanged will be published. This event type has two associated data keys;

  • eventKeySettingsChanged - When the FpsSettings have changed
  • eventKeyFlowConfigsChanged - When the flow configurations have changed

External state changes

When something external to FPS has changed, such as a flow service being installed, uninstalled or updated, or an additional device is connected or disconnected, an event with type externalStateChanged will be published. This event has two associated data keys;

  • eventKeyFlowServicesChanged - When flow services have changed
  • eventKeyDevicesChanged - When additional devices state has changed

Example

paymentClient.subscribeToSystemEvents().subscribe(flowEvent -> {
    String type = flowEvent.getType();
    switch (type) {
        case "flowStateChanged":
            boolean flowConfigsChanged = flowEvent.getData().getBooleanValue("eventKeyFlowConfigsChanged", false);
            boolean fpsSettingsChanged = flowEvent.getData().getBooleanValue("eventKeySettingsChanged", false);
            break;
        case "externalStateChanged":
            boolean flowServicesChanged = flowEvent.getData().getBooleanValue("eventKeyFlowServicesChanged", false);
            boolean devicesChanged = flowEvent.getData().getBooleanValue("eventKeyDevicesChanged", false);
            break;
    }