Swiftpack.co - Package - vapor-community/stripe-provider


Swift Vapor

StripeProvider is a Vapor wrapper around StripeKit

Usage guide

In your Package.swift file, add the following

.package(url: "https://github.com/vapor-community/stripe-provider.git", from: "3.0.0")

Register the configuration and the provider in configure.swift

import Stripe

let stripeConfiguration = StripeConfiguration(apiKey: "sk_live_1234")

try services.register(StripeProvider())

Now to make a charge

import Stripe

struct ChargeToken: Content {
    var stripeToken: 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.stripeToken).map { stripeCharge in
            if stripeCharge.status == .success {
                return .ok
            } else {
                print("Stripe charge status: \(stripeCharge.status.rawValue)")
                return .badRequest


Vapor Stripe Provider 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! 😀


Stars: 122
Help us keep the lights on


2.4.0 - Oct 9, 2019

Adds support for payment intents and updated to the latest API of 09-09-2019. See changes here.

3.0.0-alpha.1.5 - Sep 28, 2019

Exported StripeKit so now you can just import Stripe rather than StripeKit.

3.0.0-alpha.1.4 - Jul 16, 2019

2.3.4 - Jul 5, 2019

Adds support for Stripe Direct Charging

3.0.0-alpha.1.3 - Jun 19, 2019