Swiftpack.co - northsydneybears/stripe as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by northsydneybears.
northsydneybears/stripe 6.0.1-beta
Duplicate mirror of Vapor-community/stripe
⭐️ 0
🕓 3 years ago
macOS
.package(url: "https://github.com/northsydneybears/stripe.git", from: "6.0.1-beta")

Stripe

Swift Vapor

Stripe is a Vapor helper to use StripeKit

Usage guide

In your Package.swift file, add the following

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

To use Stripe in your Vapor application, set the environment variable for you Stripe API key

export STRIPE_API_KEY="sk_123456"      

Now you can access a StripeClient via Request.


struct ChargeToken: Content {
    var token: String
}

func chargeCustomer(_ req: Request) throws -> EventLoopFuture<HTTPStatus> {
    return try req.content.decode(ChargeToken.self).flatMap { charge in
        return req.stripe.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
            }
        }
    }
}

License

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

GitHub

link
Stars: 0
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

3 years ago

Version bump of stripe-kit

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics