-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from vapor-community/2019-10-08
Update to latest API 2019-11-05
- Loading branch information
Showing
13 changed files
with
350 additions
and
98 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// AccountLinkRoutes.swift | ||
// | ||
// | ||
// Created by Andrew Edwards on 11/3/19. | ||
// | ||
|
||
import NIO | ||
import NIOHTTP1 | ||
import Foundation | ||
|
||
public protocol AccountLinkRoutes { | ||
|
||
/// Creates an AccountLink object that returns a single-use Stripe URL that the user can redirect their user to in order to take them through the Connect Onboarding flow. | ||
/// - Parameter account: The identifier of the account to create an account link for. | ||
/// - Parameter failureUrl: The URL that the user will be redirected to if the account link is no longer valid. | ||
/// - Parameter successUrl: The URL that the user will be redirected to upon leaving or completing the linked flow successfully. | ||
/// - Parameter type: The type of account link the user is requesting. Possible values are `custom_account_verification` or `custom_account_update`. | ||
/// - Parameter collect: The information the platform wants to collect from users up-front. Possible values are `currently_due` and `eventually_due`. | ||
func create(account: String, | ||
failureUrl: String, | ||
successUrl: String, | ||
type: AccountLinkCreationType, | ||
collect: AccountLinkCreationCollectType?) -> EventLoopFuture<AccountLink> | ||
|
||
var headers: HTTPHeaders { get set } | ||
} | ||
|
||
public struct StripeAccountLinkRoutes: AccountLinkRoutes { | ||
private let apiHandler: StripeAPIHandler | ||
public var headers: HTTPHeaders = [:] | ||
|
||
init(apiHandler: StripeAPIHandler) { | ||
self.apiHandler = apiHandler | ||
} | ||
|
||
public func create(account: String, | ||
failureUrl: String, | ||
successUrl: String, | ||
type: AccountLinkCreationType, | ||
collect: AccountLinkCreationCollectType?) -> EventLoopFuture<AccountLink> { | ||
var body: [String: Any] = ["account": account, | ||
"failure_url": failureUrl, | ||
"success_url": successUrl, | ||
"type": type.rawValue] | ||
|
||
if let collect = collect { | ||
body["collect"] = collect.rawValue | ||
} | ||
|
||
return apiHandler.send(method: .POST, path: StripeAPIEndpoint.accountLinks.endpoint, body: .string(body.queryParameters), headers: headers) | ||
} | ||
} |
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
Oops, something went wrong.