Flow response listeners - AEVI-AppFlow/pos-android-sdk GitHub Wiki

It is possible for both client (POS) applications and flow services to define response entry points that gets called when the final flow responses are available, in a similar way to how flow services are called in the flow itself.

This is how client applications receives responses for the flows they initiate and for flow services it may be useful to review the outcome for some reason or have an opportunity to undo changes made in the flow upon errors, cancellations, etc. As an example, if loyalty points were used and the transaction is later declined or cancelled, it would allow a loyalty app to refund those points back to the customer. Note that only the BasePaymentResponseListenerService is relevant for flow services.

This can be done by extending and implementing one of the response listener services. Currently two base listener services are defined:

  • BaseResponseListenerService - to listen for Response objects resulting from a initial Request
  • BasePaymentResponseListenerService - to listen for PaymentResponse objects resulting from a Payment request

Response service

Response service have two callback methods for responses - one for generic responses, such as for any of the defined request types or custom request types, and one for responses from a status update flow. These are delivered separately as many clients may not be interested in responses from status updates.

public class ResponseListenerService extends BaseResponseListenerService {

    @Override
    protected void notifyGenericResponse(Response response) {
       // Handle generic response
    }

    @Override
    protected void notifyStatusUpdateResponse(Response response) {
       // Handle (if required) status update response
    }

    @Override
    protected void notifyError(String errorCode, String errorMessage) {
        // Map error code against one of `ErrorConstants`
    }
}

Payment response service

Your application should implement the notifyResponse and notifyError methods as shown in the example for payment responses below.

public class PaymentResponseListenerService extends BasePaymentResponseListenerService {

    @Override
    protected void notifyResponse(PaymentResponse paymentResponse) {
       // Handle response
    }

    @Override
    protected void notifyError(String errorCode, String errorMessage) {
       // Map error code against one of `ErrorConstants`
    }
}

Exposing services

The service(s) should be registered in your manifest as normal and should include the correct intent filter as shown below.

        <service
            android:name=".PaymentResponseListenerService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.aevi.sdk.flow.action.PROCESS_PAYMENT_RESPONSE"/>
            </intent-filter>
        </service>

        <service
            android:name=".ResponseListenerService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.aevi.sdk.flow.action.PROCESS_RESPONSE"/>
            </intent-filter>
        </service>

Note - A client will only be notified of responses that it itself initiated and flow services will only be notified of responses for payment flows in which it was called.

See Handling Responses for more information on how to parse the response data and see Handling Errors for details how to map the error codes.

⚠️ **GitHub.com Fallback** ⚠️