From f95a783239b2683d38825ed46f9cff10d8483d5f Mon Sep 17 00:00:00 2001 From: Mauro Restuccia Date: Wed, 10 May 2023 11:14:49 -0400 Subject: [PATCH] fix: Added missing properties to create entities --- .../ContentView.swift | 10 +-- .../Model/Journeys/Request/Entity.swift | 88 ++++++++++++++++++- 2 files changed, 90 insertions(+), 8 deletions(-) diff --git a/Example/AlloyCodelessLiteiOSDemo/ContentView.swift b/Example/AlloyCodelessLiteiOSDemo/ContentView.swift index 355cd83..2be81bf 100644 --- a/Example/AlloyCodelessLiteiOSDemo/ContentView.swift +++ b/Example/AlloyCodelessLiteiOSDemo/ContentView.swift @@ -34,7 +34,7 @@ struct ContentView: View { // *** this key is part of a working example *** // You should obtain your key from the alloy dashboard // On settings > SDK Config - apiKey: "7db38092-3df1-4e56-8d01-3a92478485ba", + apiKey: "9ca83767-f213-4aaf-bc1b-1ed0a89eaf23", production: false, realProduction: true, codelessFinalValidation: false @@ -68,13 +68,13 @@ struct ContentView: View { resumeJourney.toggle() // We are creating 2 entities for the journey application using only first and last name. // The Entity data needed will vary depending on the services associated to your workflows. - let entityDataPerson = Entity.EntityData(nameFirst: "John", nameLast: "Doe") - let entityDataPerson2 = Entity.EntityData(nameFirst: "Julie", nameLast: "Tam") + let entityDataPerson = Entity.EntityData(nameFirst: "John", nameLast: "Doe", phoneNumber: "5555555555", emailAddress: "test@test.com", documentSsn: "111111112") + let entityDataPerson2 = Entity.EntityData(nameFirst: "Julie", nameLast: "Tam", addressCountryCode: "US", documentSsn: "111111111") // We add the entity data to an entity structure. Entity type can be person or business // The branch name needs to match the branch names on your journey. // If you only have one branch, you don't need to pass a branch name. - let entityPerson = Entity(entityData: entityDataPerson, entityType: "person", branchName: "vouched") - let entityPerson2 = Entity(entityData: entityDataPerson2, entityType: "person", branchName: "veriff") + let entityPerson = Entity(entityData: entityDataPerson, entityType: "person", branchName: "vouched", externalEntityId: "EX-1234x") + let entityPerson2 = Entity(entityData: entityDataPerson2, entityType: "person", branchName: "veriff", externalEntityId: "EX-5678x") let entities = EntityData(entities: [entityPerson, entityPerson2], additionalEntities: false) // *** this key is part of a working example *** diff --git a/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/Model/Journeys/Request/Entity.swift b/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/Model/Journeys/Request/Entity.swift index 3fe9f29..63cb3b7 100644 --- a/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/Model/Journeys/Request/Entity.swift +++ b/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/Model/Journeys/Request/Entity.swift @@ -11,32 +11,110 @@ public struct Entity: Codable { public struct EntityData: Codable { public let nameFirst: String public let nameLast: String + public let nameMiddle: String? + public let phoneNumber: String? + public let emailAddress: String? + public let addressLine1: String? + public let addressLine2: String? + public let addressCity: String? + public let addressState: String? + public let addressPostalCode: String? + public let addressCountryCode: String? + public let birthDate: String? + public let documentSsn: String? + public let documentIdCard: String? + public let documentLicense: String? + public let documentPassport: String? + public let gender: String? // MARK: CodingKeys public enum CodingKeys: String, CodingKey { case nameFirst = "name_first" case nameLast = "name_last" + case nameMiddle = "name_middle" + case phoneNumber = "phone_number" + case emailAddress = "email_address" + case addressLine1 = "address_line_1" + case addressLine2 = "address_line_2" + case addressCity = "address_city" + case addressState = "address_state" + case addressPostalCode = "address_postal_code" + case addressCountryCode = "address_country_code" + case birthDate = "birth_date" + case documentSsn = "document_ssn" + case documentIdCard = "document_id_card" + case documentLicense = "document_license" + case documentPassport = "document_passport" + case gender = "gender" } // MARK: Initializers - public init(nameFirst: String, nameLast: String) { + public init( + nameFirst: String, + nameLast: String, + nameMiddle: String? = nil, + phoneNumber: String? = nil, + emailAddress: String? = nil, + addressLine1: String? = nil, + addressLine2: String? = nil, + addressCity: String? = nil, + addressState: String? = nil, + addressPostalCode: String? = nil, + addressCountryCode: String? = nil, + birthDate: String? = nil, + documentSsn: String? = nil, + documentIdCard: String? = nil, + documentLicense: String? = nil, + documentPassport: String? = nil, + gender: String? = nil) { self.nameFirst = nameFirst self.nameLast = nameLast + self.nameMiddle = nameMiddle + self.phoneNumber = phoneNumber + self.emailAddress = emailAddress + self.addressLine1 = addressLine1 + self.addressLine2 = addressLine2 + self.addressCity = addressCity + self.addressState = addressState + self.addressPostalCode = addressPostalCode + self.addressCountryCode = addressCountryCode + self.birthDate = birthDate + self.documentSsn = documentSsn + self.documentIdCard = documentIdCard + self.documentLicense = documentLicense + self.documentPassport = documentPassport + self.gender = gender } public init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) - nameFirst = try values.decode(String.self, forKey: .nameFirst) nameLast = try values.decode(String.self, forKey: .nameLast) + nameMiddle = try values.decodeIfPresent(String.self, forKey: .nameMiddle) + phoneNumber = try values.decodeIfPresent(String.self, forKey: .phoneNumber) + emailAddress = try values.decodeIfPresent(String.self, forKey: .emailAddress) + addressLine1 = try values.decodeIfPresent(String.self, forKey: .addressLine1) + addressLine2 = try values.decodeIfPresent(String.self, forKey: .addressLine2) + addressCity = try values.decodeIfPresent(String.self, forKey: .addressCity) + addressState = try values.decodeIfPresent(String.self, forKey: .addressState) + addressPostalCode = try values.decodeIfPresent(String.self, forKey: .addressPostalCode) + addressCountryCode = try values.decodeIfPresent(String.self, forKey: .addressCountryCode) + birthDate = try values.decodeIfPresent(String.self, forKey: .birthDate) + documentSsn = try values.decodeIfPresent(String.self, forKey: .documentSsn) + documentIdCard = try values.decodeIfPresent(String.self, forKey: .documentIdCard) + documentLicense = try values.decodeIfPresent(String.self, forKey: .documentLicense) + documentPassport = try values.decodeIfPresent(String.self, forKey: .documentPassport) + gender = try values.decodeIfPresent(String.self, forKey: .gender) } } let entityData: EntityData let entityType: String let branchName: String + let externalEntityId: String? + // MARK: CodingKeys @@ -44,14 +122,16 @@ public struct Entity: Codable { case entityData = "data" case entityType = "entity_type" case branchName = "branch_name" + case externalEntityId = "external_entity_id" } // MARK: Initializers - public init(entityData: EntityData, entityType: String, branchName: String) { + public init(entityData: EntityData, entityType: String, branchName: String, externalEntityId: String? = nil) { self.entityData = entityData self.entityType = entityType self.branchName = branchName + self.externalEntityId = externalEntityId } public init(from decoder: Decoder) throws { @@ -60,6 +140,7 @@ public struct Entity: Codable { entityData = try values.decode(EntityData.self, forKey: .entityData) entityType = try values.decode(String.self, forKey: .entityType) branchName = try values.decode(String.self, forKey: .branchName) + externalEntityId = try values.decodeIfPresent(String.self, forKey: .externalEntityId) } public func encode(to encoder: Encoder) throws { @@ -69,6 +150,7 @@ public struct Entity: Codable { try container.encode(entityData, forKey: .entityData) try container.encode(entityType, forKey: .entityType) try container.encode(branchName, forKey: .branchName) + try container.encodeIfPresent(externalEntityId, forKey: .externalEntityId) } }