Stripe is a payment platform that handles credit cards, bitcoin and ACH transfers. They have become one of the best platforms for handling payments for projects, services or products.
There wasn't a library for it that worked with Vapor, and I needed one for my project. The Stripe API is huge, and therefor I only plan on implementing the things that deal with payments. If there is something you need outside of that scope, feel free to submit a Pull Request.
In your Package.swift
file, add a Package
For Swift 3
.Package(url: "https://github.com/vapor-community/stripe.git", Version(1,0,0))
For Swift 4
.package(url: "https://github.com/vapor-community/stripe.git", .exact(Version(1,0,0)))
You'll need a config file as well. Place a stripe.json
file in your Config
folder
{
"apiKey": "YOUR_API_KEY"
}
Add the provider to your droplet
try drop.addProvider(Stripe.Provider.self)
And you are all set. Interacting with the API is quite easy. Everything is Node backed with a simple API.
Making calls to the api is a simple one line
let object = try drop.stripe?.balance.history().serializedResponse()
The object is returned response model, or model array.
To avoid having to remember to add tests to LinuxMain.swift
you can use Sourcery to add your tets cases there for you. Just install the sourcery binary with Homebrew brew install sourcery
, navigate to your project folder, and from the command line run the following:
sourcery --sources Tests/ --templates Sourcery/LinuxMain.stencil --args testimports='@testable import StripeTests'
It will generate the following with your tests added:
import XCTest
@testable import StripeTests
extension BalanceTests {
static var allTests = [
("testBalance", testBalance),
...
]
}
.
.
XCTMain([
testCase(BalanceTests.allTests),
...
])
- Balance Fetching
- Charges
- Customers
- Coupons
- Plans
- Refunds
- Tokens
- Sources
- Subscriptions
- Connect account
- Orders
- Order Items
- Products
- Disputes
- Invoices
- Invoice Items
- Ephemeral Keys
Vapor Stripe Provider is available under the MIT license. See the LICENSE file for more info.
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! 😀