stripe-ruby-mock 1.8.4.9 → 1.8.4.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +20 -11
- data/lib/stripe_mock/api/bank_tokens.rb +13 -0
- data/lib/stripe_mock/client.rb +4 -0
- data/lib/stripe_mock/data.rb +27 -1
- data/lib/stripe_mock/instance.rb +34 -1
- data/lib/stripe_mock/request_handlers/cards.rb +37 -0
- data/lib/stripe_mock/request_handlers/charges.rb +6 -0
- data/lib/stripe_mock/request_handlers/customers.rb +14 -8
- data/lib/stripe_mock/request_handlers/recipients.rb +26 -0
- data/lib/stripe_mock/server.rb +4 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock.rb +3 -0
- data/spec/shared_stripe_examples/bank_token_examples.rb +40 -0
- data/spec/shared_stripe_examples/card_examples.rb +54 -0
- data/spec/shared_stripe_examples/charge_examples.rb +14 -0
- data/spec/shared_stripe_examples/customer_examples.rb +5 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +62 -0
- data/spec/support/stripe_examples.rb +7 -0
- metadata +12 -2
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# stripe-ruby-mock
|
1
|
+
# stripe-ruby-mock [![Build Status](https://travis-ci.org/rebelidealist/stripe-ruby-mock.png?branch=master)](https://travis-ci.org/rebelidealist/stripe-ruby-mock)
|
2
2
|
|
3
3
|
* Homepage: https://github.com/rebelidealist/stripe-ruby-mock
|
4
4
|
* Issues: https://github.com/rebelidealist/stripe-ruby-mock/issues
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
In your gemfile:
|
9
9
|
|
10
|
-
gem 'stripe-ruby-mock', '>= 1.8.4.
|
10
|
+
gem 'stripe-ruby-mock', '>= 1.8.4.10'
|
11
11
|
|
12
12
|
## Features
|
13
13
|
|
@@ -17,7 +17,7 @@ In your gemfile:
|
|
17
17
|
|
18
18
|
## Description
|
19
19
|
|
20
|
-
** *WARNING:
|
20
|
+
** *WARNING: This library does not cover all Stripe API endpoints. If you need one that's missing, please create an issue for it.* **
|
21
21
|
|
22
22
|
At its core, this library overrides [stripe-ruby's](https://github.com/stripe/stripe-ruby)
|
23
23
|
request method to skip all http calls and
|
@@ -191,16 +191,21 @@ end
|
|
191
191
|
By default, StripeMock searches in your `spec/fixtures/stripe_webhooks/` folder for your own, custom webhooks.
|
192
192
|
If it finds nothing, it falls back to [test events generated through stripe's webhooktester](lib/stripe_mock/webhook_fixtures/).
|
193
193
|
|
194
|
-
|
194
|
+
For example, you could create a file in `spec/fixtures/stripe_webhooks/invoice.created.with-sub.json`, copy/paste the default from [the default invoice.created.json](lib/stripe_mock/webhook_fixtures/invoice.created.json), and customize it to your needs.
|
195
195
|
|
196
|
-
|
196
|
+
Then you can use that webook directly in your specs:
|
197
197
|
|
198
|
-
|
198
|
+
```ruby
|
199
|
+
it "can use a custom webhook fixture" do
|
200
|
+
event = StripeMock.mock_webhook_event('invoice.created.with-sub')
|
201
|
+
# etc.
|
202
|
+
end
|
203
|
+
```
|
199
204
|
|
200
|
-
|
205
|
+
You can alse override values on the fly:
|
201
206
|
|
202
207
|
```ruby
|
203
|
-
it "can override
|
208
|
+
it "can override webhook values" do
|
204
209
|
# NOTE: given hash values get merged directly into event.data.object
|
205
210
|
event = StripeMock.mock_webhook_event('customer.created', {
|
206
211
|
:id => 'cus_my_custom_value',
|
@@ -214,6 +219,12 @@ it "can override default webhook values" do
|
|
214
219
|
end
|
215
220
|
```
|
216
221
|
|
222
|
+
You can name events whatever you like in your `spec/fixtures/stripe_webhooks/` folder. However, if you try to call a non-standard event that's doesn't exist in that folder, StripeMock will throw an error.
|
223
|
+
|
224
|
+
If you wish to use a different fixture path, you can set it yourself:
|
225
|
+
|
226
|
+
StripeMock.webhook_fixture_path = './spec/other/folder/'
|
227
|
+
|
217
228
|
## Generating Card Tokens
|
218
229
|
|
219
230
|
Sometimes you need to check if your code reads a stripe card correctly. If so, you can specifically
|
@@ -244,9 +255,7 @@ If you always want debug to be on (it's quite verbose), you should put this in a
|
|
244
255
|
## TODO
|
245
256
|
|
246
257
|
* Cover all stripe urls/methods
|
247
|
-
*
|
248
|
-
* Currently implemented for: **Customers**, **Charges**, and **Plans**
|
249
|
-
* Throw useful errors that emulate Stripe's
|
258
|
+
* Throw useful errors that emulate Stripe's requirements
|
250
259
|
* For example: "You must supply either a card or a customer id" for `Stripe::Charge`
|
251
260
|
|
252
261
|
## Developing stripe-ruby-mock
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module StripeMock
|
2
|
+
|
3
|
+
def self.generate_bank_token(bank_params)
|
4
|
+
if @state == 'local'
|
5
|
+
instance.generate_bank_token(bank_params)
|
6
|
+
elsif @state == 'remote'
|
7
|
+
client.generate_bank_token(bank_params)
|
8
|
+
else
|
9
|
+
raise UnstartedStateError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/lib/stripe_mock/client.rb
CHANGED
@@ -48,6 +48,10 @@ module StripeMock
|
|
48
48
|
timeout_wrap { @pipe.strict? }
|
49
49
|
end
|
50
50
|
|
51
|
+
def generate_bank_token(recipient_params)
|
52
|
+
timeout_wrap { @pipe.generate_bank_token(recipient_params) }
|
53
|
+
end
|
54
|
+
|
51
55
|
def generate_card_token(card_params)
|
52
56
|
timeout_wrap { @pipe.generate_card_token(card_params) }
|
53
57
|
end
|
data/lib/stripe_mock/data.rb
CHANGED
@@ -67,6 +67,21 @@ module StripeMock
|
|
67
67
|
}.merge(params)
|
68
68
|
end
|
69
69
|
|
70
|
+
def self.mock_refund(params={})
|
71
|
+
mock_charge.merge({
|
72
|
+
refunded: true,
|
73
|
+
refunds: [
|
74
|
+
{
|
75
|
+
amount: params[:amount],
|
76
|
+
currency: "usd",
|
77
|
+
created: 1380208998,
|
78
|
+
object: "refund",
|
79
|
+
balance_transaction: "txn_2dyYXXP90MN26R"
|
80
|
+
}
|
81
|
+
]
|
82
|
+
})
|
83
|
+
end
|
84
|
+
|
70
85
|
def self.mock_charge_array
|
71
86
|
{
|
72
87
|
:data => [test_charge, test_charge, test_charge],
|
@@ -99,6 +114,18 @@ module StripeMock
|
|
99
114
|
}.merge(params)
|
100
115
|
end
|
101
116
|
|
117
|
+
def self.mock_bank_account(params={})
|
118
|
+
{
|
119
|
+
object: "bank_account",
|
120
|
+
bank_name: "STRIPEMOCK TEST BANK",
|
121
|
+
last4: "6789",
|
122
|
+
country: "US",
|
123
|
+
currency: "usd",
|
124
|
+
validated: false,
|
125
|
+
fingerprint: "aBcFinGerPrINt123"
|
126
|
+
}.merge(params)
|
127
|
+
end
|
128
|
+
|
102
129
|
def self.mock_coupon(params={})
|
103
130
|
{
|
104
131
|
:duration => 'repeating',
|
@@ -312,6 +339,5 @@ module StripeMock
|
|
312
339
|
:id => "di_test_coupon"
|
313
340
|
}
|
314
341
|
end
|
315
|
-
|
316
342
|
end
|
317
343
|
end
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -16,18 +16,23 @@ module StripeMock
|
|
16
16
|
end
|
17
17
|
|
18
18
|
include StripeMock::RequestHandlers::Charges
|
19
|
+
include StripeMock::RequestHandlers::Cards
|
19
20
|
include StripeMock::RequestHandlers::Customers
|
20
21
|
include StripeMock::RequestHandlers::InvoiceItems
|
21
22
|
include StripeMock::RequestHandlers::Plans
|
23
|
+
include StripeMock::RequestHandlers::Recipients
|
22
24
|
|
23
25
|
|
24
|
-
attr_reader :charges, :customers, :plans, :error_queue
|
26
|
+
attr_reader :charges, :customers, :plans, :error_queue, :recipients
|
27
|
+
attr_reader :bank_tokens
|
25
28
|
attr_accessor :debug, :strict
|
26
29
|
|
27
30
|
def initialize
|
28
31
|
@customers = {}
|
32
|
+
@recipients = {}
|
29
33
|
@charges = {}
|
30
34
|
@plans = {}
|
35
|
+
@bank_tokens = {}
|
31
36
|
@card_tokens = {}
|
32
37
|
|
33
38
|
@id_counter = 0
|
@@ -65,6 +70,12 @@ module StripeMock
|
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
73
|
+
def generate_bank_token(bank_params)
|
74
|
+
token = new_id 'btok'
|
75
|
+
@bank_tokens[token] = Data.mock_bank_account(bank_params)
|
76
|
+
token
|
77
|
+
end
|
78
|
+
|
68
79
|
def generate_card_token(card_params)
|
69
80
|
token = new_id 'tok'
|
70
81
|
card_params[:id] = new_id 'cc'
|
@@ -72,6 +83,14 @@ module StripeMock
|
|
72
83
|
token
|
73
84
|
end
|
74
85
|
|
86
|
+
def get_bank_by_token(token)
|
87
|
+
if token.nil? || @bank_tokens[token].nil?
|
88
|
+
Data.mock_bank_account
|
89
|
+
else
|
90
|
+
@bank_tokens.delete(token)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
75
94
|
def get_card_by_token(token)
|
76
95
|
if token.nil? || @card_tokens[token].nil?
|
77
96
|
Data.mock_card :id => new_id('cc')
|
@@ -80,6 +99,20 @@ module StripeMock
|
|
80
99
|
end
|
81
100
|
end
|
82
101
|
|
102
|
+
def add_card_to_customer(card, cus)
|
103
|
+
card[:customer] = cus[:id]
|
104
|
+
|
105
|
+
if cus[:cards][:count] == 0
|
106
|
+
cus[:cards][:count] += 1
|
107
|
+
else
|
108
|
+
cus[:cards][:data].delete_if {|card| card[:id] == cus[:default_card]}
|
109
|
+
end
|
110
|
+
|
111
|
+
cus[:cards][:data] << card
|
112
|
+
|
113
|
+
card
|
114
|
+
end
|
115
|
+
|
83
116
|
private
|
84
117
|
|
85
118
|
def assert_existance(type, id, obj, message=nil)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Cards
|
4
|
+
|
5
|
+
def Cards.included(klass)
|
6
|
+
klass.add_handler 'post /v1/customers/(.*)/cards', :create_card
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_card(route, method_url, params, headers)
|
10
|
+
route =~ method_url
|
11
|
+
|
12
|
+
customer = customers[$1]
|
13
|
+
assert_existance :customer, $1, customer
|
14
|
+
|
15
|
+
card = card_from_params(params[:card])
|
16
|
+
add_card_to_customer(card, customer)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def validate_card(card)
|
22
|
+
[:exp_month, :exp_year].each do |field|
|
23
|
+
card[field] = card[field].to_i
|
24
|
+
end
|
25
|
+
card
|
26
|
+
end
|
27
|
+
|
28
|
+
def card_from_params(attrs_or_token)
|
29
|
+
if attrs_or_token.is_a? Hash
|
30
|
+
attrs_or_token = generate_card_token(attrs_or_token)
|
31
|
+
end
|
32
|
+
card = get_card_by_token(attrs_or_token)
|
33
|
+
validate_card(card)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -6,6 +6,7 @@ module StripeMock
|
|
6
6
|
klass.add_handler 'post /v1/charges', :new_charge
|
7
7
|
klass.add_handler 'get /v1/charges/(.*)', :get_charge
|
8
8
|
klass.add_handler 'post /v1/charges/(.*)/capture', :capture_charge
|
9
|
+
klass.add_handler 'post /v1/charges/(.*)/refund', :refund_charge
|
9
10
|
end
|
10
11
|
|
11
12
|
def new_charge(route, method_url, params, headers)
|
@@ -28,6 +29,11 @@ module StripeMock
|
|
28
29
|
charge
|
29
30
|
end
|
30
31
|
|
32
|
+
def refund_charge(route, method_url, params, headers)
|
33
|
+
route =~ method_url
|
34
|
+
charge = Data.mock_refund(params)
|
35
|
+
end
|
36
|
+
|
31
37
|
end
|
32
38
|
end
|
33
39
|
end
|
@@ -8,6 +8,7 @@ module StripeMock
|
|
8
8
|
klass.add_handler 'delete /v1/customers/(.*)/subscription', :cancel_subscription
|
9
9
|
klass.add_handler 'post /v1/customers/(.*)', :update_customer
|
10
10
|
klass.add_handler 'get /v1/customers/(.*)', :get_customer
|
11
|
+
klass.add_handler 'delete /v1/customers/(.*)', :delete_customer
|
11
12
|
klass.add_handler 'get /v1/customers', :list_customers
|
12
13
|
end
|
13
14
|
|
@@ -65,20 +66,25 @@ module StripeMock
|
|
65
66
|
|
66
67
|
if params[:card]
|
67
68
|
new_card = get_card_by_token(params.delete(:card))
|
68
|
-
|
69
|
-
if cus[:cards][:count] == 0
|
70
|
-
cus[:cards][:count] += 1
|
71
|
-
else
|
72
|
-
cus[:cards][:data].delete_if {|card| card[:id] == cus[:default_card]}
|
73
|
-
end
|
74
|
-
|
75
|
-
cus[:cards][:data] << new_card
|
69
|
+
add_card_to_customer(new_card, cus)
|
76
70
|
cus[:default_card] = new_card[:id]
|
77
71
|
end
|
78
72
|
|
79
73
|
cus
|
80
74
|
end
|
81
75
|
|
76
|
+
def delete_customer(route, method_url, params, headers)
|
77
|
+
route =~ method_url
|
78
|
+
assert_existance :customer, $1, customers[$1]
|
79
|
+
|
80
|
+
customers[$1] = {
|
81
|
+
id: customers[$1][:id],
|
82
|
+
deleted: true
|
83
|
+
}
|
84
|
+
|
85
|
+
customers[$1]
|
86
|
+
end
|
87
|
+
|
82
88
|
def get_customer(route, method_url, params, headers)
|
83
89
|
route =~ method_url
|
84
90
|
assert_existance :customer, $1, customers[$1]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Recipients
|
4
|
+
|
5
|
+
def Recipients.included(klass)
|
6
|
+
klass.add_handler 'post /v1/recipients', :new_recipient
|
7
|
+
klass.add_handler 'get /v1/recipients/(.*)', :get_recipient
|
8
|
+
end
|
9
|
+
|
10
|
+
def new_recipient(route, method_url, params, headers)
|
11
|
+
id = new_id('rp')
|
12
|
+
if params[:bank_account]
|
13
|
+
params[:active_account] = get_bank_by_token(params.delete(:bank_account))
|
14
|
+
end
|
15
|
+
recipients[id] = Data.mock_recipient(params.merge :id => id)
|
16
|
+
recipients[id]
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_recipient(route, method_url, params, headers)
|
20
|
+
route =~ method_url
|
21
|
+
assert_existance :recipient, $1, recipients[$1]
|
22
|
+
recipients[$1] ||= Data.mock_recipient(:id => $1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/stripe_mock/server.rb
CHANGED
@@ -50,6 +50,10 @@ module StripeMock
|
|
50
50
|
@instance.generate_card_token(card_params)
|
51
51
|
end
|
52
52
|
|
53
|
+
def generate_bank_token(recipient_params)
|
54
|
+
@instance.generate_bank_token(recipient_params)
|
55
|
+
end
|
56
|
+
|
53
57
|
def debug?; @instance.debug; end
|
54
58
|
def strict?; @instance.strict; end
|
55
59
|
def ping; true; end
|
data/lib/stripe_mock/version.rb
CHANGED
data/lib/stripe_mock.rb
CHANGED
@@ -23,15 +23,18 @@ require 'stripe_mock/api/instance'
|
|
23
23
|
require 'stripe_mock/api/client'
|
24
24
|
require 'stripe_mock/api/server'
|
25
25
|
require 'stripe_mock/api/card_tokens'
|
26
|
+
require 'stripe_mock/api/bank_tokens'
|
26
27
|
require 'stripe_mock/api/errors'
|
27
28
|
require 'stripe_mock/api/webhooks'
|
28
29
|
require 'stripe_mock/api/strict'
|
29
30
|
require 'stripe_mock/api/debug'
|
30
31
|
|
31
32
|
require 'stripe_mock/request_handlers/charges.rb'
|
33
|
+
require 'stripe_mock/request_handlers/cards.rb'
|
32
34
|
require 'stripe_mock/request_handlers/customers.rb'
|
33
35
|
require 'stripe_mock/request_handlers/invoice_items.rb'
|
34
36
|
require 'stripe_mock/request_handlers/plans.rb'
|
37
|
+
require 'stripe_mock/request_handlers/recipients.rb'
|
35
38
|
require 'stripe_mock/instance'
|
36
39
|
|
37
40
|
module StripeMock
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Bank Account Token Mocking' do
|
4
|
+
|
5
|
+
it "generates a bank token with an associated account in memory" do
|
6
|
+
bank_token = StripeMock.generate_bank_token(
|
7
|
+
:bank_name => "Memory Bank",
|
8
|
+
:last4 => "7171"
|
9
|
+
)
|
10
|
+
tokens = test_data_source(:bank_tokens)
|
11
|
+
expect(tokens[bank_token]).to_not be_nil
|
12
|
+
expect(tokens[bank_token][:bank_name]).to eq("Memory Bank")
|
13
|
+
expect(tokens[bank_token][:last4]).to eq("7171")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates a token whose id begins with test_btok" do
|
17
|
+
bank_token = StripeMock.generate_bank_token({
|
18
|
+
:last4 => "1212"
|
19
|
+
})
|
20
|
+
expect(bank_token).to match /^test_btok/
|
21
|
+
end
|
22
|
+
|
23
|
+
it "assigns the generated bank account to a new recipient" do
|
24
|
+
bank_token = StripeMock.generate_bank_token(
|
25
|
+
:bank_name => "Bank Token Mocking",
|
26
|
+
:last4 => "7777"
|
27
|
+
)
|
28
|
+
|
29
|
+
recipient = Stripe::Recipient.create({
|
30
|
+
name: "Fred Flinstone",
|
31
|
+
type: "individual",
|
32
|
+
email: 'blah@domain.co',
|
33
|
+
bank_account: bank_token
|
34
|
+
})
|
35
|
+
expect(recipient.active_account.last4).to eq("7777")
|
36
|
+
expect(recipient.active_account.bank_name).to eq("Bank Token Mocking")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Card API' do
|
4
|
+
it 'creates/returns a card when using customer.cards.create given a card token' do
|
5
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
6
|
+
card_token = StripeMock.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
7
|
+
card = customer.cards.create(card: card_token)
|
8
|
+
|
9
|
+
expect(card.customer).to eq('test_customer_sub')
|
10
|
+
expect(card.last4).to eq("1123")
|
11
|
+
expect(card.exp_month).to eq(11)
|
12
|
+
expect(card.exp_year).to eq(2099)
|
13
|
+
|
14
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
15
|
+
expect(customer.cards.count).to eq(1)
|
16
|
+
card = customer.cards.data.first
|
17
|
+
expect(card.customer).to eq('test_customer_sub')
|
18
|
+
expect(card.last4).to eq("1123")
|
19
|
+
expect(card.exp_month).to eq(11)
|
20
|
+
expect(card.exp_year).to eq(2099)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'creates/returns a card when using customer.cards.create given card params' do
|
24
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
25
|
+
card = customer.cards.create(card: {
|
26
|
+
number: '4242424242424242',
|
27
|
+
exp_month: '11',
|
28
|
+
exp_year: '3031',
|
29
|
+
cvc: '123'
|
30
|
+
})
|
31
|
+
|
32
|
+
expect(card.customer).to eq('test_customer_sub')
|
33
|
+
expect(card.last4).to eq("4242")
|
34
|
+
expect(card.exp_month).to eq(11)
|
35
|
+
expect(card.exp_year).to eq(3031)
|
36
|
+
|
37
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
38
|
+
expect(customer.cards.count).to eq(1)
|
39
|
+
card = customer.cards.data.first
|
40
|
+
expect(card.customer).to eq('test_customer_sub')
|
41
|
+
expect(card.last4).to eq("4242")
|
42
|
+
expect(card.exp_month).to eq(11)
|
43
|
+
expect(card.exp_year).to eq(3031)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'create does not change the customers default card' do
|
47
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
48
|
+
card_token = StripeMock.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
49
|
+
card = customer.cards.create(card: card_token)
|
50
|
+
|
51
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
52
|
+
expect(customer.default_card).to be_nil
|
53
|
+
end
|
54
|
+
end
|
@@ -120,4 +120,18 @@ shared_examples 'Charge API' do
|
|
120
120
|
expect(returned_charge.captured).to be_true
|
121
121
|
end
|
122
122
|
end
|
123
|
+
|
124
|
+
it "refunds a stripe charge item" do
|
125
|
+
charge = Stripe::Charge.create(
|
126
|
+
amount: 999,
|
127
|
+
currency: 'USD',
|
128
|
+
card: 'card_token_abcde',
|
129
|
+
description: 'card charge'
|
130
|
+
)
|
131
|
+
|
132
|
+
charge = charge.refund(amount: 999)
|
133
|
+
|
134
|
+
expect(charge.refunded).to eq(true)
|
135
|
+
expect(charge.refunds.first.amount).to eq(999)
|
136
|
+
end
|
123
137
|
end
|
@@ -197,6 +197,11 @@ shared_examples 'Customer API' do
|
|
197
197
|
}.to raise_error Stripe::InvalidRequestError
|
198
198
|
end
|
199
199
|
|
200
|
+
it "deletes a customer" do
|
201
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
202
|
+
customer = customer.delete
|
203
|
+
expect(customer.deleted).to be_true
|
204
|
+
end
|
200
205
|
|
201
206
|
context "With strict mode toggled off" do
|
202
207
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Recipient API' do
|
4
|
+
|
5
|
+
it "creates a stripe recipient with a default card" do
|
6
|
+
recipient = Stripe::Recipient.create({
|
7
|
+
type: "corporation",
|
8
|
+
name: "MyCo",
|
9
|
+
email: "owner@myco.com",
|
10
|
+
bank_account: 'void_bank_token'
|
11
|
+
})
|
12
|
+
expect(recipient.id).to match /^test_rp/
|
13
|
+
expect(recipient.name).to eq('MyCo')
|
14
|
+
expect(recipient.email).to eq('owner@myco.com')
|
15
|
+
|
16
|
+
expect(recipient.active_account).to_not be_nil
|
17
|
+
expect(recipient.active_account.bank_name).to_not be_nil
|
18
|
+
expect(recipient.active_account.last4).to_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "stores a created stripe recipient in memory" do
|
22
|
+
recipient = Stripe::Recipient.create({
|
23
|
+
type: "individual",
|
24
|
+
name: "Customer One",
|
25
|
+
bank_account: 'bank_account_token_1'
|
26
|
+
})
|
27
|
+
recipient2 = Stripe::Recipient.create({
|
28
|
+
type: "individual",
|
29
|
+
name: "Customer Two",
|
30
|
+
bank_account: 'bank_account_token_1'
|
31
|
+
})
|
32
|
+
data = test_data_source(:recipients)
|
33
|
+
expect(data[recipient.id]).to_not be_nil
|
34
|
+
expect(data[recipient.id][:name]).to eq("Customer One")
|
35
|
+
|
36
|
+
expect(data[recipient2.id]).to_not be_nil
|
37
|
+
expect(data[recipient2.id][:name]).to eq("Customer Two")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "retrieves a stripe recipient" do
|
41
|
+
original = Stripe::Recipient.create({
|
42
|
+
type: "individual",
|
43
|
+
name: "Bob",
|
44
|
+
email: "bob@example.com"
|
45
|
+
})
|
46
|
+
recipient = Stripe::Recipient.retrieve(original.id)
|
47
|
+
|
48
|
+
expect(recipient.id).to eq(original.id)
|
49
|
+
expect(recipient.name).to eq(original.name)
|
50
|
+
expect(recipient.email).to eq(original.email)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "cannot retrieve a recipient that doesn't exist" do
|
54
|
+
expect { Stripe::Recipient.retrieve('nope') }.to raise_error {|e|
|
55
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
56
|
+
expect(e.param).to eq('recipient')
|
57
|
+
expect(e.http_status).to eq(404)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
@@ -1,18 +1,25 @@
|
|
1
1
|
|
2
2
|
def require_stripe_examples
|
3
|
+
require 'shared_stripe_examples/bank_token_examples'
|
3
4
|
require 'shared_stripe_examples/card_token_examples'
|
5
|
+
require 'shared_stripe_examples/card_examples'
|
4
6
|
require 'shared_stripe_examples/charge_examples'
|
5
7
|
require 'shared_stripe_examples/customer_examples'
|
6
8
|
require 'shared_stripe_examples/error_mock_examples'
|
7
9
|
require 'shared_stripe_examples/invoice_item_examples'
|
8
10
|
require 'shared_stripe_examples/plan_examples'
|
11
|
+
require 'shared_stripe_examples/recipient_examples'
|
9
12
|
end
|
10
13
|
|
11
14
|
def it_behaves_like_stripe(&block)
|
15
|
+
it_behaves_like 'Bank Account Token Mocking', &block
|
12
16
|
it_behaves_like 'Card Token Mocking', &block
|
17
|
+
it_behaves_like 'Card API', &block
|
18
|
+
it_behaves_like 'Charge API', &block
|
13
19
|
it_behaves_like 'Charge API', &block
|
14
20
|
it_behaves_like 'Customer API', &block
|
15
21
|
it_behaves_like 'Invoice Item API', &block
|
16
22
|
it_behaves_like 'Plan API', &block
|
23
|
+
it_behaves_like 'Recipient API', &block
|
17
24
|
it_behaves_like 'Stripe Error Mocking', &block
|
18
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-ruby-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.4.
|
4
|
+
version: 1.8.4.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stripe
|
@@ -116,6 +116,7 @@ extra_rdoc_files: []
|
|
116
116
|
files:
|
117
117
|
- .gitignore
|
118
118
|
- .rspec
|
119
|
+
- .travis.yml
|
119
120
|
- ChangeLog.rdoc
|
120
121
|
- Gemfile
|
121
122
|
- LICENSE.txt
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- Rakefile
|
124
125
|
- bin/stripe-mock-server
|
125
126
|
- lib/stripe_mock.rb
|
127
|
+
- lib/stripe_mock/api/bank_tokens.rb
|
126
128
|
- lib/stripe_mock/api/card_tokens.rb
|
127
129
|
- lib/stripe_mock/api/client.rb
|
128
130
|
- lib/stripe_mock/api/debug.rb
|
@@ -141,10 +143,12 @@ files:
|
|
141
143
|
- lib/stripe_mock/errors/unstarted_state_error.rb
|
142
144
|
- lib/stripe_mock/errors/unsupported_request_error.rb
|
143
145
|
- lib/stripe_mock/instance.rb
|
146
|
+
- lib/stripe_mock/request_handlers/cards.rb
|
144
147
|
- lib/stripe_mock/request_handlers/charges.rb
|
145
148
|
- lib/stripe_mock/request_handlers/customers.rb
|
146
149
|
- lib/stripe_mock/request_handlers/invoice_items.rb
|
147
150
|
- lib/stripe_mock/request_handlers/plans.rb
|
151
|
+
- lib/stripe_mock/request_handlers/recipients.rb
|
148
152
|
- lib/stripe_mock/server.rb
|
149
153
|
- lib/stripe_mock/util.rb
|
150
154
|
- lib/stripe_mock/version.rb
|
@@ -189,12 +193,15 @@ files:
|
|
189
193
|
- spec/instance_spec.rb
|
190
194
|
- spec/readme_spec.rb
|
191
195
|
- spec/server_spec.rb
|
196
|
+
- spec/shared_stripe_examples/bank_token_examples.rb
|
197
|
+
- spec/shared_stripe_examples/card_examples.rb
|
192
198
|
- spec/shared_stripe_examples/card_token_examples.rb
|
193
199
|
- spec/shared_stripe_examples/charge_examples.rb
|
194
200
|
- spec/shared_stripe_examples/customer_examples.rb
|
195
201
|
- spec/shared_stripe_examples/error_mock_examples.rb
|
196
202
|
- spec/shared_stripe_examples/invoice_item_examples.rb
|
197
203
|
- spec/shared_stripe_examples/plan_examples.rb
|
204
|
+
- spec/shared_stripe_examples/recipient_examples.rb
|
198
205
|
- spec/spec_helper.rb
|
199
206
|
- spec/stripe_mock_spec.rb
|
200
207
|
- spec/support/stripe_examples.rb
|
@@ -233,12 +240,15 @@ test_files:
|
|
233
240
|
- spec/instance_spec.rb
|
234
241
|
- spec/readme_spec.rb
|
235
242
|
- spec/server_spec.rb
|
243
|
+
- spec/shared_stripe_examples/bank_token_examples.rb
|
244
|
+
- spec/shared_stripe_examples/card_examples.rb
|
236
245
|
- spec/shared_stripe_examples/card_token_examples.rb
|
237
246
|
- spec/shared_stripe_examples/charge_examples.rb
|
238
247
|
- spec/shared_stripe_examples/customer_examples.rb
|
239
248
|
- spec/shared_stripe_examples/error_mock_examples.rb
|
240
249
|
- spec/shared_stripe_examples/invoice_item_examples.rb
|
241
250
|
- spec/shared_stripe_examples/plan_examples.rb
|
251
|
+
- spec/shared_stripe_examples/recipient_examples.rb
|
242
252
|
- spec/spec_helper.rb
|
243
253
|
- spec/stripe_mock_spec.rb
|
244
254
|
- spec/support/stripe_examples.rb
|