stripe-ruby-mock 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -7
- data/lib/stripe_mock.rb +1 -0
- data/lib/stripe_mock/data.rb +2 -1
- data/lib/stripe_mock/instance.rb +3 -1
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/transfers.rb +54 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/spec/shared_stripe_examples/subscription_examples.rb +3 -2
- data/spec/shared_stripe_examples/transfer_examples.rb +66 -0
- data/spec/support/stripe_examples.rb +1 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
In your gemfile:
|
10
10
|
|
11
|
-
gem 'stripe-ruby-mock', '~> 2.0.
|
11
|
+
gem 'stripe-ruby-mock', '~> 2.0.5', :require => 'stripe_mock'
|
12
12
|
|
13
13
|
## Features
|
14
14
|
|
@@ -25,7 +25,7 @@ In your gemfile:
|
|
25
25
|
|
26
26
|
## Description
|
27
27
|
|
28
|
-
** *WARNING: This library does not cover all Stripe API endpoints. If you need one that's missing, please create an issue for it
|
28
|
+
** *WARNING: This library does not cover all Stripe API endpoints. If you need one that's missing, please create an issue for it, or [see this wiki page](https://github.com/rebelidealist/stripe-ruby-mock/wiki/Implementing-a-New-Behavior) if you're interested in contributing* **
|
29
29
|
|
30
30
|
At its core, this library overrides [stripe-ruby's](https://github.com/stripe/stripe-ruby)
|
31
31
|
request method to skip all http calls and
|
@@ -353,11 +353,7 @@ StripeMock.global_id_prefix = 'my_app_'
|
|
353
353
|
|
354
354
|
## Developing stripe-ruby-mock
|
355
355
|
|
356
|
-
|
357
|
-
|
358
|
-
$ bundle install
|
359
|
-
$ bundle exec rspec
|
360
|
-
$ bundle exec rspec -t live # Runs certain tests against Stripe's servers
|
356
|
+
[Please see this wiki page](https://github.com/rebelidealist/stripe-ruby-mock/wiki/Implementing-a-New-Behavior)
|
361
357
|
|
362
358
|
Patches are welcome and greatly appreciated! If you're contributing to fix a problem,
|
363
359
|
be sure to write tests that illustrate the problem being fixed.
|
data/lib/stripe_mock.rb
CHANGED
@@ -50,6 +50,7 @@ require 'stripe_mock/request_handlers/invoices.rb'
|
|
50
50
|
require 'stripe_mock/request_handlers/invoice_items.rb'
|
51
51
|
require 'stripe_mock/request_handlers/plans.rb'
|
52
52
|
require 'stripe_mock/request_handlers/recipients.rb'
|
53
|
+
require 'stripe_mock/request_handlers/transfers.rb'
|
53
54
|
require 'stripe_mock/request_handlers/subscriptions.rb'
|
54
55
|
require 'stripe_mock/request_handlers/tokens.rb'
|
55
56
|
require 'stripe_mock/instance'
|
data/lib/stripe_mock/data.rb
CHANGED
data/lib/stripe_mock/instance.rb
CHANGED
@@ -28,11 +28,12 @@ module StripeMock
|
|
28
28
|
include StripeMock::RequestHandlers::InvoiceItems
|
29
29
|
include StripeMock::RequestHandlers::Plans
|
30
30
|
include StripeMock::RequestHandlers::Recipients
|
31
|
+
include StripeMock::RequestHandlers::Transfers
|
31
32
|
include StripeMock::RequestHandlers::Tokens
|
32
33
|
|
33
34
|
|
34
35
|
attr_reader :bank_tokens, :charges, :coupons, :customers, :events,
|
35
|
-
:invoices, :invoice_items, :plans, :recipients, :subscriptions
|
36
|
+
:invoices, :invoice_items, :plans, :recipients, :transfers, :subscriptions
|
36
37
|
|
37
38
|
attr_accessor :error_queue, :debug
|
38
39
|
|
@@ -47,6 +48,7 @@ module StripeMock
|
|
47
48
|
@invoice_items = {}
|
48
49
|
@plans = {}
|
49
50
|
@recipients = {}
|
51
|
+
@transfers = {}
|
50
52
|
@subscriptions = {}
|
51
53
|
|
52
54
|
@debug = false
|
@@ -11,7 +11,7 @@ module StripeMock
|
|
11
11
|
|
12
12
|
start_time = options[:current_period_start] || Time.now.utc.to_i
|
13
13
|
params = { plan: plan, customer: cus[:id], current_period_start: start_time }
|
14
|
-
params.merge! options.select {|k,v| k =~ /application_fee_percent|quantity|metadata/}
|
14
|
+
params.merge! options.select {|k,v| k =~ /application_fee_percent|quantity|metadata|tax_percent/}
|
15
15
|
# TODO: Implement coupon logic
|
16
16
|
|
17
17
|
if (plan[:trial_period_days].nil? && options[:trial_end].nil?) || options[:trial_end] == "now"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Transfers
|
4
|
+
|
5
|
+
def Transfers.included(klass)
|
6
|
+
klass.add_handler 'post /v1/transfers', :new_transfer
|
7
|
+
klass.add_handler 'get /v1/transfers', :get_all_transfers
|
8
|
+
klass.add_handler 'get /v1/transfers/(.*)', :get_transfer
|
9
|
+
klass.add_handler 'post /v1/transfers/(.*)/cancel', :cancel_transfer
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_all_transfers(route, method_url, params, headers)
|
13
|
+
if recipient = params[:recipient]
|
14
|
+
assert_existence :recipient, recipient, recipients[recipient]
|
15
|
+
end
|
16
|
+
|
17
|
+
_transfers = transfers.each_with_object([]) do |(_, transfer), array|
|
18
|
+
if recipient
|
19
|
+
array << transfer if transfer[:recipient] == recipient
|
20
|
+
else
|
21
|
+
array << transfer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if params[:limit]
|
26
|
+
_transfers = _transfers.first([params[:limit], _transfers.size].min)
|
27
|
+
end
|
28
|
+
|
29
|
+
_transfers
|
30
|
+
end
|
31
|
+
|
32
|
+
def new_transfer(route, method_url, params, headers)
|
33
|
+
id = new_id('tr')
|
34
|
+
if params[:bank_account]
|
35
|
+
params[:account] = get_bank_by_token(params.delete(:bank_account))
|
36
|
+
end
|
37
|
+
transfers[id] = Data.mock_transfer(params.merge :id => id)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_transfer(route, method_url, params, headers)
|
41
|
+
route =~ method_url
|
42
|
+
assert_existence :transfer, $1, transfers[$1]
|
43
|
+
transfers[$1] ||= Data.mock_transfer(:id => $1)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cancel_transfer(route, method_url, params, headers)
|
47
|
+
route =~ method_url
|
48
|
+
assert_existence :transfer, $1, transfers[$1]
|
49
|
+
t = transfers[$1] ||= Data.mock_transfer(:id => $1)
|
50
|
+
t.merge!({:status => "canceled"})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/stripe_mock/version.rb
CHANGED
@@ -34,7 +34,7 @@ shared_examples 'Customer Subscriptions' do
|
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
|
-
it "correctly sets quantity and
|
37
|
+
it "correctly sets quantity, application_fee_percent and tax_percent" do
|
38
38
|
Stripe::Plan.create(
|
39
39
|
:amount => 2500,
|
40
40
|
:interval => 'month',
|
@@ -46,9 +46,10 @@ shared_examples 'Customer Subscriptions' do
|
|
46
46
|
customer = Stripe::Customer.create(id: 'test_customer_sub', card: gen_card_tk)
|
47
47
|
|
48
48
|
subscription = customer.subscriptions.create({
|
49
|
-
:plan => "silver", quantity: 2, application_fee_percent: 10})
|
49
|
+
:plan => "silver", quantity: 2, application_fee_percent: 10, tax_percent: 20})
|
50
50
|
expect(subscription.quantity).to eq(2)
|
51
51
|
expect(subscription.application_fee_percent).to eq(10)
|
52
|
+
expect(subscription.tax_percent).to eq(20)
|
52
53
|
end
|
53
54
|
|
54
55
|
it "adds additional subscription to customer with existing subscription" do
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Transfer API' do
|
4
|
+
|
5
|
+
it "creates a stripe transfer" do
|
6
|
+
recipient = Stripe::Recipient.create(type: "corporation", name: "MyCo")
|
7
|
+
transfer = Stripe::Transfer.create(amount: "100", currency: "usd", recipient: recipient.id)
|
8
|
+
|
9
|
+
expect(transfer.id).to match /^test_tr/
|
10
|
+
expect(transfer.amount).to eq('100')
|
11
|
+
expect(transfer.currency).to eq('usd')
|
12
|
+
expect(transfer.recipient).to eq recipient.id
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "listing transfers" do
|
16
|
+
let(:recipient) { Stripe::Recipient.create(type: "corporation", name: "MyCo") }
|
17
|
+
|
18
|
+
before do
|
19
|
+
3.times do
|
20
|
+
Stripe::Transfer.create(amount: "100", currency: "usd", recipient: recipient.id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "without params retrieves all tripe transfers" do
|
25
|
+
expect(Stripe::Transfer.all.count).to eq(3)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "accepts a limit param" do
|
29
|
+
expect(Stripe::Transfer.all(limit: 2).count).to eq(2)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "filters the search to a specific recipient" do
|
33
|
+
r2 = Stripe::Recipient.create(type: "corporation", name: "MyCo")
|
34
|
+
Stripe::Transfer.create(amount: "100", currency: "usd", recipient: r2.id)
|
35
|
+
|
36
|
+
expect(Stripe::Transfer.all(recipient: r2.id).count).to eq(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "retrieves a stripe transfer" do
|
42
|
+
original = Stripe::Transfer.create(amount: "100", currency: "usd")
|
43
|
+
transfer = Stripe::Transfer.retrieve(original.id)
|
44
|
+
|
45
|
+
expect(transfer.id).to eq(original.id)
|
46
|
+
expect(transfer.amount).to eq(original.amount)
|
47
|
+
expect(transfer.currency).to eq(original.currency)
|
48
|
+
expect(transfer.recipient).to eq(original.recipient)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "canceles a stripe transfer " do
|
52
|
+
original = Stripe::Transfer.create(amount: "100", currency: "usd")
|
53
|
+
res, api_key = Stripe.request(:post, "/v1/transfers/#{original.id}/cancel", 'api_key', {})
|
54
|
+
|
55
|
+
expect(res[:status]).to eq("canceled")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "cannot retrieve a transfer that doesn't exist" do
|
59
|
+
expect { Stripe::Transfer.retrieve('nope') }.to raise_error {|e|
|
60
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
61
|
+
expect(e.param).to eq('transfer')
|
62
|
+
expect(e.http_status).to eq(404)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -17,6 +17,7 @@ def it_behaves_like_stripe(&block)
|
|
17
17
|
it_behaves_like 'Plan API', &block
|
18
18
|
it_behaves_like 'Recipient API', &block
|
19
19
|
it_behaves_like 'Refund API', &block
|
20
|
+
it_behaves_like 'Transfer API', &block
|
20
21
|
it_behaves_like 'Stripe Error Mocking', &block
|
21
22
|
it_behaves_like 'Customer Subscriptions', &block
|
22
23
|
it_behaves_like 'Webhook Events API', &block
|
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: 2.0.
|
4
|
+
version: 2.0.5
|
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: 2015-02-
|
12
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stripe
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/stripe_mock/request_handlers/recipients.rb
|
162
162
|
- lib/stripe_mock/request_handlers/subscriptions.rb
|
163
163
|
- lib/stripe_mock/request_handlers/tokens.rb
|
164
|
+
- lib/stripe_mock/request_handlers/transfers.rb
|
164
165
|
- lib/stripe_mock/request_handlers/validators/param_validators.rb
|
165
166
|
- lib/stripe_mock/server.rb
|
166
167
|
- lib/stripe_mock/test_strategies/base.rb
|
@@ -232,6 +233,7 @@ files:
|
|
232
233
|
- spec/shared_stripe_examples/recipient_examples.rb
|
233
234
|
- spec/shared_stripe_examples/refund_examples.rb
|
234
235
|
- spec/shared_stripe_examples/subscription_examples.rb
|
236
|
+
- spec/shared_stripe_examples/transfer_examples.rb
|
235
237
|
- spec/shared_stripe_examples/validation_examples.rb
|
236
238
|
- spec/shared_stripe_examples/webhook_event_examples.rb
|
237
239
|
- spec/spec_helper.rb
|
@@ -290,6 +292,7 @@ test_files:
|
|
290
292
|
- spec/shared_stripe_examples/recipient_examples.rb
|
291
293
|
- spec/shared_stripe_examples/refund_examples.rb
|
292
294
|
- spec/shared_stripe_examples/subscription_examples.rb
|
295
|
+
- spec/shared_stripe_examples/transfer_examples.rb
|
293
296
|
- spec/shared_stripe_examples/validation_examples.rb
|
294
297
|
- spec/shared_stripe_examples/webhook_event_examples.rb
|
295
298
|
- spec/spec_helper.rb
|