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.
In your Package.swift
file, add the following
.package(url: "https://github.com/vapor-community/stripe-provider.git", from: "2.2.0")
Register the config and the provider in configure.swift
let config = StripeConfig(productionKey: "sk_live_1234", testKey: "sk_test_1234")
services.register(config)
try services.register(StripeProvider())
And you are all set. Interacting with the API is quite easy from any route handler.
struct ChargeToken: Content {
var token: String
}
func chargeCustomer(_ req: Request) throws -> EventLoopFuture<HTTPStatus> {
return try req.content.decode(ChargeToken.self).flatMap { charge in
return try req.make(StripeClient.self).charge.create(amount: 2500, currency: .usd, source: charge.token).map { stripeCharge in
if stripeCharge.status == .success {
return .ok
} else {
print("Stripe charge status: \(stripeCharge.status.rawValue)")
return .badRequest
}
}
}
}
And you can always check the documentation to see the required paramaters for specific API calls.
- Balance
- Charges
- Customers
- Disputes
- Events
- File Links
- File Uploads
- PaymentIntents
- Payouts
- Products
- Refunds
- Tokens
- Bank Accounts
- Cards
- Sources
- Sessions
- Coupons
- Discounts
- Invoices
- Invoice Items
- 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
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! 😀