From 6bb01ce67255d2983ebd08edeba49c2fc51a9554 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Thu, 24 Jan 2019 18:24:33 -0500 Subject: [PATCH] Updated legal entity to be created from dictionary instead of the actual concrete type. The concrete type was what stripe would send back after an account creation or update. The type can't be responsible for creating a new one because some fields to create it aren't returned by stripe like last 4 ssn. --- Sources/Stripe/API/Routes/AccountRoutes.swift | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Sources/Stripe/API/Routes/AccountRoutes.swift b/Sources/Stripe/API/Routes/AccountRoutes.swift index 6e0c2b3..0dac1b1 100644 --- a/Sources/Stripe/API/Routes/AccountRoutes.swift +++ b/Sources/Stripe/API/Routes/AccountRoutes.swift @@ -9,9 +9,9 @@ import Vapor public protocol AccountRoutes { - func create(type: ConnectedAccountType, email: String?, country: String?, accountToken: String?, businessLogo: String?, businessName: String?, businessPrimaryColor: String?, businessUrl: String?, debitNegativeBalances: Bool?, declineChargeOn: [String: Bool]?, defaultCurrency: StripeCurrency?, externalAccount: Any?, legalEntity: StripeConnectAccountLegalEntity?, metadata: [String: String]?, payoutSchedule: [String: String]?, payoutStatementDescriptor: String?, productDescription: String?, statementDescriptor: String?, supportEmail: String?, supportPhone: String?, supportUrl: String?, tosAcceptance: StripeTOSAcceptance?) throws -> Future + func create(type: ConnectedAccountType, email: String?, country: String?, accountToken: String?, businessLogo: String?, businessName: String?, businessPrimaryColor: String?, businessUrl: String?, debitNegativeBalances: Bool?, declineChargeOn: [String: Bool]?, defaultCurrency: StripeCurrency?, externalAccount: Any?, legalEntity: [String: Any]?, metadata: [String: String]?, payoutSchedule: [String: String]?, payoutStatementDescriptor: String?, productDescription: String?, statementDescriptor: String?, supportEmail: String?, supportPhone: String?, supportUrl: String?, tosAcceptance: StripeTOSAcceptance?) throws -> Future func retrieve(account: String) throws -> Future - func update(account: String, businessName: String?, businessPrimaryColor: String?, businessUrl: String?, debitNegativeBalances: Bool?, declineChargeOn: [String: Bool]?, defaultCurrency: StripeCurrency?, email: String?, externalAccount: Any?, legalEntity: StripeConnectAccountLegalEntity?, metadata: [String: String]?, payoutSchedule: [String: String]?, payoutStatementDescriptor: String?, productDescription: String?, statementDescriptor: String?, supportEmail: String?, supportPhone: String?, supportUrl: String?, tosAcceptance: StripeTOSAcceptance?) throws -> Future + func update(account: String, businessName: String?, businessPrimaryColor: String?, businessUrl: String?, debitNegativeBalances: Bool?, declineChargeOn: [String: Bool]?, defaultCurrency: StripeCurrency?, email: String?, externalAccount: Any?, legalEntity: [String: Any]?, metadata: [String: String]?, payoutSchedule: [String: String]?, payoutStatementDescriptor: String?, productDescription: String?, statementDescriptor: String?, supportEmail: String?, supportPhone: String?, supportUrl: String?, tosAcceptance: StripeTOSAcceptance?) throws -> Future func delete(account: String) throws -> Future func reject(account: String, for: AccountRejectReason) throws -> Future func listAll(filter: [String: Any]?) throws -> Future @@ -31,7 +31,7 @@ extension AccountRoutes { declineChargeOn: [String: Bool]? = nil, defaultCurrency: StripeCurrency? = nil, externalAccount: Any? = nil, - legalEntity: StripeConnectAccountLegalEntity? = nil, + legalEntity: [String: Any]? = nil, metadata: [String: String]? = nil, payoutSchedule: [String: String]? = nil, payoutStatementDescriptor: String? = nil, @@ -78,7 +78,7 @@ extension AccountRoutes { defaultCurrency: StripeCurrency? = nil, email: String? = nil, externalAccount: Any? = nil, - legalEntity: StripeConnectAccountLegalEntity? = nil, + legalEntity: [String: Any]? = nil, metadata: [String : String]? = nil, payoutSchedule: [String : String]? = nil, payoutStatementDescriptor: String? = nil, @@ -147,7 +147,7 @@ public struct StripeConnectAccountRoutes: AccountRoutes { declineChargeOn: [String: Bool]?, defaultCurrency: StripeCurrency?, externalAccount: Any?, - legalEntity: StripeConnectAccountLegalEntity?, + legalEntity: [String: Any]?, metadata: [String: String]?, payoutSchedule: [String: String]?, payoutStatementDescriptor: String?, @@ -202,14 +202,14 @@ public struct StripeConnectAccountRoutes: AccountRoutes { if let externalAccountToken = externalAccount as? String { body["external_account"] = externalAccountToken - } else if let externalBankAccount = externalAccount as? StripeExternalBankAccount { - try externalBankAccount.toEncodedDictionary().forEach { body["external_account[\($0)]"] = $1 } - } else if let externalCardAccount = externalAccount as? StripeExternalCardAccount { - try externalCardAccount.toEncodedDictionary().forEach { body["external_account[\($0)]"] = $1 } + } else if let externalBankAccount = externalAccount as? [String: Any] { + externalBankAccount.forEach { body["external_account[\($0)]"] = $1 } + } else if let externalCardAccount = externalAccount as? [String: Any] { + externalCardAccount.forEach { body["external_account[\($0)]"] = $1 } } if let legalEntity = legalEntity { - try legalEntity.toEncodedDictionary().forEach { body["legal_entity[\($0)]"] = $1 } + legalEntity.forEach { body["legal_entity[\($0)]"] = $1 } } if let metadata = metadata { @@ -276,7 +276,7 @@ public struct StripeConnectAccountRoutes: AccountRoutes { defaultCurrency: StripeCurrency?, email: String?, externalAccount: Any?, - legalEntity: StripeConnectAccountLegalEntity?, + legalEntity: [String: Any]?, metadata: [String : String]?, payoutSchedule: [String : String]?, payoutStatementDescriptor: String?, @@ -316,16 +316,16 @@ public struct StripeConnectAccountRoutes: AccountRoutes { body["email"] = email } - if let externalBankAccount = externalAccount as? StripeExternalBankAccount { - try externalBankAccount.toEncodedDictionary().forEach { body["external_account[\($0)]"] = $1 } - } - - if let externalCardAccount = externalAccount as? StripeExternalCardAccount { - try externalCardAccount.toEncodedDictionary().forEach { body["external_account[\($0)]"] = $1 } + if let externalAccountToken = externalAccount as? String { + body["external_account"] = externalAccountToken + } else if let externalBankAccount = externalAccount as? [String: Any] { + externalBankAccount.forEach { body["external_account[\($0)]"] = $1 } + } else if let externalCardAccount = externalAccount as? [String: Any] { + externalCardAccount.forEach { body["external_account[\($0)]"] = $1 } } if let legalEntity = legalEntity { - try legalEntity.toEncodedDictionary().forEach { body["legal_entity[\($0)]"] = $1 } + legalEntity.forEach { body["legal_entity[\($0)]"] = $1 } } if let metadata = metadata {