Skip to main content

Communication

Upload a document and get instant results. Gain a deeper understanding of how Veryfi Lens interacts with your application.

Download on theApp StoreDownload on theGoogle Play

  1. Set your delegate:
VeryfiLens.shared().delegate = self
  1. Implement the delegate methods:
extension ViewController: VeryfiLensDelegate {

func veryfiLensClose(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensClose: " + jsonString!)) // do something with the JSON here
}

func veryfiLensUpdate(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensUpdate: " + jsonString!)) // do something with the JSON here
}

func veryfiLensSuccess(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensSuccess: " + jsonString!)) // do something with the JSON here
}

func veryfiLensError(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensError: " + jsonString!)) // do something with the error JSON here
}

Note: If your project is using Swift 6 add @preconcurrency keyword to your delegate implementation like this:

extension ViewController: @preconcurrency VeryfiLensDelegate {
//... Delegate methods implementation
}

Delegate Definitions

  • veryfiLensClose - the Veryfi Lens camera has been closed, either as a result of submitting an image for processing, or the user closed the camera without submitting an image.
{
"status": "close",
"queue_count": 1,
"framework-version": "1.4.0",
"session_scan_count": 1,
"framework-build": "1"
}

NOTE: In the object above, queue_count refers to the number of submitted documents that are currently in the processing queue. session_scan_count refers to the number of documents that were submitted in the most recent Lens camera session - if this is equal to 0 (zero) then the camera session was canceled without submitting anything.

  • veryfiLensUpdate - during the processing of a document, this delegate will be fired multiple times. One time it will contain the thumbnail path for the submitted document and one time it will contain a full-size image path. In addition, multiple instances of this delegate will be fired containing the current upload progress percentage.

Sample package created notification:

{
"status": "start",
"package_id": "edc8653e4c2b4ef1"
}

Submit was pressed while submitWithoutClose is enabled

{
"status" : "update",
"msg" : "submit_without_close"
}

There will be another message with the amount of documents to process:

{
"status": "start",
"msg": "on_multiple_documents",
"data": 1,
"images_count": 4,
"multiple_transactions": false
}

There will be another message with the following document information:

{
"blur_detected": 0,
"image_size": "{}",
"status": "inprogress",
"document_detected": 1,
"source": "scan",
"device_angle": 0,
"detected_objects": [],
"msg": "document_information",
"lcd_results": "[]",
"package_id": "edc8653e4c2b4ef1",
"corners": "[]",
"document_type": "receipt",
"lcd_scores": []
}

Thumbnail shared example:

{
"status": "inprogress",
"msg": "img_thumbnail_path",
"data": "/path/to/thumbnail.jpg",
"package_id": "edc8653e4c2b4ef1"
}

Full-size image shared example:

{
"status": "inprogress",
"msg": "img_original_path",
"data": "/path/to/image.jpg",
"package_id": "edc8653e4c2b4ef1",
"document_type": "receipt"
}

Stitched PDF shared example:

{
"status": "inprogress",
"msg": "img_stitched_pdf_path",
"data": "/path/to/images.pdf",
"package_id": "edc8653e4c2b4ef1"
}

Upload progress example:

{
"status": "inprogress",
"msg": "progress",
"data": 68,
"package_id": "edc8653e4c2b4ef1"
}

Package removed example:

{
"status": "removed",
"msg": "clear_package",
"package_id": "edc8653e4c2b4ef1"
}
  • veryfiLensError - if an error occurs during uploading or processing a submitted or a general exception or crash is caught in Veryfi Lens, this notification contains the error details.

Sample error data:

{
"status": "error",
"package_id": "edc8653e4c2b4ef1",
"error": "[Wombat].Reachability.noInternetConnection"
}
  • veryfiLensSuccess - this delegate fires once a document has finished processing, whether it was submitted via the camera, the gallery, or it was dictated or entered/typed manually. This delegate provides the response from the Veryfi API.

Example:

{
"data": {"total":6.6,"invoice_number":"04814","subtotal":6.36,"currency_code":"USD","total_pages":1,"date":"2023-03-21 19:31:00","payment":{"card_number":"0115","display_name":"Visa ***0115","type":"visa"},"reference_number":"VDCBJ-81080","accounting_entry_type":"debit","id":339981080,"vendors":["Walmart","Walmart"],"vendor":{"raw_name":"Walmart","country_code":"US","lng":-122.109695,"category":"Department Store","name":"Walmart","map_url":"https:\/\/www.google.com\/maps\/search\/?api=1&query=Walmart+600+SHOWERS+DR+MOUNTAIN+VIEW+CA+94040+TR#+TE#+OP#","raw_address":"600 SHOWERS DR\nMOUNTAIN VIEW CA 94040","type":"Department Store","phone_number":"650-917-0796","web":"survey.walmart.com","external_id":null,"external_ids":[],"lat":37.400925,"logo":"https:\/\/cdn.veryfi.com\/logos\/us\/218078496.jpeg","logo_name":"walmart","address":"600 SHOWERS DR\nMOUNTAIN VIEW CA 94040\nTR#\nTE#\nOP#"},"pdf_url":"https:\/\/scdn.veryfi.com\/receipts\/a1c6bdc6fd6aa87b\/c54e174e-051c-4fbe-8d23-9ce22a1f6d18\/50f12835-8c90-4e6f-9e1d-cb2beb115c14.pdf?Expires=1754964211&Signature=SxCEMd~FWMCSMf3I0cwvptq8PzewiVwKC7tqE6ZFsA4Y5KsfUcMED4gW~o8Acy9R6Wpz7gJ4OBm9atpTklpVO8GKpv~KDWHEBe1JvKJqaIJlz-v2lBc8-IV7luQ1BpmKf02TqLiRJh6jPQBPQKntR-CimpLe-KWx6Q5zfaoijSwdQPU-ptqVY909bL-gVsgW0aIjnm4dRgX5JFKTmkh1uNp~PCsVP9E9oojuMlIHUtQUV~bndtLkg1yetknEyWdt8UWa8TlRn4VEhyx22dAP5Q96anBLWqVS8AgZdEKdsr0MBn1TnPe2YQ3yKjI1iSxGlXsquNxs~IwLmg6ySgiAuQ__&Key-Pair-Id=APKAJCILBXEJFZF4DCHQ","img_url":"https:\/\/scdn.veryfi.com\/receipts\/a1c6bdc6fd6aa87b\/c54e174e-051c-4fbe-8d23-9ce22a1f6d18\/74025bbc-333e-40b9-be4b-f1e22a89c031.jpg?Expires=1754964211&Signature=PPzCOpX8NQOxdrKzXPc4XZ0YqlpDDt029BQAWQzkoaPidLkyLpzZycWSIJ8XgrNahfXNgDNZwrM5wlRLPZ0c7nv5aUV4BX9y-NLBeBGy-gOc6pvXnGmnfBoQn8DCooXuiVlKZdTj9W-wlgnWW5hJYCO4qxZpRfZoOtNRubAJyjOvRPHHsUtj0ThqmyZnOwLJEwQ7SCSGa8NJcFtWma~iNZajUm67bdip1vvNpx~rRBktclQFOzFhCc11l2FuN9aEDe6jd6Zx-BPRqdmr8uqP60sOYMZSZNPY3Tolot7AfB5eQ6YwvDyFZxnJ5ObgP94Msu4AJxIvqkzf24OP7JkrwQ__&Key-Pair-Id=APKAJCILBXEJFZF4DCHQ","model":"2.71.0","document_type":"receipt","tax":0.24,"vending_person_number":"009009","ocr_text":"Give us feedback @ survey.walmart.com\nThank you! ID #:7SHKC5SPH95\nWalmart >\n650-917-0796 Mgr:RENARDO\n600 SHOWERS DR\nMOUNTAIN VIEW CA 94040\nST# 02280 OP# 009009 TE# 09 TR# 04814\nLAYS\t002840020129 F\t3.68 N\nPEPSI\t001200003066 F\t2.48 X\nCRV FEE\t068113176540 F\t0.10 X\nCKOUT BAGTAX 000000001101K\t0.10 0\n\tSUBTOTAL\t6.36\nTAX 1 9.125 %\t0.24\n\tTOTAL\t6.60\nVISA TEND\t6.60\nVISA CREDIT **** **** **** 0115 I O\nAPPROVAL # 905081\nREF # 1042000314\nTRANS ID - 303081090537310\nVALIDATION - 255L\nPAYMENT SERVICE - E\nAID A0000000031010\nAAC 350129A87930283E\nTERMINAL # SC010046\n*NO SIGNATURE REQUIRED\n03\/21\/23\t19:31:00\nCHANGE DUE\t0.00\n# ITEMS SOLD 4\nTC# 5223 1066 2522 3267 4171\n\nWalmart+\nBecome a member 1\nScan for free 30-day trial\nLow Prices You Can Trust. Every Day.\n03\/21\/23 19:31:00\n***CUSTOMER COPY***","default_category":"Job Supplies","is_document":true,"is_blurry":[],"exch_rate":1,"is_duplicate":true,"category":"Supplies","meta":{"owner":"usename.001","pages":[{"language":["en"],"screenshot":{"score":0.92,"type":null},"height":3821,"is_blurry":{"score":0.9713826952327509,"value":false},"width":1838}],"processed_pages":1,"device_id":"093B9C56-D1FA-4965-B005-EEA03F379900","device_user_uuid":null,"source":"lens.receipt","language":["en"],"source_documents":[{"width":1838,"height":3821,"size_kb":2184}],"ocr_score":0.971,"total_pages":1},"document_reference_number":"5223 1066 2522 3267 4171","created_date":"2025-08-12 01:48:25","line_items":[{"id":1557156984,"category":"Supplies","text":"LAYS\t002840020129 F\t3.68 N","description":"LAYS","type":"food","full_description":"LAYS","sku":"002840020129","quantity":1,"order":0,"total":3.68,"tags":[]}],"tags":[],"ship_to":{"address":null,"name":null,"parsed_address":null},"total_weight":null,"barcodes":[{"type":"QRCODE","data":"http:\/\/walmart.com\/plusgiftcard"},{"type":"CODE39","data":"GCTTIOQI$+8FN 2S"}],"total_quantity":4,"duplicate_of":258263850,"guest_count":null,"is_transaction":false,"tax_lines":[{"base":null,"rate":9.125,"order":0,"code":"1","total_inclusive":null,"total":0.24,"name":null}],"vending_person":"RENARDO","img_thumbnail_url":"https:\/\/scdn.veryfi.com\/receipts\/a1c6bdc6fd6aa87b\/c54e174e-051c-4fbe-8d23-9ce22a1f6d18\/thumbnail.jpg?Expires=1754964211&Signature=Ah~Ey~w8QG7eyr1zfrGcTd5Mu6bQDdm~W45g9fSYzRHKQLFy5yVJjcXH589zLaF7dTP3c5qAk4y28ZvkqpUG4ztylk2W5XTiik~82kWOm1z71nBs2qa5q~e2-aHV4bb9iU9xL8ZlmIuiBHwvZ7SUSteHmBShmlIY758CTjowiQ9t6lx1bmrcNxl5HwRq6bA7iQkxBwGWAYzJ~r3AwdNktfr57iZpYiBt5p69vMIYRArTrWAgH7yMlubMOAuyuwSZ98E7r5v5K9KmNy1RXX6ZiUVRMsvPcEHyPQAKIVF2R4g9Dzt6Q5O4VCJ-jt~Q-ZxF4j69gBUvhDALXtFPxt2rVg__&Key-Pair-Id=APKAJCILBXEJFZF4DCHQ","is_money_in":false,"img_blur":false,"is_approved":false,"status":"processed","img_file_name":"339981080.jpg","updated_date":"2025-08-12 01:48:31","store_number":"02280"},
"document_type": "receipt",
"package_id": "fScdb8nKkXprWL7MCvUn",
"status": "done",
"device_id": "093B9C56-D1FA-4965-B005-EEA03F379900",
"is_emulator": true
}

Dictated data example:

{
"package_id": "edc8653e4c2b4ef1",
"data": {"account_number": "", "bill_to": {"address": "", "name": "",}, "card_number": "", "category": "Meals & Entertainment", "created_date": "2021-01-14 05: 19: 51", "currency_code": "USD", "date": "2021-01-14 05: 19: 51", "delivery_date": "", "discount": 0, "due_date": "", "external_id": "", "id": 31428417, "img_file_name": "xxxxxxxxx.png", "img_thumbnail_url": "https: \/\/cdn.veryfi.com\/partner-receipts\/xxxxxxxxx_t.png", "img_url": "https: \/\/cdn.veryfi.com\/partner-receipts\/xxxxxxxxx.png", "incoterms": "", "insurance": "", "invoice_number": "", "line_items": [], "notes": "", "ocr_text": "starbucks 23.4", "order_date": "", "payment": {"card_number": "", "display_name": "No Payment,", "type": "no_payment,"}, "phone_number": "", "purchase_order_number": "", "reference_number": "VBDEC-0000", "service_end_date": "", "service_start_date": "", "ship_date": "", "shipping": 0, "subtotal": 23.4, "tags": [], "tax": 0, "tip": 0, "total": 23.4, "total_weight": "", "vendor": {"abn_number": "", "address": "", "fax_number": "", "logo": "https: \/\/cdn.veryfi.com\/logos\/us\/910419611.png", "name": "Starbucks", "phone_number": "", "raw_name": "Starbucks", "type": "", "vat_number": ""}},
"type":"dictation"
}
  • (Optional) onHelpButtonClicked - triggered when the user taps the help button in the camera interface. This delegate method provides a presentingViewController parameter that you can use to present your custom help UI on top of the camera. You are responsible for handling the presentation and dismissal of your custom view. The help button can be enabled using the showHelpButton setting.

Example implementation:
func onHelpButtonClicked(_ presentingViewController: UIViewController) {

let viewController = UIViewController() // Reference your custom UIViewController in here, by it a Storyboard, xib, programatic or SwiftUI UIHostingController

presentingViewController.present(viewController, animated: true)
}