Skip to content

Commit

Permalink
Merge pull request #27 from vapor-community/beta
Browse files Browse the repository at this point in the history
Merge Beta into Master
  • Loading branch information
Andrewangeta authored Mar 25, 2018
2 parents b995ce2 + a4415c4 commit 104ce26
Show file tree
Hide file tree
Showing 174 changed files with 6,891 additions and 12,388 deletions.
25 changes: 25 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2

jobs:
macos:
macos:
xcode: "9.2"
steps:
- checkout
- run: swift build
- run: swift test
linux:
docker:
- image: norionomura/swift:swift-4.1-branch
steps:
- checkout
- run: apt-get update
- run: apt-get install -yq libssl-dev
- run: swift build
- run: swift test
workflows:
version: 2
tests:
jobs:
- linux
# - macos
14 changes: 8 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// swift-tools-version:3.1

// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "Stripe",
targets: [
Target(name: "Stripe"),
products: [
.library(name: "Stripe", targets: ["Stripe"])
],
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
.Package(url: "https://github.com/vapor/random.git", majorVersion: 1),
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"),
],
targets: [
.target(name: "Stripe", dependencies: ["Vapor"]),
.testTarget(name: "StripeTests", dependencies: ["Vapor", "Stripe"])
]
)
17 changes: 0 additions & 17 deletions Package@swift-4.swift

This file was deleted.

119 changes: 64 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,102 @@
# Vapor Stripe Provider

![Swift](http://img.shields.io/badge/swift-3.1-brightgreen.svg)
![Vapor](http://img.shields.io/badge/vapor-2.0-brightgreen.svg)
![Build](https://img.shields.io/badge/build-passing-brightgreen.svg)
![Swift](http://img.shields.io/badge/swift-4.1-brightgreen.svg)
![Vapor](http://img.shields.io/badge/vapor-3.0-brightgreen.svg)
[![CircleCI](https://circleci.com/gh/vapor-community/stripe-provider/tree/beta.svg?style=svg)](https://circleci.com/gh/vapor-community/stripe-provider/tree/beta)

[Stripe][stripe_home] 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.

## Why Create this?
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.

## Getting Started
In your `Package.swift` file, add a Package
For Swift 3
~~~~swift
.Package(url: "https://github.com/vapor-community/stripe.git", Version(1,0,0))
~~~~

For Swift 4
~~~~swift
.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
~~~~json
{
"apiKey": "YOUR_API_KEY"
}
.package(url: "https://github.com/vapor-community/stripe-provider.git", .branch("beta"))
~~~~

Add the provider to your droplet
Register the config and the provider to your Application
~~~~swift
try drop.addProvider(Stripe.Provider.self)
~~~~
let config = StripeConfig(apiKey: "sk_12345678")

And you are all set. Interacting with the API is quite easy. Everything is Node backed with a simple API.
services.register(config)

Making calls to the api is a simple one line
~~~~swift
let object = try drop.stripe?.balance.history().serializedResponse()
~~~~
The object is returned response model, or model array.
try services.register(StripeProvider())

## Testing
app = try Application(services: services)

To avoid having to remember to add tests to `LinuxMain.swift` you can use [Sourcery][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:
~~~~bash
sourcery --sources Tests/ --templates Sourcery/LinuxMain.stencil --args testimports='@testable import StripeTests'
stripeClient = try app.make(StripeClient.self)
~~~~
It will generate the following with your tests added:

And you are all set. Interacting with the API is quite easy and adopts the `Future` syntax used in Vapor 3.
Making calls to the api is straight forward.
~~~~swift
import XCTest
@testable import StripeTests
extension BalanceTests {
static var allTests = [
("testBalance", testBalance),
...
]
}
.
.
XCTMain([
testCase(BalanceTests.allTests),
...
])
let cardParams = ["exp_month": 1,
"exp_year": 2030,
"number": "4242424242424242",
"cvc": 123,
"object": "card"]

let futureCharge = try stripeClient.charge.create(amount: 2500, currency: .usd, source: cardParams)

futureCharge.do({ (charge) in
// do something with charge object...
}).catch({ (error) in
print(error)
})
~~~~

And you can always check the documentation to see the required paramaters for specific API calls.

## Linux compatibility
Currently the project won't compile for linux.
You can track this issue [here](https://bugs.swift.org/browse/SR-7180) and [here](https://github.com/apple/swift-corelibs-foundation/pull/1347)

## Whats Implemented
* [x] Balance Fetching

### Core Resources
* [x] Balance
* [x] Charges
* [x] Customers
* [x] Coupons
* [x] Plans
* [x] Disputes
* [ ] Events
* [ ] File Uploads
* [ ] Payouts
* [x] Refunds
* [x] Tokens
---
### Payment Methods
* [x] Bank Accounts
* [x] Cards
* [x] Sources
---
### Subscriptions
* [x] Coupons
* [x] Discounts
* [x] Invoices
* [x] Invoice Items
* [x] Plans
* [x] Subscriptions
* [x] Connect account
* [x] Subscription items
---
### Connect
* [x] Account
* [ ] Application Fee Refunds
* [ ] Application Fees
* [ ] Country Specs
* [x] External Accounts
* [ ] Transfers
* [ ] Transfer Reversals
---
### Relay
* [x] Orders
* [x] Order Items
* [x] Products
* [x] Disputes
* [x] Invoices
* [x] Invoice Items
* [x] Returns
* [x] SKUs
* [x] Ephemeral Keys

[stripe_home]: http://stripe.com "Stripe"
[stripe_api]: https://stripe.com/docs/api "Stripe API Endpoints"
[sourcery]: https://github.com/krzysztofzablocki/Sourcery "Sourcery"

## License

Expand Down
Loading

0 comments on commit 104ce26

Please sign in to comment.