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

Vapor Stripe Provider

Swift Vapor CircleCI

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.

Getting Started

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.

Whats Implemented

Core Resources

  • [x] Balance
  • [x] Charges
  • [x] Customers
  • [x] Disputes
  • [ ] Events
  • [x] File Links
  • [x] File Uploads
  • [ ] PaymentIntents
  • [x] Payouts
  • [x] Products
  • [x] Refunds
  • [x] Tokens

Payment Methods

  • [x] Bank Accounts
  • [x] Cards
  • [x] Sources

Checkout

  • [ ] Sessions

Billing

  • [x] Coupons
  • [x] Discounts
  • [x] Invoices
  • [x] Invoice Items
  • [x] Products
  • [x] Plans
  • [x] Subscriptions
  • [x] Subscription items
  • [ ] Usage Records

Connect

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

Fraud

  • [ ] Reviews
  • [ ] Value Lists
  • [ ] Value List Items

Issuing

  • [ ] Authorizations
  • [ ] Cardholders
  • [ ] Cards
  • [ ] Disputes
  • [ ] Transactions

Terminal

  • [ ] Connection Tokens
  • [ ] Locations
  • [ ] Readers

Orders

  • [x] Orders
  • [x] Order Items
  • [x] Returns
  • [x] SKUs
  • [x] Ephemeral Keys

Sigma

  • [ ] Scheduled Queries

Webhooks

  • [ ] Webhook Endpoints

License

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

Github

link
Stars: 122
Help us keep the lights on

Dependencies

Releases

2.4.1 - Dec 6, 2019

Points back to the master branch.

3.0.0-beta.2.0.0 - Nov 6, 2019

Updates to support the 2019-11-05 API

3.0.0-beta.1.0.0 - Nov 3, 2019

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.