Skip to content
No description or website provided.
Branch: master
Clone or download
Latest commit 1f74dc9 Jun 18, 2019


StripeKit is a Swift package used to communicate with the Stripe API for Server Side Swift Apps.

Current supported version

Version 1.0.0 of StripeKit supports the Stripe API version of 2019-05-16. You can check the releases page to use a version of StripeKit that meets your needs.


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

.package(url: "", from: "1.0.0")

Using the API

Initialize the StripeClient

let elg = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
let stripe = StripeClient(eventLoop: elg, apiKey: "sk_12345")

And now you have acess to the APIs via stripe.

The APIs you have available corrospond to what's implemented.

For example to use the charges API, the stripeclient has a property to access that API via routes.

try stripe.charges.create(amount: 2500,
                          currency: .usd,
                          description: "A server written in swift.",
                          source: "tok_visa").flatMap { (charge) -> EventLoopFuture<Void> in
                           if charge.status == .succeeded {
                               print("New servers are on the way 🚀")
                           } else {
                               print("Sorry you have to use Node.js 🤢")

Nuances with parameters and type safety

Stripe has a habit of changing APIs and having dynamic paramters for alot of their APIs. To accomadate for these changes, certain routes that take arguments that are hashs or Dictionaries, are represented by a swift dictionary [String: Any].

For example consider the connect account api.

// We define a custom dictionary to represent the paramaters stripe requires.
// This allows us to avoid having to add updates to the library when a paramater or structure changes.
let individual: [String: Any] = ["address": ["city": "New York",
					     "country": "US",
                                             "line1": "1551 Broadway",
                                             "postal_code": "10036",
	                  	             "state": "NY"],
				 "first_name": "Taylor",
			         "last_name": "Swift",
                                 "ssn_last_4": "0000",
				 "dob": ["day": "13",
					 "month": "12",
					 "year": "1989"]]
let businessSettings: [String: Any] = ["payouts": ["statement_descriptor": "SWIFTFORALL"]]

let tosDictionary: [String: Any] = ["date": Int(Date().timeIntervalSince1970), "ip": ""]

try stripe.connectAccounts.create(type: .custom,									
                                  country: "US",
				  email: "",
				  businessType: .individual,
			          defaultCurrency: .usd,
				  externalAccount: "bank_token",
			          individual: individual,
				  requestedCapabilities: ["platform_payments"],
				  settings: businessSettings,
				  tosAcceptance: tosDictionary).flatMap { connectAccount in
					print("New Stripe Connect account ID: \(")			

Authentication via the Stripe-Account header

The first, preferred, authentication option is to use your (the platform account’s) secret key and pass a Stripe-Account header identifying the connected account for which the request is being made. The example request performs a refund of a charge on behalf of a connected account:

   stripe.refunds.headers.add(name: "Stripe-Account", value: "acc_12345")
   try stripe.refunds.create(charge: "ch_12345", reason: .requestedByCustomer)

NOTE: The modified headers will remain on the route instance (refunds in this case) of the StripeClient if a reference to it is held. If you're accessing the StripeClient in the scope of a function, the headers will not be retained.

Whats Implemented

Core Resources

  • Balance
  • Charges
  • Customers
  • Customer Tax IDs
  • Disputes
  • Events
  • File Links
  • File Uploads
  • PaymentIntents
  • Payouts
  • Products
  • Refunds
  • Tokens

Payment Methods

  • Payment Methods
  • Bank Accounts
  • Cards
  • Sources


  • Sessions


  • Coupons
  • Discounts
  • Invoices
  • Invoice Items
  • Tax Rates
  • Credit Notes
  • Products
  • Plans
  • Subscriptions
  • Subscription items
  • Usage Records


  • Account
  • Application Fee Refunds
  • Application Fees
  • Country Specs
  • External Accounts
  • Persons
  • Top-ups
  • Transfers
  • Transfer Reversals


  • Reviews
  • Value Lists
  • Value List Items


  • Authorizations
  • Cardholders
  • Cards
  • Disputes
  • Transactions


  • Connection Tokens
  • Locations
  • Readers


  • Orders
  • Order Items
  • Returns
  • SKUs
  • Ephemeral Keys


  • Scheduled Queries


  • Webhook Endpoints

TODO At some point


StripeKit is available under the MIT license. See the LICENSE file for more info.

Want to help?

Feel free to submit a pull request whether it's a clean up, a new approach to handling things, adding a new part of the API, or even if it's just a typo. All help is welcomed! 😀

You can’t perform that action at this time.