Last active
May 15, 2018 06:31
-
-
Save poksi592/a95896d3e6df3912e4b69246c5493865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationServices { | |
// ApplicationServices is a singleton, because it makes it easier to be accessed from anywhere to access its functions/services | |
static let shared = ApplicationServices() | |
let appRouter = ApplicationRouter() | |
func pay(amount: Double, | |
username: String, | |
password: String, | |
completion: @escaping (() -> Void)) { | |
// Get payment token from `LoginModule` with `username` and `password` | |
guard let moduleUrl = URL(schema: "tandem", | |
host: "login", | |
path: "/payment-token", | |
parameters: ["username": username, | |
"password": password]) else { | |
return | |
} | |
appRouter.open(url: moduleUrl) { [weak self] (response, responseData, urlResponse, error) in | |
// Use `token` in response to make an actual payment through `PaymentsModule` | |
guard let response = response, | |
let token = response["paymentToken"] as? String, | |
let moduleUrl = URL(schema: "tandem", | |
host: "payments", | |
path: "/pay", | |
parameters: ["token": token, | |
"amount": String(amount)]) else { | |
return | |
} | |
self?.appRouter.open(url: moduleUrl) { (response, responseData, urlResponse, error) in | |
// Final callback, basically just to synchronize our example here with the NonCompliantModule | |
completion() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment