Skip to content

Commit

Permalink
Merge branch 'IPC-167_remove_requirements_check_health_sdk' into IPC-…
Browse files Browse the repository at this point in the history
…153_payment_review_screen
  • Loading branch information
razvancapra committed Mar 19, 2024
2 parents d522d4d + 8ed475b commit 86ec1c3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 122 deletions.
4 changes: 1 addition & 3 deletions HealthSDK/GiniHealthSDK/Documentation/source/Integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ let partialDocs = [PartialDocumentInfo(document: createdDocument.links.document)

## Check preconditions

There are three methods in GiniHealth:
There is one method in GiniHealth:

* `healthSDK.isAnyBankingAppInstalled(appSchemes: [String])` without a networking call, returns true when at least the one of the listed among `LSApplicationQueriesSchemes` in your `Info.plist` is installed on the device and can support Gini Pay functionality,
* `healthSDK.checkIfAnyPaymentProviderAvailable()` with a networking call, returns a list of availible payment provider or informs that there are no supported banking apps installed,
* `healthSDK.checkIfDocumentIsPayable(docId: String)` returns true if Iban was extracted.

## Fetching data for payment review screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,6 @@ public struct DataForReview {
}
}
}

/**
Checks if there are any banking app which support Gini Pay Connect functionality installed.

- Parameters:
- completion: An action for processing asynchronous data received from the service with Result type as a paramater. Result is a value that represents either a success or a failure, including an associated value in each case. Completion block called on main thread.
In success case it includes array of payment providers.
In case of failure error that there are no supported banking apps installed.
*/
public func checkIfAnyPaymentProviderAvailable(completion: @escaping (Result<PaymentProviders, GiniHealthError>) -> Void){
self.fetchInstalledBankingApps(completion: completion)
}

/**
Checks if there is any banking app which can support Gini Pay Connect functionality installed.
- Parameters:
- appSchemes: A list of [LSApplicationQueriesSchemes] added in Info.plist. Scheme format: ginipay-bank://
- Returns: a boolean value.
*/
public func isAnyBankingAppInstalled(appSchemes: [String]) -> Bool {
for scheme in appSchemes {
if let url = URL(string:scheme) {
if UIApplication.shared.canOpenURL(url) {
return true
}
}
}
return false
}

/**
Sets a configuration which is used to customize the look of the Gini Health SDK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ final class AppCoordinator: Coordinator {
self.window.makeKeyAndVisible()
}


fileprivate func showScreenAPI(with pages: [GiniCapturePage]? = nil) {
let metadata = GiniHealthAPILibrary.Document.Metadata(branchId: documentMetadataBranchId,
additionalHeaders: [documentMetadataAppFlowKey: "ScreenAPI"])
Expand All @@ -135,24 +134,6 @@ final class AppCoordinator: Coordinator {
private var testDocument: GiniHealthAPILibrary.Document?
private var testDocumentExtractions: [GiniHealthAPILibrary.Extraction]?

fileprivate func checkIfAnyBankingAppsInstalled(from viewController: UIViewController, completion: @escaping () -> Void) {
health.checkIfAnyPaymentProviderAvailable { result in
switch(result) {
case .success(_):
completion()
case .failure(_):
let alertViewController = UIAlertController(title: "",
message: "We didn't find any banking apps installed",
preferredStyle: .alert)

alertViewController.addAction(UIAlertAction(title: "OK", style: .default) { _ in
alertViewController.dismiss(animated: true)
})
viewController.present(alertViewController, animated: true)
}
}
}

fileprivate func showPaymentReviewWithTestDocument() {
let configuration = GiniHealthConfiguration()

Expand All @@ -162,73 +143,81 @@ final class AppCoordinator: Coordinator {

health.delegate = self
health.setConfiguration(configuration)

checkIfAnyBankingAppsInstalled(from: self.rootViewController) {
if let document = self.testDocument {
self.selectAPIViewController.showActivityIndicator()

self.health.fetchDataForReview(documentId: document.id) { result in
switch result {
case .success(let data):
let vc = PaymentReviewViewController.instantiate(with: self.health,
data: data,
selectedPaymentProvider: self.paymentComponentsController.selectedPaymentProvider,
trackingDelegate: self)
vc.modalPresentationStyle = .overCurrentContext
vc.modalTransitionStyle = .coverVertical
self.rootViewController.present(vc, animated: true)
case .failure(let error):
print("❌ Document data fetching failed: \(String(describing: error))")
}

if let document = self.testDocument {
self.selectAPIViewController.showActivityIndicator()

self.health.fetchDataForReview(documentId: document.id) { result in
switch result {
case .success(let data):
self.health.checkIfDocumentIsPayable(docId: document.id, completion: { [weak self] resultPayable in
switch resultPayable {
case .success(let isPayable):
let invoice = DocumentWithExtractions(documentID: document.id,
extractions: data.extractions,
isPayable: isPayable)
self?.showInvoicesList(invoices: [invoice])
case .failure(let error):
print("❌ Checking if document is payable failed: \(String(describing: error))")
}
self?.selectAPIViewController.hideActivityIndicator()
})
case .failure(let error):
print("❌ Document data fetching failed: \(String(describing: error))")
self.selectAPIViewController.hideActivityIndicator()
}
} else {
// Upload the test document image
let testDocumentImage = UIImage(named: "testDocument")!
let testDocumentData = testDocumentImage.jpegData(compressionQuality: 1)!

self.selectAPIViewController.showActivityIndicator()

self.health.documentService.createDocument(fileName: nil,
docType: nil,
type: .partial(testDocumentData),
metadata: nil) { result in
switch result {
case .success(let createdDocument):
let partialDocInfo = GiniHealthAPILibrary.PartialDocumentInfo(document: createdDocument.links.document)
self.health.documentService.createDocument(fileName: nil,
docType: nil,
type: .composite(CompositeDocumentInfo(partialDocuments: [partialDocInfo])),
metadata: nil) { result in
switch result {
case .success(let compositeDocument):
self.health.setDocumentForReview(documentId: compositeDocument.id) { result in
switch result {
case .success(let extractions):
self.testDocument = compositeDocument
self.testDocumentExtractions = extractions

// Show the payment review screen
let vc = PaymentReviewViewController.instantiate(with: self.health,
document: compositeDocument,
extractions: extractions,
selectedPaymentProvider: self.paymentComponentsController.selectedPaymentProvider,
trackingDelegate: self)
self.rootViewController.present(vc, animated: true)
case .failure(let error):
print("❌ Setting document for review failed: \(String(describing: error))")
}
}
} else {
// Upload the test document image
let testDocumentImage = UIImage(named: "testDocument")!
let testDocumentData = testDocumentImage.jpegData(compressionQuality: 1)!

self.selectAPIViewController.showActivityIndicator()

self.health.documentService.createDocument(fileName: nil,
docType: nil,
type: .partial(testDocumentData),
metadata: nil) { result in
switch result {
case .success(let createdDocument):
let partialDocInfo = GiniHealthAPILibrary.PartialDocumentInfo(document: createdDocument.links.document)
self.health.documentService.createDocument(fileName: nil,
docType: nil,
type: .composite(CompositeDocumentInfo(partialDocuments: [partialDocInfo])),
metadata: nil) { result in
switch result {
case .success(let compositeDocument):
self.health.setDocumentForReview(documentId: compositeDocument.id) { result in
switch result {
case .success(let extractions):
self.testDocument = compositeDocument
self.testDocumentExtractions = extractions

self.health.checkIfDocumentIsPayable(docId: compositeDocument.id, completion: { [weak self] resultPayable in
switch resultPayable {
case .success(let isPayable):
let invoice = DocumentWithExtractions(documentID: compositeDocument.id,
extractions: extractions,
isPayable: isPayable)
self?.showInvoicesList(invoices: [invoice])
case .failure(let error):
print("❌ Checking if document is payable failed: \(String(describing: error))")
}
self?.selectAPIViewController.hideActivityIndicator()
})
case .failure(let error):
print("❌ Setting document for review failed: \(String(describing: error))")
self.selectAPIViewController.hideActivityIndicator()
}
case .failure(let error):
print("❌ Document creation failed: \(String(describing: error))")
self.selectAPIViewController.hideActivityIndicator()
}
case .failure(let error):
print("❌ Document creation failed: \(String(describing: error))")
self.selectAPIViewController.hideActivityIndicator()
}
case .failure(let error):
print("❌ Document creation failed: \(String(describing: error))")
self.selectAPIViewController.hideActivityIndicator()
}
case .failure(let error):
print("❌ Document creation failed: \(String(describing: error))")
self.selectAPIViewController.hideActivityIndicator()
}
}
}
Expand Down Expand Up @@ -278,7 +267,7 @@ final class AppCoordinator: Coordinator {
}
}

fileprivate func showInvoicesList() {
fileprivate func showInvoicesList(invoices: [DocumentWithExtractions]? = nil) {
self.selectAPIViewController.hideActivityIndicator()
let configuration = GiniHealthConfiguration()

Expand All @@ -292,7 +281,8 @@ final class AppCoordinator: Coordinator {
paymentComponentsController = PaymentComponentsController(giniHealth: health)
invoicesListCoordinator.start(documentService: health.documentService,
hardcodedInvoicesController: HardcodedInvoicesController(),
paymentComponentsController: paymentComponentsController)
paymentComponentsController: paymentComponentsController,
invoices: invoices)
add(childCoordinator: invoicesListCoordinator)
rootViewController.present(invoicesListCoordinator.rootViewController, animated: true)
}
Expand Down Expand Up @@ -322,6 +312,10 @@ extension AppCoordinator: ScreenAPICoordinatorDelegate {
coordinator.rootViewController.dismiss(animated: true)
self.remove(childCoordinator: coordinator)
}

func presentInvoicesList(invoices: [DocumentWithExtractions]?) {
self.showInvoicesList(invoices: invoices)
}
}

// MARK: GiniHealthDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ final class InvoicesListCoordinator: NSObject, Coordinator {

func start(documentService: DefaultDocumentService,
hardcodedInvoicesController: HardcodedInvoicesControllerProtocol,
paymentComponentsController: PaymentComponentsController) {
paymentComponentsController: PaymentComponentsController,
invoices: [DocumentWithExtractions]? = nil) {
self.invoicesListViewController = InvoicesListViewController()
invoicesListViewController.viewModel = InvoicesListViewModel(coordinator: self,
invoices: invoices,
documentService: documentService,
hardcodedInvoicesController: hardcodedInvoicesController,
paymentComponentsController: paymentComponentsController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import UIKit

protocol ScreenAPICoordinatorDelegate: AnyObject {
func screenAPI(coordinator: ScreenAPICoordinator, didFinish: ())
func presentInvoicesList(invoices: [DocumentWithExtractions]?)
}

final class ScreenAPICoordinator: NSObject, Coordinator, GiniHealthTrackingDelegate, GiniCaptureResultsDelegate {
Expand Down Expand Up @@ -97,18 +98,13 @@ final class ScreenAPICoordinator: NSObject, Coordinator, GiniHealthTrackingDeleg
extractions: data.extractions,
isPayable: isPayable)
self?.hardcodedInvoicesController.appendInvoiceWithExtractions(invoice: invoice)

self?.rootViewController.dismiss(animated: true, completion: {
self?.delegate?.presentInvoicesList(invoices: [invoice])
})
case .failure(let error):
print("❌ Checking if document is payable failed: \(String(describing: error))")
}
})
let vc = PaymentReviewViewController.instantiate(with: healthSdk,
data: data,
selectedPaymentProvider: self?.paymentComponentController.selectedPaymentProvider,
trackingDelegate: self)
vc.modalTransitionStyle = .coverVertical
vc.modalPresentationStyle = .overCurrentContext
self?.rootViewController.present(vc, animated: true)
case .failure(let error):
print("❌ Document data fetching failed: \(String(describing: error))")
}
Expand Down

0 comments on commit 86ec1c3

Please sign in to comment.