Skip to content

Commit

Permalink
Merge pull request #8 from vapor-community/2019-10-08
Browse files Browse the repository at this point in the history
Update to latest API 2019-11-05
  • Loading branch information
Andrewangeta authored Nov 6, 2019
2 parents 970e510 + 16cd691 commit 1cc8418
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 98 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
### StripeKit is a Swift package used to communicate with the [Stripe](https://stripe.com) API for Server Side Swift Apps.

## Current supported version
Version **1.0.0** of StripeKit supports the Stripe API version of **[2019-05-16](https://stripe.com/docs/upgrades#2019-05-16)**.
You can check the releases page to use a version of StripeKit that meets your needs.
Version **2.0.0** of StripeKit supports the Stripe API version of **[2019-11-05](https://stripe.com/docs/upgrades#2019-11-05)**.
**You can check the releases page to use a version of StripeKit that meets your needs.**

## Installation
To start using StripeKit, in your `Package.swift`, add the following

~~~~swift
.package(url: "https://github.com/vapor-community/stripekit.git", from: "1.0.0")
.package(url: "https://github.com/vapor-community/stripekit.git", from: "2.0.0")
~~~~

## Using the API
Expand Down Expand Up @@ -149,6 +149,7 @@ None of the API calls throw errors. Instead each route returns a successful `Eve
---
### Connect
* [x] Account
* [x] Account Links
* [x] Application Fee Refunds
* [x] Application Fees
* [x] Country Specs
Expand Down
4 changes: 4 additions & 0 deletions Sources/StripeKit/API/Helpers/Endpoints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ internal enum StripeAPIEndpoint {
case scheduledQueryRun
case scheduledQueryRuns(String)

case accountLinks

var endpoint: String {
switch self {
case .balance: return APIBase + APIVersion + "balance"
Expand Down Expand Up @@ -407,6 +409,8 @@ internal enum StripeAPIEndpoint {

case .scheduledQueryRun: return APIBase + APIVersion + "sigma/scheduled_query_runs"
case .scheduledQueryRuns(let query): return APIBase + APIVersion + "sigma/scheduled_query_runs/\(query)"

case .accountLinks: return APIBase + APIVersion + "account_links"
}
}
}
53 changes: 53 additions & 0 deletions Sources/StripeKit/API/Routes/AccountLinkRoutes.swift
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)
}
}
3 changes: 1 addition & 2 deletions Sources/StripeKit/API/Routes/AccountRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public protocol AccountRoutes {
/// - businessType: The business type. Can be `individual` or `company`.
/// - company: Information about the company or business. This field is null unless `business_type` is set to `company`.
/// - defaultCurrency: Three-letter ISO currency code representing the default currency for the account. This must be a currency that Stripe supports in the account’s country.
/// - externalAccount: A card or bank account to attach to the account. You can provide either a token, like the ones returned by Stripe.js, or a dictionary, as documented in the `external_account` parameter for [bank account](https://stripe.com/docs/api#account_create_bank_account) creation.
/// By default, providing an external account sets it as the new default external account for its currency, and deletes the old default if one exists. To add additional external accounts without replacing the existing default for the currency, use the bank account or card creation API.
/// - externalAccount: A card or bank account to attach to the account. You can provide either a token, like the ones returned by Stripe.js, or a dictionary, as documented in the `external_account` parameter for [bank account](https://stripe.com/docs/api#account_create_bank_account) creation. By default, providing an external account sets it as the new default external account for its currency, and deletes the old default if one exists. To add additional external accounts without replacing the existing default for the currency, use the bank account or card creation API.
/// - individual: Information about the person represented by the account. This field is null unless `business_type` is set to `individual`.
/// - metadata: A set of key-value pairs that you can attach to an `Account` object. This can be useful for storing additional information about the account in a structured format.
/// - requestedCapabilities: The set of capabilities you want to unlock for this account (US only). Each capability will be inactive until you have provided its specific requirements and Stripe has verified them. An account may have some of its requested capabilities be active and some be inactive. This will be unset if you POST an empty value.
Expand Down
Loading

0 comments on commit 1cc8418

Please sign in to comment.