Bank Transaction Linking

Overview

We provide the ability to submit a bank account transaction identifier when capturing image for a paper document of type either receipt or invoice.

This provides facilitates creating link between a particular document and a bank account transaction.

This is helpful if an integrating app requires the ability to display a document associated with a particular bank account transaction, or display all document associated with a particular bank account.

Linking a Bank Transaction to a Document

  1. Determine documentType of type SensibillAPIModel.DocumentType that User wants to associate with document before starting capture.
  2. Determine accountTransactionId that User wants to associate with document before starting capture.
  3. Initialize CaptureFlowCoordinator with the host UIViewController that will be presenting the transaction linking flow.
  4. Set delegate of above created instance to the host UIViewController.
  5. Build DocumentMetadata by initializing DocumentMetadata.Builder with one of the documentType determined in Step1, and add accountTransactionID determined in Step2.
  6. Start transaction linking flow by passing DocumentMetadata object created in Step 4 using start(metadata:) method on instance of CaptureFlowCoordinator created in Step 1
  7. Retain instance of coordinator.
  8. Optionally (recommended) register a document upload observer with DocumentUploadObserver , so you can provide custom handling of various document uploading states for a generated document.

Note:

  • The result object received as part of CaptureFlowCoordinatorDelegate’s delegate method coordinatorDidFinishCapture(_ coordinator:, result:) contains one or more sourceId captured as part of transaction linking flow represents a document being uploaded to Sensibill.
  • The bank account transaction identifier (called accountTransactionId) is a free-form string that supports various transaction identifiers. It can be provided by the integrator via the add(accountTransactionID:) method of the DocumentMetadata.Builder object. See Monitoring Document Uploads

Example

import Sensibill

class ViewController: UIViewController {

    // MARK: - Private Properties

    private var captureFlowCoordinator: CaptureFlowCoordinator?

    // MARK: - Private Methods

    private func linkAccountTransaction() {

      // Step 1
      let documentType: SensibillAPIModel.DocumentType = ... // .invoice or .receipt

      // Step 2
      let accountTransactionID: String = ... // example: 1234

      // Step 3
      let coordinator = CaptureFlowCoordinator(host: self)

      // Step 4
      coordinator.delegate = self

      // Step 5
      let metadata = DocumentMetadata.Builder(documentType: documentType)
                    .add(accountTransactionID: accountTransactionID)
                    .build()

      // Step 6
      coordinator.start(metadata: metadata)

      // Step 7
      self.captureFlowCoordinator = coordinator
  }
}

When launching the Receipt Capture Flow , a transaction id can be provided. If a transaction id is provided, the transaction id will be attached as metadata to any receipt object that is created as a result of the capture flow.

For reference, the following snippets would be inserted in place of the code in step 3 of the Use Receipt Capture guide.

Kotlin

val myTransaction: MyTransactionModel // Your transaction model

captureFlow.launchCaptureFlow(
    captureFlowListener,
    externalAccountTransactionId = myTransaction.id
)

Java

final MyTransactionModel myTransaction;  // Your transaction model

captureFlow.launchCaptureFlow(
    captureFlowListener,
    CaptureFlowCoordinator.Companion.getDEFAULT_CONFIG()
    externalAccountTransactionId = myTransaction.getId()
);

Reference The Receipt Capture Flow
CaptureFlowCoordinator

Unlinking a Bank Transaction from a Document

The following example demonstrates how to unlink transactionId associated with document by submitting edit document request to Sensibill API.

func unlinkAccountTransaction(forDocumentID documentID: String) {

  do {

    let content = SensibillAPIModel.DocumentContentDto()

    let accountMetadata = SensibillAPIModel.AccountMetadata(
      account: nil,
      transactionId: ""
    )

    let update = SensibillAPIModel.EditDocumentRequestDto(
      content: content,
      accountMetadata: accountMetadata
    )

    try apiClient.documents.document(
      update: update,
      id: id
    )
    .execute { task in
      if let result = task.result {
        switch result {
          case .success:
            // Unlink successful.
          case .failure:
            // Unlink failed.
          }
        } else {
          ...
        }
      }
    } catch {
      // Unlink failed.
    }
}