Flow

GiniHealth is the main class for interacting with the Gini Health SDK. It provides a way to submit a document for reviewing its extracted payment details and let’s the user make the payment with one of the payment providers.

The recommended flow is to:
  1. Call GiniHealth.checkRequirementsAsync() to make sure that the flow can be completed.
  2. Call one of the overloads of setDocumentForReview, to submit a document.
  3. Display ReviewFragment.

Checking requirements

Requirements are not enforced, but recommended. Review Fragment will still start, but the flow cannot be completed if not all requirements are met.

checkRequirementsAsync() returns a list of missing requirements. Empty list means all requirements are met.

Setting a document for review

setDocumentForReview can be called with:
  1. Document instance in the case the upload was performed with Gini Pay Api lib (see Gini class).
  2. Document id, this will probably be the case when there’s backend integration between the client and Gini.

When calling it with an id the SDK will make a network call to obtain a Document instance. So it is preferred to use the Document instance if you already have it. The same applies to the optional PaymentDetails, if they are present they will be displayed and network calls to get extractions will be skipped.

The exposed flows of GiniHealth are used by the ReviewFragment to observe the state of the document and extractions, but they are public so that they can be observed anywhere, the main purpose for this is to observe errors.

Note: If you observe payment details flow, you can check PaymentDetails.isPayable as an extra condition before displaying the ReviewFragment.

Display ReviewFragment

ReviewFragment displays document pages and extractions and it lets the user pay using a payment provider

To instantiate it you need to create a FragmentFactory and set it to fragment manager:

class ReviewFragmentFactory(private val giniHealth: GiniHealth,
                            private val configuration: ReviewConfiguration,
                            private val listener: ReviewFragmentListener
) : FragmentFactory() {
    override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
        return ReviewFragment(giniHealth, configuration, listener)
    }
}

supportFragmentManager.fragmentFactory = ReviewFragmentFactory(giniHealth)

ReviewFragment handles errors by default, displaying snackbars for errors, but it can be configured to ignore them, in which case all flows of GiniHealth should be observed for errors.

Event Tracking

To get informed of ReviewFragment events (like the user clicking the “close” or “next” button) you can implement the ReviewFragmentListener and pass it to the fragment constructor.