Skip to content

Commit

Permalink
LP-958: Add W8BenE and w9 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Poveda committed Oct 25, 2024
1 parent de1771d commit 5c7e0f7
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 7 deletions.
19 changes: 19 additions & 0 deletions Sources/VeryfiSDK/Client/GetW8BenE.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GetW8BenE.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Get single w8BenE document by ID from Veryfi inbox.
/// - Parameters:
/// - documentId: ID of document to retreive
/// - completion: Block executed after request.
/// - detail: Response from server.
/// - error: Error from server.
public func getW8BenE(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
self.request(method: .GET, route: .w8BenE, queryItem: documentId, completion: completion)
}
}
19 changes: 19 additions & 0 deletions Sources/VeryfiSDK/Client/GetW8BenEs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GetW8BenEs.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Get all w8BenE documents from Veryfi inbox.
/// - Parameters:
/// - queryItems: Query items to apply to the get request.
/// - completion: Block executed after request.
/// - detail: Response from server.
/// - error: Error from server.
public func getW8BenEs(queryItems: [URLQueryItem]? = nil, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
self.request(method: .GET, route: .w8BenE, queryItems: queryItems, completion: completion)
}
}
19 changes: 19 additions & 0 deletions Sources/VeryfiSDK/Client/GetW9.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GetW9.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Get single w9 document by ID from Veryfi inbox.
/// - Parameters:
/// - documentId: ID of document to retreive
/// - completion: Block executed after request.
/// - detail: Response from server.
/// - error: Error from server.
public func getW9(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
self.request(method: .GET, route: .w9s, queryItem: documentId, completion: completion)
}
}
19 changes: 19 additions & 0 deletions Sources/VeryfiSDK/Client/GetW9s.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GetW9s.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Get all w9 documents from Veryfi inbox.
/// - Parameters:
/// - queryItems: Query items to apply to the get request.
/// - completion: Block executed after request.
/// - detail: Response from server.
/// - error: Error from server.
public func getW9s(queryItems: [URLQueryItem]? = nil, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
self.request(method: .GET, route: .w9s, queryItems: queryItems, completion: completion)
}
}
2 changes: 0 additions & 2 deletions Sources/VeryfiSDK/Client/ProcessW2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ extension Client {
/// - Parameters:
/// - fileName: Name of the file to upload to the Veryfi API.
/// - fileData: UTF8 encoded file data
/// - categories: List of document categories.
/// - deleteAfterProcessing: Do not store file in Veryfi's inbox.
/// - params: Additional parameters.
/// - completion: Function called after request completes.
/// - detail: Response from server.
Expand Down
5 changes: 0 additions & 5 deletions Sources/VeryfiSDK/Client/ProcessW2Url.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ extension Client {
/// - Parameters:
/// - fileUrl: Publicly available URL.
/// - fileUrls: List of publicly available URLs.
/// - categories: List of document categories.
/// - deleteAfterProcessing: Do not store file in Veryfi's inbox.
/// - boostMode: Skip data enrichment but process document faster.
/// - externalId: Existing ID to assign to document.
/// - maxPagesToProcess: Number of pages to process.
/// - completion: Block executed after request.
/// - detail: Response from server.
/// - error: Error from server.
Expand Down
33 changes: 33 additions & 0 deletions Sources/VeryfiSDK/Client/ProcessW8BenE.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ProcessW8BenE.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Upload a w8BenE image for the Veryfi API to process.
/// - Parameters:
/// - fileName: Name of the file to upload to the Veryfi API.
/// - fileData: UTF8 encoded file data
/// - params: Additional parameters.
/// - completion: Function called after request completes.
/// - detail: Response from server.
/// - error: Error from server.
public func processW8BenE(fileName: String,
fileData: Data,
params: [String: Any]? = nil,
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
var requestParams = params ?? [String: Any]()
requestParams["file_data"] = fileData.base64EncodedString()
requestParams["file_name"] = fileName

guard let jsonData = try? JSONSerialization.data(withJSONObject: requestParams, options: .prettyPrinted) else {
completion(.failure(.parsingError))
return
}

self.request(method: .POST, route: .w8BenE, uploadData: jsonData, completion: completion)
}
}
27 changes: 27 additions & 0 deletions Sources/VeryfiSDK/Client/ProcessW8BenEUrl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ProcessW8BenEUrl.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Upload w8BenE document to Veryfi API with URL.
/// - Parameters:
/// - fileUrl: Publicly available URL.
/// - fileUrls: List of publicly available URLs.
/// - completion: Block executed after request.
/// - detail: Response from server.
/// - error: Error from server.
public func processW8BenEURL(fileUrl: String? = nil,
fileUrls: [String]? = nil,
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
let params: [String: Any] = [
"file_url": fileUrl as Any, //implicit coerce
"file_urls": fileUrls as Any, //implicit coerce
] //implicit coerce
let jsonData = try? JSONSerialization.data(withJSONObject: params)
self.request(method: .POST, route: .w8BenE, body: jsonData, completion: completion)
}
}
33 changes: 33 additions & 0 deletions Sources/VeryfiSDK/Client/ProcessW9.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ProcessW9.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Upload a w9 image for the Veryfi API to process.
/// - Parameters:
/// - fileName: Name of the file to upload to the Veryfi API.
/// - fileData: UTF8 encoded file data
/// - params: Additional parameters.
/// - completion: Function called after request completes.
/// - detail: Response from server.
/// - error: Error from server.
public func processW9(fileName: String,
fileData: Data,
params: [String: Any]? = nil,
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
var requestParams = params ?? [String: Any]()
requestParams["file_data"] = fileData.base64EncodedString()
requestParams["file_name"] = fileName

guard let jsonData = try? JSONSerialization.data(withJSONObject: requestParams, options: .prettyPrinted) else {
completion(.failure(.parsingError))
return
}

self.request(method: .POST, route: .w9s, uploadData: jsonData, completion: completion)
}
}
27 changes: 27 additions & 0 deletions Sources/VeryfiSDK/Client/ProcessW9Url.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ProcessW9Url.swift
// VeryfiSDK
//
// Created by Veryfi on 25/10/24.
//
import Foundation

extension Client {
/// Upload w9 document to Veryfi API with URL.
/// - Parameters:
/// - fileUrl: Publicly available URL.
/// - fileUrls: List of publicly available URLs.
/// - completion: Block executed after request.
/// - detail: Response from server.
/// - error: Error from server.
public func processW9URL(fileUrl: String? = nil,
fileUrls: [String]? = nil,
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
let params: [String: Any] = [
"file_url": fileUrl as Any, //implicit coerce
"file_urls": fileUrls as Any, //implicit coerce
] //implicit coerce
let jsonData = try? JSONSerialization.data(withJSONObject: params)
self.request(method: .POST, route: .w9s, body: jsonData, completion: completion)
}
}
2 changes: 2 additions & 0 deletions Sources/VeryfiSDK/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum Endpoint: String {
case anyDocuments = "/partner/any-documents/"
case bankStatements = "/partner/bank-statements/"
case w2s = "/partner/w2s/"
case w9s = "/partner/w9s/"
case w8BenE = "/partner/w-8ben-e/"
}

public class NetworkManager {
Expand Down

0 comments on commit 5c7e0f7

Please sign in to comment.