stripe_mock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e511d1bc67f8b5b9b39e08658e961fe87f10ee09
4
+ data.tar.gz: c1f784c1bbc2818768df71a85fd8aa85affa695d
5
+ SHA512:
6
+ metadata.gz: fc3b159c8cab798bd3dd1ae722561d2c14b3431438fb79febdc0d6929887418947c78e41d8b29dca633a80dd9f5ca05eac122d9db7a9af747cc676189257408f
7
+ data.tar.gz: 3b8cd90f3e942434435abaf8ba17ee4ec6bb76d26e0379c1aa9cc868167e2f078ba976dc76b7f11937e02a630f9df4a9d56f97fc91613d921f0c6f727094c4f8
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
11
+ spec/cassettes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --profile
3
+ --fail-fast
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stripe_mock.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,71 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+ watch('lib/stripe_mock/stripe_proxy.rb') { rspec.spec_dir }
39
+
40
+ # Ruby files
41
+ ruby = dsl.ruby
42
+ dsl.watch_spec_files_for(ruby.lib_files)
43
+ #
44
+ # # Rails files
45
+ # rails = dsl.rails(view_extensions: %w(erb haml slim))
46
+ # dsl.watch_spec_files_for(rails.app_files)
47
+ # dsl.watch_spec_files_for(rails.views)
48
+ #
49
+ # watch(rails.controllers) do |m|
50
+ # [
51
+ # rspec.spec.("routing/#{m[1]}_routing"),
52
+ # rspec.spec.("controllers/#{m[1]}_controller"),
53
+ # rspec.spec.("acceptance/#{m[1]}")
54
+ # ]
55
+ # end
56
+ #
57
+ # # Rails config changes
58
+ # watch(rails.spec_helper) { rspec.spec_dir }
59
+ # watch(rails.routes) { "#{rspec.spec_dir}/routing" }
60
+ # watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
61
+ #
62
+ # # Capybara features specs
63
+ # watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
64
+ # watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
65
+ #
66
+ # # Turnip features and steps
67
+ # watch(%r{^spec/acceptance/(.+)\.feature$})
68
+ # watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
69
+ # Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
70
+ # end
71
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Digital Opera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # StripeMock - WIP
2
+
3
+ # This gem is Incomplete!
4
+
5
+ Only Transfers is fully stubbed out.
6
+
7
+ ### Setup for Stripe API version 2015-07-07
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'stripe_mock', require: false
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install stripe_mock
24
+
25
+ ## How does StripeMock work?
26
+
27
+ StripeMock uses Webmock to hijack the request to the Stripe servers and return the
28
+ corresponding Stripe response.
29
+
30
+ ### Setup
31
+
32
+ To capture requests to Strip simply add these lines to your spec file
33
+
34
+ ```ruby
35
+ before(:all) do
36
+ StripeMock.capture_requests
37
+ end
38
+ ```
39
+
40
+ ### Mocked Requests
41
+
42
+ To get a mocked response, just use the Stripe gem as you normally would.
43
+
44
+ ```ruby
45
+ Stipe::Transfer.all
46
+
47
+ # #<Stripe::ListObject:0x3fe634d74498> JSON: {
48
+ # "object": "list",
49
+ # "url": "/v1/transfers",
50
+ # "has_more": false,
51
+ # "data": [
52
+ # #<Stripe::Transfer id=tr_16DA2VCKrsNpguPAW93AVKPk 0x00000a> JSON: {
53
+ # "id": "tr_16DA2VCKrsNpguPAW93AVKPk",
54
+ # "object": "transfer",
55
+ # "created": 1434184255,
56
+ # "date": 1434240000,
57
+ # ...
58
+ # },
59
+ # #<Stripe::Transfer[...] ...>,
60
+ # #<Stripe::Transfer[...] ...>
61
+ # ]
62
+ # }
63
+ ```
64
+
65
+ ##### Getting Transfer Failure Codes
66
+
67
+ To get the transfer failure_code filled in, just use the desired failure_code as the id of the transfer. EX:
68
+
69
+ ```ruby
70
+ Stripe::Transfer.retrieve('insufficient_funds')
71
+ ```
72
+
73
+ All codes are listed here: [https://stripe.com/docs/api/ruby#transfer_failures](https://stripe.com/docs/api/ruby#transfer_failures)
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/digitalopera/stripe_mock.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stripe_mock"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require "stripe_mock/version"
2
+
3
+ require "stripe_mock/credit_cards/cards"
4
+
5
+ require "stripe_mock/data/bank_account"
6
+ require "stripe_mock/data/balance_transaction"
7
+ require "stripe_mock/data/cards"
8
+ require "stripe_mock/data/charges"
9
+ require "stripe_mock/data/transfers"
10
+ # require "stripe_mock/data/tokens"
11
+
12
+ require "stripe_mock/stripe_proxy"
13
+ require "stripe_mock/failures"
14
+ require "stripe_mock/utils"
15
+ require "stripe_mock/webmock"
16
+
17
+ module StripeMock
18
+ # Your code goes here...
19
+ end
@@ -0,0 +1,66 @@
1
+ module StripeMock
2
+ module CreditCards
3
+ class << self
4
+ BAD_CARDS = [
5
+ {
6
+ exp_month: '0',
7
+ code: :invalid_expiry_month
8
+ },
9
+ {
10
+ exp_year: '0',
11
+ code: :invalid_expiry_year
12
+ },
13
+ {
14
+ number: '4242424242424241',
15
+ code: :incorrect_number
16
+ },
17
+ {
18
+ number: '4000000000000002',
19
+ code: :card_declined
20
+ },
21
+ {
22
+ number: '4000000000000127',
23
+ code: :incorrect_cvc
24
+ },
25
+ {
26
+ number: '4000000000000119',
27
+ code: :processing_error
28
+ },
29
+ {
30
+ number: 'asdf',
31
+ code: :invalid_number
32
+ },
33
+ {
34
+ cvc: '0',
35
+ code: :invalid_cvc
36
+ }
37
+ ]
38
+
39
+ def card_number_by_code(code)
40
+ attr_value_by_code(:number, code)
41
+ end
42
+
43
+ def attr_value_by_code(type, code)
44
+ BAD_CARDS.detect do |hash|
45
+ code == hash[:code]
46
+ end[type.to_sym]
47
+ end
48
+
49
+ def is_erroneous?(card_hash)
50
+ !card_error(card_hash).nil?
51
+ end
52
+
53
+ def card_error(card_hash)
54
+ hash = BAD_CARDS.detect do |hash|
55
+ hash.keys.any? do |key|
56
+ !card_hash[key].nil? && card_hash[key] == hash[key]
57
+ end
58
+ end
59
+
60
+ unless hash.nil?
61
+ StripeMock.card_failures[hash[:code]]
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,59 @@
1
+ module StripeMock
2
+ module Data
3
+ def self.balance_transaction(params={})
4
+ source_id = params[:source] || StripeMock.new_id('tr')
5
+ {
6
+ id: StripeMock.new_id('txn'),
7
+ object: 'balance_transaction',
8
+ amount: -18982,
9
+ currency: 'usd',
10
+ net: -18982,
11
+ type: 'transfer',
12
+ created: Faker::Date.backward(2).to_time.to_i,
13
+ available_on: Faker::Date.backward(1).to_time.to_i,
14
+ status: 'available',
15
+ fee: 0,
16
+ fee_details: [],
17
+ source: source_id,
18
+ description: 'STRIPE TRANSFER',
19
+ sourced_transfers: {
20
+ object: 'list',
21
+ total_count: 0,
22
+ has_more: false,
23
+ url: "/v1/transfers?source_transaction=#{ source_id }",
24
+ data: []
25
+ }
26
+ }.merge(params)
27
+ end
28
+
29
+ def self.balance_transactions(params={})
30
+ {
31
+ object: 'list',
32
+ url: '/v1/balance/history',
33
+ has_more: false,
34
+ data: [balance_transaction, balance_transaction({
35
+ type: 'charge',
36
+ amount: 37621,
37
+ net: 36000,
38
+ fee: 1621,
39
+ fee_details: [
40
+ {
41
+ amount: 1121,
42
+ currency: "usd",
43
+ type: "stripe_fee",
44
+ description: "Stripe processing fees",
45
+ application: nil
46
+ },
47
+ {
48
+ amount: 500,
49
+ currency: "usd",
50
+ type: "application_fee",
51
+ description: "MY APP application fee",
52
+ application: "ca_xxx"
53
+ }
54
+ ]
55
+ })]
56
+ }.merge(params)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,17 @@
1
+ module StripeMock
2
+ module Data
3
+ def self.bank_account(params={})
4
+ {
5
+ object: 'bank_account',
6
+ id: StripeMock.new_id('ba'),
7
+ last4: '6789',
8
+ country: 'US',
9
+ currency: 'usd',
10
+ status: 'new',
11
+ fingerprint: nil,
12
+ routing_number: Faker::Number.number(9).to_s,
13
+ bank_name: 'STRIPE TEST BANK'
14
+ }.merge(params)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module StripeMock
2
+ module Data
3
+ def self.card(params={})
4
+ {
5
+ id: StripeMock.new_id('card'),
6
+ object: "card",
7
+ last4: Faker::Number.number(4).to_s,
8
+ brand: "Visa",
9
+ funding: "credit",
10
+ exp_month: Faker::Number.between(1, 12),
11
+ exp_year: (Date.today.year + 1),
12
+ fingerprint: Faker::Internet.password(16),
13
+ country: "US",
14
+ name: Faker::Name.name,
15
+ address_line1: Faker::Address.street_address,
16
+ address_line2: nil,
17
+ address_city: Faker::Address.city,
18
+ address_state: Faker::Address.state_abbr,
19
+ address_zip: Faker::Address.postcode,
20
+ address_country: nil,
21
+ cvc_check: 'pass',
22
+ address_line1_check: 'pass',
23
+ address_zip_check: 'pass',
24
+ tokenization_method: nil,
25
+ dynamic_last4: nil,
26
+ metadata: {}
27
+ }.merge(params)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ module StripeMock
2
+ module Data
3
+ def self.charge(params={})
4
+ id = params[:id] || StripeMock.new_id('ch')
5
+
6
+ {
7
+ id: id,
8
+ object: "charge",
9
+ created: Faker::Date.backward(2).to_time.to_i,
10
+ livemode: false,
11
+ paid: true,
12
+ status: 'succeeded',
13
+ amount: Faker::Number.number(4),
14
+ currency: "usd",
15
+ refunded: false,
16
+ source: StripeMock::Data.card,
17
+ captured: true,
18
+ balance_transaction: StripeMock.new_id('txn'),
19
+ failure_message: nil,
20
+ failure_code: nil,
21
+ amount_refunded: 0,
22
+ customer: nil,
23
+ invoice: nil,
24
+ description: "For items ordered on my kick ass app",
25
+ dispute: nil,
26
+ metadata: {},
27
+ statement_descriptor: 'MY APP',
28
+ fraud_details: {},
29
+ receipt_email: nil,
30
+ shipping: nil,
31
+ destination: nil,
32
+ application_fee: nil,
33
+ refunds: {
34
+ object: "list",
35
+ total_count: 0,
36
+ has_more: false,
37
+ url: "/v1/charges/#{ id }/refunds",
38
+ data: []
39
+ }
40
+ }.merge(params)
41
+ end
42
+
43
+ def self.charges(params={})
44
+ {
45
+ object: 'list',
46
+ url: '/v1/charges',
47
+ has_more: false,
48
+ data: [charge, charge]
49
+ }.merge(params)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ module StripeMock
2
+ module Data
3
+ def self.token(params={})
4
+ {
5
+ id: StripeMock.new_id('tok'),
6
+ livemode: false,
7
+ created: Faker::Date.backward(2).to_time.to_i,
8
+ used: false,
9
+ object: "token",
10
+ type: 'card',
11
+ card: StripeMock::Data.card,
12
+ client_ip: nil
13
+ }.merge(params)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,49 @@
1
+ module StripeMock
2
+ module Data
3
+ def self.transfer(params={})
4
+ id = params[:id] || StripeMock.new_id('tr')
5
+ bank_account_id = StripeMock.new_id('ba')
6
+
7
+ {
8
+ id: id,
9
+ object: "transfer",
10
+ created: Faker::Date.backward(2).to_time.to_i,
11
+ date: Date.today.to_time.to_i,
12
+ livemode: false,
13
+ amount: 100,
14
+ currency: "usd",
15
+ reversed: false,
16
+ status: 'paid',
17
+ type: 'bank_account',
18
+ reversals: {
19
+ object: "list",
20
+ total_count: 0,
21
+ has_more: false,
22
+ url: "/v1/transfers/#{id}/reversals",
23
+ data: []
24
+ },
25
+ balance_transaction: StripeMock.new_id('txn'),
26
+ bank_account: StripeMock::Data.bank_account(id: bank_account_id),
27
+ destination: bank_account_id,
28
+ description: 'STRIPE TRANSFER',
29
+ failure_message: nil,
30
+ failure_code: nil,
31
+ amount_reversed: 0,
32
+ metadata: {},
33
+ statement_descriptor: nil,
34
+ recipient: nil,
35
+ source_transaction: nil,
36
+ application_fee: nil
37
+ }.merge(params)
38
+ end
39
+
40
+ def self.transfers(params={})
41
+ {
42
+ object: 'list',
43
+ url: '/v1/transfers',
44
+ has_more: false,
45
+ data: [transfer, transfer]
46
+ }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,86 @@
1
+ module StripeMock
2
+ class << self
3
+ def transfer_failures
4
+ %w(insufficient_funds account_closed no_account invalid_account_number debit_not_authorized bank_ownership_changed account_frozen could_not_process bank_account_restricted invalid_currency)
5
+ end
6
+
7
+ def card_failures
8
+ {
9
+ incorrect_number: {
10
+ message: "Your card number is incorrect.",
11
+ code: 'incorrect_number',
12
+ param: 'number',
13
+ type: 'card_error'
14
+ },
15
+ invalid_number: {
16
+ message: "This card number looks invalid.",
17
+ code: 'invalid_number',
18
+ param: 'number',
19
+ type: 'card_error'
20
+ },
21
+ invalid_expiry_month: {
22
+ message: "Your card's expiration month is invalid.",
23
+ code: 'invalid_expiry_month',
24
+ param: 'exp_month',
25
+ type: 'card_error'
26
+ },
27
+ invalid_expiry_year: {
28
+ message: "Your card's expiration year is invalid.",
29
+ code: 'invalid_expiry_year',
30
+ param: 'exp_year',
31
+ type: 'card_error'
32
+ },
33
+ invalid_cvc: {
34
+ message: "Your card's security code is invalid.",
35
+ code: 'invalid_cvc',
36
+ param: 'cvc',
37
+ type: 'card_error'
38
+ },
39
+ expired_card_month: {
40
+ message: "Your card's expiration month is invalid.",
41
+ code: 'invalid_expiry_month',
42
+ param: 'exp_month',
43
+ type: 'card_error'
44
+ },
45
+ expired_card_year: {
46
+ message: "Your card's expiration year is invalid.",
47
+ code: 'invalid_expiry_year',
48
+ param: 'exp_year',
49
+ type: 'card_error'
50
+ },
51
+ incorrect_cvc: {
52
+ message: "Your card's security code is incorrect.",
53
+ code: 'incorrect_cvc',
54
+ param: 'cvc',
55
+ type: 'card_error',
56
+ charge: 'ch_xxx'
57
+ },
58
+ incorrect_zip: {
59
+ message: "The zip code you supplied failed validation.",
60
+ code: 'incorrect_zip',
61
+ param: 'address_zip',
62
+ type: 'card_error',
63
+ charge: 'ch_xxx'
64
+ },
65
+ card_declined: {
66
+ message: "Your card was declined.",
67
+ code: 'card_declined',
68
+ type: 'card_error',
69
+ charge: 'ch_xxx'
70
+ },
71
+ missing: {
72
+ message: "Cannot charge a customer that has no active card",
73
+ code: 'missing',
74
+ param: 'card',
75
+ type: 'card_error'
76
+ },
77
+ processing_error: {
78
+ message: "An error occurred while processing your card. Try again in a little bit.",
79
+ code: 'processing_error',
80
+ type: 'card_error',
81
+ charge: 'ch_xxx'
82
+ }
83
+ }
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,85 @@
1
+ require 'sinatra/base'
2
+ require 'json'
3
+
4
+ class MockedStripe < Sinatra::Base
5
+
6
+ #== TOKENS ===================================================================
7
+ # get "/v1/tokens" do
8
+ # # json_response StripeMock::Data::charges
9
+ # end
10
+ #
11
+ # get "/v1/tokens/:id" do
12
+ # json_response StripeMock::Data::token id: params[:id]
13
+ # end
14
+ #
15
+ # post '/v1/tokens' do
16
+ # if StripeMock::CreditCards.is_erroneous?(params[:card])
17
+ # status 402
18
+ # card_error = StripeMock::CreditCards.card_error(params[:card])
19
+ #
20
+ # json_response({
21
+ # error: card_error
22
+ # })
23
+ # else
24
+ # json_response StripeMock::Data::token
25
+ # end
26
+ # end
27
+ #
28
+ # #== CHARGES ==================================================================
29
+ # get "/v1/charges" do
30
+ # json_response StripeMock::Data::charges
31
+ # end
32
+
33
+ get "/v1/charges/:id" do
34
+ json_response StripeMock::Data::charge id: params[:id]
35
+ end
36
+
37
+ # post '/v1/charges' do
38
+ # matches = /tok_(\S+)/.match params[:source]
39
+ # if !matches.nil? && !matches[1].nil?
40
+ # status 402
41
+ # card_error = StripeMock.charge_failures[matches[1].to_sym]
42
+ #
43
+ # json_response({
44
+ # error: {
45
+ # message: card_error[:message],
46
+ # param: card_error[:param]
47
+ # }
48
+ # })
49
+ # else
50
+ # json_response StripeMock::Data::charge
51
+ # end
52
+ # end
53
+
54
+ #== BALANCE TRANSACTIONS =====================================================
55
+ get "/v1/balance/history" do
56
+ json_response StripeMock::Data::balance_transactions
57
+ end
58
+
59
+ #== TRANSFERS ================================================================
60
+ get "/v1/transfers" do
61
+ json_response StripeMock::Data::transfers
62
+ end
63
+
64
+ get "/v1/transfers/:id" do
65
+ transfer_overrides = {
66
+ id: params[:id]
67
+ }
68
+
69
+ if StripeMock.transfer_failures.include?( params[:id] )
70
+ transfer_overrides[:failure_code] = params[:id]
71
+ end
72
+ json_response StripeMock::Data::transfer transfer_overrides
73
+ end
74
+
75
+ post '/v1/transfers' do
76
+ json_response StripeMock::Data::transfer
77
+ end
78
+
79
+ private #---------------------------------------------------------------------
80
+
81
+ def json_response(hash)
82
+ content_type :json
83
+ hash.to_json
84
+ end
85
+ end
@@ -0,0 +1,5 @@
1
+ module StripeMock
2
+ def self.new_id(prefix)
3
+ "#{ prefix }_#{ Faker::Internet.password(16) }"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module StripeMock
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ module StripeMock
2
+ def self.capture_requests
3
+ require 'webmock'
4
+
5
+ WebMock.allow_net_connect!
6
+ WebMock::API.stub_request(:any, /https:\/\/api\.stripe\.com/).to_rack(MockedStripe)
7
+ end
8
+
9
+ def self.stop_capturing
10
+ WebMock.reset!
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stripe_mock/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stripe_mock"
8
+ spec.version = StripeMock::VERSION
9
+ spec.authors = ["Grant Klinsing"]
10
+ spec.email = ["grant@digitalopera.com"]
11
+
12
+ spec.summary = %q{Mocking Library for Stripe}
13
+ spec.description = %q{Mimic Stripe calls without hitting Stripe's servers}
14
+ spec.homepage = "https://github.com/digitalopera/stripe_mock"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'sinatra', '~> 1.4.6'
23
+ spec.add_dependency 'webmock', '~> 1.20.0'
24
+ spec.add_dependency "json", '~> 1.8.3'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.1.0"
29
+ spec.add_development_dependency "guard-rspec", "~> 4.6.0"
30
+ spec.add_development_dependency "faker", "~> 1.4.3"
31
+ spec.add_development_dependency "stripe", "~> 1.23.0"
32
+ spec.add_development_dependency "dotenv-rails", "~> 2.0.2"
33
+ spec.add_development_dependency "vcr", "~> 2.9.3"
34
+ end
metadata ADDED
@@ -0,0 +1,222 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stripe_mock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Grant Klinsing
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.20.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.20.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.6.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.6.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: faker
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.4.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.4.3
125
+ - !ruby/object:Gem::Dependency
126
+ name: stripe
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.23.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.23.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: dotenv-rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.0.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.0.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: vcr
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 2.9.3
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 2.9.3
167
+ description: Mimic Stripe calls without hitting Stripe's servers
168
+ email:
169
+ - grant@digitalopera.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".travis.yml"
177
+ - Gemfile
178
+ - Guardfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/setup
184
+ - lib/stripe_mock.rb
185
+ - lib/stripe_mock/credit_cards/cards.rb
186
+ - lib/stripe_mock/data/balance_transaction.rb
187
+ - lib/stripe_mock/data/bank_account.rb
188
+ - lib/stripe_mock/data/cards.rb
189
+ - lib/stripe_mock/data/charges.rb
190
+ - lib/stripe_mock/data/tokens.rb
191
+ - lib/stripe_mock/data/transfers.rb
192
+ - lib/stripe_mock/failures.rb
193
+ - lib/stripe_mock/stripe_proxy.rb
194
+ - lib/stripe_mock/utils.rb
195
+ - lib/stripe_mock/version.rb
196
+ - lib/stripe_mock/webmock.rb
197
+ - stripe_mock.gemspec
198
+ homepage: https://github.com/digitalopera/stripe_mock
199
+ licenses:
200
+ - MIT
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubyforge_project:
218
+ rubygems_version: 2.4.8
219
+ signing_key:
220
+ specification_version: 4
221
+ summary: Mocking Library for Stripe
222
+ test_files: []