Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing Cukes #431

Merged
merged 156 commits into from
Jan 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
29c4da7
Nuke everything :bomb:
steveklabnik Nov 28, 2013
0249dca
"Tokenize a card without a secret" works.
steveklabnik Dec 2, 2013
999670a
Set up rake tasks to make running features easier
steveklabnik Dec 10, 2013
e48738e
New feature: creating API keys.
steveklabnik Dec 12, 2013
e494c51
New feature: retrieve API keys
steveklabnik Dec 12, 2013
82780ea
New feature: list all API keys
steveklabnik Dec 13, 2013
c3e3f5b
New feature: remove API keys
steveklabnik Dec 13, 2013
7a8e23a
Refactor/reorganize steps for clarity.
steveklabnik Dec 13, 2013
65a81b8
Update README.
steveklabnik Dec 13, 2013
424c741
Adding technical documentation.
steveklabnik Dec 13, 2013
8397390
moving root_url and accept_headers into global variables
matthewfl Dec 13, 2013
6f28333
adding card tokens schema
matthewfl Dec 13, 2013
f4328d5
Refactor schema error handling, reintroduce failure
matthewfl Dec 13, 2013
224b089
basic create customer scenario
matthewfl Dec 14, 2013
43349be
micro library to contain interaction with the api
matthewfl Dec 14, 2013
c318fb3
New feature: Customer index
matthewfl Dec 14, 2013
26bbee3
clean up some whitespace
steveklabnik Dec 16, 2013
f385d4f
New feature: get customer
steveklabnik Dec 16, 2013
aeb357e
'fix' failing address spec.
steveklabnik Dec 16, 2013
c66f665
Clean up some small formatting issues.
steveklabnik Dec 16, 2013
4d05364
New feature: remove a customer
steveklabnik Dec 16, 2013
146c870
New feature: create a callback
steveklabnik Dec 16, 2013
6b9aae4
New feature: get callback info
steveklabnik Dec 16, 2013
767de1e
refactor to use the client
steveklabnik Dec 17, 2013
c88e3e7
New features: list/delete callbacks
steveklabnik Dec 17, 2013
9a4cb93
New feature: get a card
steveklabnik Dec 17, 2013
9a6603e
New features: list and remove cards
steveklabnik Dec 17, 2013
35776fa
client library refactor.
steveklabnik Dec 17, 2013
1e61843
adding hydrater
matthewfl Dec 17, 2013
bbb2eff
start changing over to hydrater
matthewfl Dec 17, 2013
7caf6fd
feature: debiting a card
matthewfl Dec 17, 2013
e7eaf45
feature: Retrieving debits for a card
matthewfl Dec 17, 2013
26878a3
Implement PUT in the client.
steveklabnik Dec 17, 2013
647f631
New feature: update card
steveklabnik Dec 17, 2013
ea7a736
Fix broken callback scenario.
steveklabnik Dec 17, 2013
7c2c8e6
feature: debit a customer
matthewfl Dec 17, 2013
72b5546
new feature: debit a card
steveklabnik Dec 17, 2013
492b2f8
spacing is hard
matthewfl Dec 17, 2013
b6cfe2b
bank accounts feature failing as address is not coming back in response
matthewfl Dec 17, 2013
ca0e231
credit bank account feature
matthewfl Dec 17, 2013
125f31b
basic crud for bank accounts
matthewfl Dec 17, 2013
45654ef
bank account debit and credit scenarios
matthewfl Dec 17, 2013
24c22bb
Move features into rest
steveklabnik Dec 17, 2013
aaa5fc4
bank account verification feature
matthewfl Dec 17, 2013
fe968e5
finishing debit scenarios and forcing json schema formatting
matthewfl Dec 17, 2013
e52e3f9
refund features
matthewfl Dec 18, 2013
6ecfbee
customer add card/bank account
matthewfl Dec 18, 2013
b7e3b68
credits features
matthewfl Dec 18, 2013
07fe36d
reversal features
matthewfl Dec 18, 2013
8db133e
events schemas
matthewfl Dec 18, 2013
12689e8
events features
matthewfl Dec 18, 2013
f06b356
Add an alias for requests using different language
steveklabnik Dec 19, 2013
bce3379
New feature: root resource
steveklabnik Dec 19, 2013
f21ca0d
New feature: the resources resource
steveklabnik Dec 19, 2013
cf4036b
minor spelling updates
dclausen Dec 20, 2013
d5c1a3e
Better error messages on status code failure.
steveklabnik Dec 20, 2013
8e820bf
New feature: create a reversal.
steveklabnik Dec 20, 2013
967a193
New feature: failed reversal.
steveklabnik Dec 20, 2013
b89b6e3
New feature: failed reversal on bank account.
steveklabnik Dec 21, 2013
ed9340d
New feature: successful reversal
steveklabnik Dec 21, 2013
b2a5c7c
New feature: debit a card
steveklabnik Dec 21, 2013
8325137
make a distinction between having a card and a customer card.
steveklabnik Dec 21, 2013
1627bab
New feature: debit a customer card
steveklabnik Dec 21, 2013
602214e
New feature: create a customer
steveklabnik Dec 21, 2013
ef2eecb
fix description around customer cards
steveklabnik Dec 25, 2013
71d9ae0
new feature: refunds create
steveklabnik Dec 25, 2013
2a70aac
Add HTTP PATCH to tiny client.
steveklabnik Dec 27, 2013
3d1c8bf
Log secret and marketplace ID
steveklabnik Dec 27, 2013
27ed2d1
New feature: create a debit
steveklabnik Dec 27, 2013
a9d699e
New feature: refunds go to original funding source.
steveklabnik Dec 28, 2013
44512a5
New feature: create a failing refund
steveklabnik Dec 28, 2013
e866535
New feature: debit a verified bank account
steveklabnik Dec 28, 2013
40f037d
New feature: debits to unverified bank accounts fail.
steveklabnik Dec 28, 2013
b6bd5a7
New feature: debit a customer
steveklabnik Dec 28, 2013
49ece83
New feature: fail to debit a customer
steveklabnik Dec 28, 2013
0d11bf3
Merge pull request #454 from dclausen/patch-1
matin Dec 31, 2013
c7068e6
New feature: default funding source.
steveklabnik Dec 31, 2013
859d9e7
New features: customers and orders
rserna2010 Jan 2, 2014
bf531fc
Convert more scenarios
rserna2010 Jan 2, 2014
3830fea
fixes error scenario and issue #459
matthewfl Jan 6, 2014
f528307
number of minor fixes
matthewfl Jan 6, 2014
7736c9e
Some movement toward #467
steveklabnik Jan 6, 2014
d0d02c1
Passing: reverse a credit on a bank account.
steveklabnik Jan 6, 2014
59337e0
remove 'set the default funding source
steveklabnik Jan 6, 2014
e11eda8
Some movement on underwriting a customer
steveklabnik Jan 6, 2014
0536af7
Moving forward on 'create an order'
steveklabnik Jan 7, 2014
a68ddd8
progress on checking escrow on orders.
steveklabnik Jan 7, 2014
f7a6c77
Add in debugging steps.
steveklabnik Jan 7, 2014
fba6285
Making some progress on 'checking escrow of order'
steveklabnik Jan 7, 2014
5ee8012
Making progress on 'orders can't be credited more...
steveklabnik Jan 7, 2014
5d33e55
Making progress on 'Create a refund'
steveklabnik Jan 7, 2014
3e1b0b8
Update interpolation syntax
steveklabnik Jan 7, 2014
870fcdb
Typo fix: should be an order not an error
steveklabnik Jan 7, 2014
51c6a76
Making progress on create a reversal
steveklabnik Jan 7, 2014
37043f4
fix interpolation syntax
steveklabnik Jan 7, 2014
4ce588a
baby steps
matthewfl Jan 7, 2014
6083a08
New feature: underwrite a customer
steveklabnik Jan 7, 2014
6c29870
Merge remote-tracking branch 'origin/cukes' into cukes
matthewfl Jan 8, 2014
585f67f
making some movement on #471
steveklabnik Jan 8, 2014
48ec874
Make progress on 'transactions inherit descriptions'
steveklabnik Jan 11, 2014
48b6239
make some progress on crediting an unverified merchant.
steveklabnik Jan 11, 2014
413775d
Making progress on 'cancelling an order'
steveklabnik Jan 13, 2014
0afcceb
Making progress on 'existing buyer makes a purchase with a new card'
steveklabnik Jan 13, 2014
37eb86b
some cleaning
matthewfl Jan 13, 2014
89da538
making progress on 'existing buyer makes a purchase with an existing …
steveklabnik Jan 14, 2014
a4a51d7
Making progress on 'new buyer makes a purchase'
steveklabnik Jan 14, 2014
e7f8430
Progress on existing buyer makes a purchase with a new card.
steveklabnik Jan 14, 2014
3cb8958
Add credit card scenarios.
rserna2010 Jan 14, 2014
8a3ffbf
making progress on 'adding a card to a customer'
steveklabnik Jan 14, 2014
0fb808b
New feature: AVS postal code matches
steveklabnik Jan 14, 2014
0c1d810
New feature: AVS postal code does not match
steveklabnik Jan 14, 2014
7de997d
New scenario: AVS Postal card is unsupported
steveklabnik Jan 14, 2014
b96c9d9
Making progress on 'AVS postal code is unused.
steveklabnik Jan 14, 2014
5381186
New feature: AVS street matches
steveklabnik Jan 14, 2014
87aafe9
New feature: AVS street does not match
steveklabnik Jan 14, 2014
ec98ab4
Making progress on 'avs street match is null'
steveklabnik Jan 14, 2014
84903e0
Progress on 'detect a visa card brand'
steveklabnik Jan 14, 2014
9a972aa
Make progress on 'detect a mastercard brand'
steveklabnik Jan 14, 2014
f850887
Make progress on 'detect an amex brand'
steveklabnik Jan 14, 2014
ae18309
make progress on 'detect a discover card'
steveklabnik Jan 14, 2014
761af4e
Make some progress on retrieving card info
steveklabnik Jan 14, 2014
80b8eb3
Progress on 'tokenizing a card'
steveklabnik Jan 14, 2014
e51d3a9
Making progress on luhn test failure
steveklabnik Jan 14, 2014
b47d8d0
new feature: unstore a card
steveklabnik Jan 14, 2014
7924eb0
New feature: CVV matches
steveklabnik Jan 14, 2014
4c454ed
progress on 'CVV doesn't match'
steveklabnik Jan 14, 2014
91847c7
Progress on 'CVV is unsupported'
steveklabnik Jan 14, 2014
0af3c98
Making progress on CVV is unused
steveklabnik Jan 14, 2014
2c2a4b0
'Add a card to a customer' now works
steveklabnik Jan 14, 2014
9a9e032
Feature fixed: Debit a card
steveklabnik Jan 15, 2014
2e7a0e6
Making progress on 'basic order flow'
steveklabnik Jan 15, 2014
84d3b4b
New feature: card metadata
steveklabnik Jan 16, 2014
e0ff12a
New feature: fail to confirm a bank account verification
steveklabnik Jan 16, 2014
2044e73
progress on 'inferring bank names'
steveklabnik Jan 16, 2014
9513dd2
Make progress on 'add a bank account to a customer'
steveklabnik Jan 16, 2014
9ba89de
removing failing tag from card scenarios
matthewfl Jan 16, 2014
5f9f1c7
cleaning orders features
matthewfl Jan 16, 2014
1392564
trying new link resolve system
matthewfl Jan 16, 2014
e4bc413
fix
matthewfl Jan 16, 2014
2eec38b
another one working
matthewfl Jan 16, 2014
2770646
fixing bank account rest scenarios
matthewfl Jan 16, 2014
7d774b5
fixed 404 error
matthewfl Jan 16, 2014
f802d28
canceling an order
matthewfl Jan 17, 2014
4b13e43
the end is nearing
matthewfl Jan 17, 2014
5a1a65f
one more to go
matthewfl Jan 17, 2014
bf659a8
I did it, its done, no more failing
matthewfl Jan 17, 2014
df27867
some issues with test credit card numbers
matthewfl Jan 18, 2014
79fd4df
properly tag luhn test failure.
steveklabnik Jan 20, 2014
8027255
Tagging CVV is unsupported failure.
steveklabnik Jan 20, 2014
a6fa221
Properly tagging cvv does not match
steveklabnik Jan 20, 2014
79702b8
cvv card number scenarios working
matthewfl Jan 21, 2014
f08a98d
it is all working now
matthewfl Jan 23, 2014
ce58fea
Add feature for debiting a card directly.
steveklabnik Jan 24, 2014
3a87dc0
Fix up specs related to reversals.
steveklabnik Jan 24, 2014
82540eb
New feature: update a customer
steveklabnik Jan 24, 2014
2b9b019
Two last bank account features.
steveklabnik Jan 24, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
before_install:
- git submodule update --init --recursive
language: python
python:
- 2.7
install:
- pip install -r tester/requirements.txt
script:
- cd tester && ./travis.sh
language: ruby
rvm:
- 2.0.0
script: bin/rake cruise
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

gem "cucumber"
gem "httparty"
gem "json-schema"
gem "uri_template"
gem "rake"
gem 'debugger'
41 changes: 41 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
GEM
remote: https://rubygems.org/
specs:
builder (3.2.2)
columnize (0.3.6)
cucumber (1.3.10)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.0.2)
debugger (1.6.5)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.1)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.1)
diff-lcs (1.2.5)
gherkin (2.12.2)
multi_json (~> 1.3)
httparty (0.12.0)
json (~> 1.8)
multi_xml (>= 0.5.2)
json (1.8.1)
json-schema (2.1.3)
multi_json (1.8.2)
multi_test (0.0.2)
multi_xml (0.5.5)
rake (10.1.0)
uri_template (0.6.0)

PLATFORMS
ruby

DEPENDENCIES
cucumber
debugger
httparty
json-schema
rake
uri_template
96 changes: 50 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
## Balanced API Specification

[![Build Status](https://travis-ci.org/balanced/balanced-api.png?branch=revision1)](https://travis-ci.org/balanced/balanced-api)

Balanced API Spec
=================

Online marketplaces enable a new form of commerce at a scale that has never
existed before. The success of online marketplaces has the potential to
materially effect the global economy by creating new jobs and economic activity
that previously did not exist. Airbnb, Kickstarter, Etsy, and other
marketplaces have created new forms of income for businesses and individuals.
That's what gets the [Balanced](https://www.balancedpayments.com/) team excited
and what the [Balanced API](https://www.balancedpayments.com/docs/integration)
hopes to support.

Payments for marketplaces is unfortunately painful because of unique
requirements including paying sellers, payments aggregation policies, tax
ramifications, and fraud. Balanced lets you charge cards, escrow funds, and pay
sellers the next business day without the pain of building a payments system.

The primary goal of this repo is to create more openness behind the decisions
driving the designs and functionality of the Balanced API. We reached out to
existing and potential customers when designing the API, but that was a limited
set of people we already knew. We've received tremendous growth in the last few
months, and our new customers have great feedback or at least want to
understand the reasoning behind the original decisions.

We're going to automate validation of our API code against the specifications
in the repo. Any changes to the API can't be deployed unless they've been
merged into master first. Any merge to master will happen concurrently with
deploys of the API and the [docs](https://www.balancedpayments.com/docs). That
means the specs need to be auto generated (except for comments) instead of
handwritten to make sure the code and specs can never go out of sync.

We'll do our best to have even internal discussions online. All changes (even
by the Balanced team) to the specs must be submitted via pull request and can
only be merged in by @matin after giving the community a chance to comment on
the changes.


Running Tests
=============

Create a new python2 virtual environment.
```
$ cd tester
$ pip install -r requirements.txt
$ python fixture_data.py > fixtures.json
$ python runner.py ../scenarios/[scenario name]
This repository contains an executable specification of the Balanced API. The
goal of this repository is two-fold. First, to ensure that the API is working
according to the spec. Second, to provide a place to have discussions around
the API as a product.

### An Executable Specification

Specifications don't matter if they're not followed. Therefore, this
specification is executable, so we can ensure conformance to the spec. There are
more details in the README file inside the `features` directory, but to run these
tests yourself, simply:

```bash
$ git clone https://github.com/balanced/balanced-api.git
$ cd balanced-api
$ bundle
$ bin/rake cucumber
```

This requires Ruby. We run the changes with Ruby 2.0, but other versions will
probably work as well. [Let us
know](https://github.com/balanced/balanced-api/issues/new) if you have any
problems running these specs, and we'd be happy to help.

If you're working on a new scenario, the 'focus' task is useful. Tag a scenario
with `@focus`, and then run `bin/rake focus`. It will only run that single scenario.

### Discussions around changes

Speaking of issues, that's the second purpose of this repository. If you would
like to see a new feature implemented in the Balanced API, please [open an
issue](https://github.com/balanced/balanced-api/issues/new) and we'll discuss
it.

For example, one of our biggest requests is to support non-USD currencies.
[Here](https://github.com/balanced/balanced-api/issues/23) is the issue with
the discussion, and when we support this feature, we close the issue via a pull
request that implements the specification, and then everyone on the issue gets
notified.

Sometimes, Issues are great for collecting feedback, as well. For example,
[all implementation of the current framework was done via
PR](https://github.com/balanced/balanced-api/pull/431), and some issues need
more explanation around use cases by those who want the feature, like [Bitcoin
support](https://github.com/balanced/balanced-api/issues/204).

We try to do as much 'internal' discussion in these issues as well, it's not
just for public feedback. If you want to know what we're thinking, just search
for a relevant issue!
52 changes: 52 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'cucumber/rake/task'

class BuildFailure < Exception;
def initialize(message = nil)
message ||= "Build failed"
super(message)
end
end;

Cucumber::Rake::Task.new do |t|
t.cucumber_opts = "--format progress --tags ~@failing"
end

Cucumber::Rake::Task.new(:focus) do |t|
t.cucumber_opts = "--format progress --tags @focus"
end

namespace :features do
desc "Run all features"
Cucumber::Rake::Task.new(:all) do |t|
t.cucumber_opts = "--format progress"
end

desc "Run in-progress features"
Cucumber::Rake::Task.new(:in_progress) do |t|
t.cucumber_opts = "--require formatters/ --format Cucumber::Formatter::InProgress --tags @failing"
end
end

desc "Run complete feature build"
task :cruise do
finished_successful = run_and_check_for_exception("cucumber")
in_progress_successful = run_and_check_for_exception("features:in_progress")

unless finished_successful && in_progress_successful
puts
puts("Finished features had failing steps") unless finished_successful
puts("In-progress Scenario/s passed when they should fail or be pending") unless in_progress_successful
puts
raise BuildFailure
end
end

def run_and_check_for_exception(task_name)
puts "*** Running #{task_name} features ***"
begin
Rake::Task["#{task_name}"].invoke
rescue Exception => e
return false
end
true
end
16 changes: 16 additions & 0 deletions bin/cucumber
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'cucumber' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('cucumber', 'cucumber')
16 changes: 16 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rake', 'rake')
81 changes: 81 additions & 0 deletions features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## Balanced API Spec: Technical details

Here's where the rubber hits the road.

### Background

We use [Cucumber](http://cukes.info/) for features. What that means is that the
descriptions are in psuedo-English, which then gets mapped to code.

You can check out the specifications by looking at any of the files that end
with `.feature` in this directory. They look like this:

```
Feature: API Keys
API Keys are what customers use to authenticate against the Balanced API.
Generally speaking, this will be the first step that is needed to be taken by
the customer to get started with the API.

Scenario: List all API keys
Customers can make as many keys as they'd like. Being able to see all of
them is a good thing.

Given I have created more than one API keys
When I GET to /api_keys
Then I should get a 200 OK status code
```

As you can see by the indentation, each file describes a 'feature.' There's
then some descriptive text about what that feature is and why it's important.
Features are a collection of 'scenarios,' which describe different things the
API can do. These scenarios also have some descriptive text as well. Scenarios
are made up of 'steps,' which start with "Given," "When," "Then," "And," and a
few others. These steps are actually executed by Cucumber: they run actual code.

That code is determined by the `step\_definitions` files, which are in that
directory. They map these feature lines to actual Ruby code. For example,

```
When I GET to /api_keys
```

is mapped to

```
When(/^I (\w+) to (\/\S*?)$/) do |verb, url|
options = {
headers: {
"Accept" => "application/vnd.api+json;revision=1.1",
},
basic_auth: {
username: $api_secret,
password: "",
}
}
response = HTTParty.send(verb.downcase, "https://api.balancedpayments.com#{url}", options)
@response_code = response.code
@response_body = JSON.parse(response.body)
end
```

This is illustrative of why we're using Cucumber; if you're not a Rubyist, you
can probably follow the second bit, but it's full of details you just don't
care about. You care that you're making a GET to a certain URL, the rest of the stuff
is just noise.

There is also a `support` directory with some background code that's used to
set things up. You probably don't care about it.

### Running the tests

The tests are run via `rake`. Simply go to the root level of the repository, and run

```
$ bin/rake cucumber
```

to run the specs that are currently passing. To see all the tasks,

```
$ bin/rake -T
```
Loading