Skip to content

Commit

Permalink
Fix #12
Browse files Browse the repository at this point in the history
  • Loading branch information
aydenp committed Dec 4, 2017
1 parent def7800 commit e678110
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Bank/API/PlaidManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,40 @@ extension PlaidManager {
extension PlaidManager {
/// Information about the current Plaid API being used by the app.
struct PlaidInfo {
let publicKey: String, secret: String, clientID: String
let publicKey: String, secret: String, clientID: String, environment: Environment

var baseURL: String {
return "https://sandbox.plaid.com/"
return "https://\(environment).plaid.com/"
}

var configuration: PLKConfiguration {
let config = PLKConfiguration(key: publicKey, env: PLKEnvironment.sandbox, product: .transactions)
let config = PLKConfiguration(key: publicKey, env: environment.linkEnvironment, product: .transactions)
config.clientName = "Bank for iOS"
return config
}

fileprivate func createAPI() -> PlaidAPI {
return PlaidAPI(rootServerURL: baseURL, clientID: clientID, secret: secret)
}

enum Environment: String {
case development, sandbox, production

var linkEnvironment: PLKEnvironment {
switch self {
case .development: return .development
case .sandbox: return .sandbox
case .production: return .production
}
}
}
}

var info: PlaidInfo {
// Read Plaid.plist from main bundle
guard let plistURL = Bundle.main.url(forResource: "Plaid", withExtension: "plist"), let plistData = try? Data(contentsOf: plistURL), let info = (try? PropertyListSerialization.propertyList(from: plistData, options: [], format: nil)) as? [String: String] else { fatalError("Invalid or non-existant Plaid info .plist file was provided.") }
// Get configuration from Plaid.plist
guard let key = info["publicKey"], let clientID = info["clientID"], let secret = info["secret"] else { fatalError("Couldn't get required Plaid API Info from Info.plist") }
return PlaidInfo(publicKey: key, secret: secret, clientID: clientID)
guard let key = info["publicKey"], let clientID = info["clientID"], let secret = info["secret"], let env = info["environment"], let environment = PlaidInfo.Environment(rawValue: env) else { fatalError("Couldn't get required Plaid API Info from Info.plist") }
return PlaidInfo(publicKey: key, secret: secret, clientID: clientID, environment: environment)
}
}
2 changes: 2 additions & 0 deletions Plaid.example.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<string>CLIENTIDHERE</string>
<key>publicKey</key>
<string>PUBLICKEYHERE</string>
<key>environment</key>
<string>development</string>
</dict>
</plist>

0 comments on commit e678110

Please sign in to comment.