Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagekotlin
// Use the androidx's Activity Result API to register a handler for the capture result.
val captureLauncher = registerForActivityResult(CaptureFlowContract()) { result: CaptureResult ->
    when (result) {
        is CaptureResult.Success -> {
            handleExtractions(result.specificExtractions)
        }
        is CaptureResult.Error -> {
            when (result.value) {
                is ResultError.Capture -> {
                    val captureError: GiniCaptureError = (result.value as ResultError.Capture).giniCaptureError
                    handleCaptureError(captureError)
                }
                is ResultError.FileImport -> {
                    // See the File Import section on the Capture Features page for more details.
                    val fileImportError = result.value as ResultError.FileImport
                    handleFileImportError(fileImportError)
                }
            }
            GiniBank.sendTransferSummary(
                "", "", "", "", "", Amount.EMPTY
            )
            GiniBank.releaseCapture(
                this
            )
        }
        CaptureResult.Empty -> {
            handleNoExtractions()
            GiniBank.sendTransferSummary(
                "", "", "", "", "", Amount.EMPTY
            )
            GiniBank.releaseCapture(
                this
            )
        }
        CaptureResult.Cancel -> {
            handleCancellation()
            GiniBank.sendTransferSummary(
                "", "", "", "", "", Amount.EMPTY
            )
            GiniBank.releaseCapture(
                this
            )
        }
        CaptureResult.EnterManually -> {
            handleEnterManually()
            GiniBank.sendTransferSummary(
                "", "", "", "", "", Amount.EMPTY
            )
            GiniBank.releaseCapture(
                this
            )
        }
    }
}

fun launchGiniCapture() {
    // Make sure camera permission has been already granted at this point.

    // Instantiate the networking implementation.
    val networkService: GiniCaptureNetworkService  = ...

    // Configure the capture feature.
    GiniBank.setCaptureConfiguration(
        CaptureConfiguration(
            networkService = networkService,
            ...
        )
    )

    // Launch and wait for the result.
    GiniBank.startCaptureFlow(captureLauncher)
}

voidfun stopGiniBankSDK() {
    // After the user has seen and potentially corrected the extractions, send the final
    // transfer summary values to Gini which will be used to improve the future extraction accuracy:
    GiniBank.sendTransferSummary(
            paymentRecipient,
            paymentReference,
            paymentPurpose,
            iban,
            bic,
            amount
            )
            
    // cleanup the capture SDK after sending the transfer summary
    GiniBank.releaseCapture(this)
}