stripe-ruby-mock 2.5.4 → 2.5.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/lib/stripe_mock.rb +1 -0
  5. data/lib/stripe_mock/data.rb +32 -13
  6. data/lib/stripe_mock/instance.rb +1 -0
  7. data/lib/stripe_mock/request_handlers/accounts.rb +16 -0
  8. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
  9. data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +1 -0
  10. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +9 -1
  11. data/lib/stripe_mock/request_handlers/transfers.rb +10 -4
  12. data/lib/stripe_mock/test_strategies/base.rb +4 -2
  13. data/lib/stripe_mock/version.rb +1 -1
  14. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +2 -2
  15. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +2 -2
  16. data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +2 -2
  17. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +3 -3
  18. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +1 -1
  19. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +1 -1
  20. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +1 -1
  21. data/lib/stripe_mock/webhook_fixtures/plan.created.json +1 -1
  22. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +1 -1
  23. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +1 -1
  24. data/spec/instance_spec.rb +31 -0
  25. data/spec/shared_stripe_examples/account_examples.rb +27 -0
  26. data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
  27. data/spec/shared_stripe_examples/invoice_examples.rb +1 -1
  28. data/spec/shared_stripe_examples/subscription_examples.rb +35 -16
  29. data/spec/shared_stripe_examples/transfer_examples.rb +61 -30
  30. data/spec/support/stripe_examples.rb +1 -0
  31. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 771c4e4adbc92b37176d94b8f91fb1f2bef740ba
4
- data.tar.gz: 86c21735586588ea3aabc958d3eb93dda6dbc7ec
3
+ metadata.gz: 8bb56a9378124dffc3cb2d4d9900ced89323ec9a
4
+ data.tar.gz: 9181762220a2d8d1fb5ff7e37d479b2b75290d76
5
5
  SHA512:
6
- metadata.gz: 0c747fed9cf7824d59fdb1be3ec1b399beabd69d54d08101c1c46d96792fe400e4d7b8c1aa6a816c981d58d902a3fdf46c6edff21bd280a07615799384a4a82f
7
- data.tar.gz: 68b2ab17e0f504f783bd8c5a20893ec89bee491a29cac16a824d8cdb45e48f7a2a34e307b153feb7fe58662ee661d2732c4d838391cf23497ea20fe0a90393a5
6
+ metadata.gz: 390ca8cee59e0584d03dc2a9c6decb8b6df5b70278984baefbd00f6b053efa747c623cf5d867fa53c8ad964d66e48d5155e9a34ee0a27846d36177f8f67a6904
7
+ data.tar.gz: 7d4bd0d536ed0b21d4eac5f0e16161e4c46e2ba00e927c74fe6fa1f88bbf1fda335b314dffe04704afccf9f226330e0b7f8c3e3b3afbf4ad03cba078562739f7
@@ -17,7 +17,7 @@ script: "bundle exec rspec && bundle exec rspec -t live"
17
17
 
18
18
  env:
19
19
  global:
20
- - IS_TRAVIS=true STRIPE_TEST_SECRET_KEY_A=sk_test_sXdhUWu3NhrB7r1tkK0zZfMW STRIPE_TEST_SECRET_KEY_B=sk_test_uPfIX9ziFNloXwtSdDPJTdnh STRIPE_TEST_SECRET_KEY_C=sk_test_waSy1TaP2RNEpoz9t2pFCysm STRIPE_TEST_SECRET_KEY_D=sk_test_Z1mQZNehRFmI3EN9mHnMafnq
20
+ - IS_TRAVIS=true STRIPE_TEST_SECRET_KEY_A=sk_test_Ut2MSlZANdT3iDALdGhyLymy STRIPE_TEST_SECRET_KEY_B=sk_test_JXtzss9tHOG1ofIyEZgoUP4Q STRIPE_TEST_SECRET_KEY_C=sk_test_ZR5nVz9p3ivsqVa7mYB0sFep STRIPE_TEST_SECRET_KEY_D=sk_test_ZR5nVz9p3ivsqVa7mYB0sFep
21
21
 
22
22
  notifications:
23
23
  webhooks:
data/README.md CHANGED
@@ -12,7 +12,7 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'
12
12
 
13
13
  In your gemfile:
14
14
 
15
- gem 'stripe-ruby-mock', '~> 2.5.4', :require => 'stripe_mock'
15
+ gem 'stripe-ruby-mock', '~> 2.5.5', :require => 'stripe_mock'
16
16
 
17
17
  ## Features
18
18
 
@@ -69,6 +69,7 @@ require 'stripe_mock/request_handlers/payouts.rb'
69
69
  require 'stripe_mock/request_handlers/subscriptions.rb'
70
70
  require 'stripe_mock/request_handlers/tokens.rb'
71
71
  require 'stripe_mock/request_handlers/country_spec.rb'
72
+ require 'stripe_mock/request_handlers/ephemeral_key.rb'
72
73
  require 'stripe_mock/instance'
73
74
 
74
75
  require 'stripe_mock/test_strategies/base.rb'
@@ -243,7 +243,8 @@ module StripeMock
243
243
  cvc_check: nil,
244
244
  address_line1_check: nil,
245
245
  address_zip_check: nil,
246
- tokenization_method: nil
246
+ tokenization_method: nil,
247
+ metadata: {}
247
248
  }, params)
248
249
  end
249
250
 
@@ -261,7 +262,8 @@ module StripeMock
261
262
  status: 'new',
262
263
  account_holder_name: 'John Doe',
263
264
  account_holder_type: 'individual',
264
- fingerprint: "aBcFinGerPrINt123"
265
+ fingerprint: "aBcFinGerPrINt123",
266
+ metadata: {}
265
267
  }.merge(params)
266
268
  end
267
269
 
@@ -594,31 +596,29 @@ module StripeMock
594
596
  currency = params[:currency] || StripeMock.default_currency
595
597
  id = params[:id] || 'tr_test_transfer'
596
598
  {
597
- :status => 'pending',
598
599
  :amount => 100,
599
- :account => {
600
- :object => 'bank_account',
601
- :country => 'US',
602
- :bank_name => 'STRIPE TEST BANK',
603
- :last4 => '6789'
604
- },
605
- :recipient => 'test_recipient',
606
- :fee => 0,
607
- :fee_details => [],
600
+ :amount_reversed => 0,
601
+ :balance_transaction => "txn_2dyYXXP90MN26R",
608
602
  :id => id,
609
603
  :livemode => false,
610
604
  :metadata => {},
611
605
  :currency => currency,
612
606
  :object => "transfer",
613
- :date => 1304114826,
607
+ :created => 1304114826,
614
608
  :description => "Transfer description",
615
609
  :reversed => false,
616
610
  :reversals => {
617
611
  :object => "list",
612
+ :data => [],
618
613
  :total_count => 0,
619
614
  :has_more => false,
620
615
  :url => "/v1/transfers/#{id}/reversals"
621
616
  },
617
+ :destination => "acct_164wxjKbnvuxQXGu",
618
+ :destination_payment => "py_164xRvKbnvuxQXGuVFV2pZo1",
619
+ :source_transaction => "ch_164xRv2eZvKYlo2Clu1sIJWB",
620
+ :source_type => "card",
621
+ :transfer_group => "group_ch_164xRv2eZvKYlo2Clu1sIJWB",
622
622
  }.merge(params)
623
623
  end
624
624
 
@@ -1027,5 +1027,24 @@ module StripeMock
1027
1027
  quantity: 2
1028
1028
  }.merge(params)
1029
1029
  end
1030
+
1031
+ def self.mock_ephemeral_key(**params)
1032
+ created = Time.now.to_i
1033
+ expires = created + 34_000
1034
+ {
1035
+ id: "ephkey_default",
1036
+ object: "ephemeral_key",
1037
+ associated_objects: [
1038
+ {
1039
+ id: params[:customer],
1040
+ type: "customer"
1041
+ }
1042
+ ],
1043
+ created: created,
1044
+ expires: expires,
1045
+ livemode: false,
1046
+ secret: "ek_test_default"
1047
+ }
1048
+ end
1030
1049
  end
1031
1050
  end
@@ -42,6 +42,7 @@ module StripeMock
42
42
  include StripeMock::RequestHandlers::Tokens
43
43
  include StripeMock::RequestHandlers::CountrySpec
44
44
  include StripeMock::RequestHandlers::Payouts
45
+ include StripeMock::RequestHandlers::EphemeralKey
45
46
 
46
47
  attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
47
48
  :disputes, :events, :invoices, :invoice_items, :orders, :plans, :recipients,
@@ -1,6 +1,7 @@
1
1
  module StripeMock
2
2
  module RequestHandlers
3
3
  module Accounts
4
+ VALID_START_YEAR = 2009
4
5
 
5
6
  def Accounts.included(klass)
6
7
  klass.add_handler 'post /v1/accounts', :new_account
@@ -30,6 +31,8 @@ module StripeMock
30
31
  account.merge!(params)
31
32
  if blank_value?(params[:tos_acceptance], :date)
32
33
  raise Stripe::InvalidRequestError.new("Invalid integer: ", "tos_acceptance[date]", http_status: 400)
34
+ elsif params[:tos_acceptance] && params[:tos_acceptance][:date]
35
+ validate_acceptance_date(params[:tos_acceptance][:date])
33
36
  end
34
37
  account
35
38
  end
@@ -65,6 +68,19 @@ module StripeMock
65
68
  end
66
69
  false
67
70
  end
71
+
72
+ def validate_acceptance_date(unix_date)
73
+ unix_now = Time.now.strftime("%s").to_i
74
+ formatted_date = Time.at(unix_date)
75
+
76
+ return if formatted_date.year >= VALID_START_YEAR && unix_now >= unix_date
77
+
78
+ raise Stripe::InvalidRequestError.new(
79
+ "ToS acceptance date is not valid. Dates are expected to be integers, measured in seconds, not in the future, and after 2009",
80
+ "tos_acceptance[date]",
81
+ http_status: 400
82
+ )
83
+ end
68
84
  end
69
85
  end
70
86
  end
@@ -0,0 +1,13 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module EphemeralKey
4
+ def self.included(klass)
5
+ klass.add_handler 'post /v1/ephemeral_keys', :create_ephemeral_key
6
+ end
7
+
8
+ def create_ephemeral_key(route, method_url, params, headers)
9
+ Data.mock_ephemeral_key(params)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -97,6 +97,7 @@ module StripeMock
97
97
  get_bank_by_token(params[:source])
98
98
  end
99
99
  end
100
+ source[:metadata].merge!(params[:metadata]) if params[:metadata]
100
101
  add_source_to_object(type, source, resource)
101
102
  end
102
103
 
@@ -8,7 +8,15 @@ module StripeMock
8
8
 
9
9
  def resolve_subscription_changes(subscription, plans, customer, options = {})
10
10
  subscription.merge!(custom_subscription_params(plans, customer, options))
11
- subscription[:items][:data] = plans.map { |plan| Data.mock_subscription_item({ plan: plan }) }
11
+ subscription[:items][:data] = plans.map do |plan|
12
+ if options[:items] && options[:items].size == plans.size
13
+ quantity = options[:items] &&
14
+ options[:items].values.detect { |item| item[:plan] == plan[:id] }[:quantity] || 1
15
+ Data.mock_subscription_item({ plan: plan, quantity: quantity })
16
+ else
17
+ Data.mock_subscription_item({ plan: plan })
18
+ end
19
+ end
12
20
  subscription
13
21
  end
14
22
 
@@ -10,13 +10,19 @@ module StripeMock
10
10
  end
11
11
 
12
12
  def get_all_transfers(route, method_url, params, headers)
13
- if recipient = params[:recipient]
14
- assert_existence :recipient, recipient, recipients[recipient]
13
+ extra_params = params.keys - [:created, :destination, :ending_before,
14
+ :limit, :starting_after, :transfer_group]
15
+ unless extra_params.empty?
16
+ raise Stripe::InvalidRequestError.new("Received unknown parameter: #{extra_params[0]}", extra_params[0].to_s, http_status: 400)
17
+ end
18
+
19
+ if destination = params[:destination]
20
+ assert_existence :destination, destination, accounts[destination]
15
21
  end
16
22
 
17
23
  _transfers = transfers.each_with_object([]) do |(_, transfer), array|
18
- if recipient
19
- array << transfer if transfer[:recipient] == recipient
24
+ if destination
25
+ array << transfer if transfer[:destination] == destination
20
26
  else
21
27
  array << transfer
22
28
  end
@@ -6,7 +6,9 @@ module StripeMock
6
6
  currency = params[:currency] || StripeMock.default_currency
7
7
  {
8
8
  :id => 'stripe_mock_default_plan_id',
9
- :name => 'StripeMock Default Plan ID',
9
+ :product => {
10
+ :name => 'StripeMock Default Plan ID'
11
+ },
10
12
  :amount => 1337,
11
13
  :currency => currency,
12
14
  :interval => 'month'
@@ -14,7 +16,7 @@ module StripeMock
14
16
  end
15
17
 
16
18
  def generate_card_token(card_params={})
17
- card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => 2018, :cvc => "999", :tokenization_method => nil }
19
+ card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => (Time.now.year + 5), :cvc => "999", :tokenization_method => nil }
18
20
  card = StripeMock::Util.card_merge(card_data, card_params)
19
21
  card[:fingerprint] = StripeMock::Util.fingerprint(card[:number]) if StripeMock.state == 'local'
20
22
 
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "2.5.4"
3
+ VERSION = "2.5.5"
4
4
  end
@@ -16,7 +16,7 @@
16
16
  "created": 1497881783,
17
17
  "plan": {
18
18
  "interval": "month",
19
- "name": "Member's Club",
19
+ "product": "pr_00000000000000",
20
20
  "amount": 100,
21
21
  "currency": "usd",
22
22
  "id": "fkx0AFo_00000000000000",
@@ -34,7 +34,7 @@
34
34
  "created": 1497881788,
35
35
  "plan": {
36
36
  "interval": "month",
37
- "name": "Vistor's Club",
37
+ "product": "pr_00000000000001",
38
38
  "amount": 200,
39
39
  "currency": "eur",
40
40
  "id": "fkx0AFo_00000000000001",
@@ -15,7 +15,7 @@
15
15
  "created": 1497881783,
16
16
  "plan": {
17
17
  "interval": "month",
18
- "name": "Member's Club",
18
+ "product": "pr_00000000000000",
19
19
  "amount": 100,
20
20
  "currency": "usd",
21
21
  "id": "fkx0AFo_00000000000000",
@@ -33,7 +33,7 @@
33
33
  "created": 1497881788,
34
34
  "plan": {
35
35
  "interval": "month",
36
- "name": "Vistor's Club",
36
+ "product": "pr_00000000000001",
37
37
  "amount": 200,
38
38
  "currency": "eur",
39
39
  "id": "fkx0AFo_00000000000001",
@@ -15,7 +15,7 @@
15
15
  "created": 1497881783,
16
16
  "plan": {
17
17
  "interval": "month",
18
- "name": "Member's Club",
18
+ "product": "pr_00000000000000",
19
19
  "amount": 100,
20
20
  "currency": "usd",
21
21
  "id": "fkx0AFo_00000000000000",
@@ -33,7 +33,7 @@
33
33
  "created": 1497881788,
34
34
  "plan": {
35
35
  "interval": "month",
36
- "name": "Vistor's Club",
36
+ "product": "pr_00000000000001",
37
37
  "amount": 200,
38
38
  "currency": "eur",
39
39
  "id": "fkx0AFo_00000000000001",
@@ -15,7 +15,7 @@
15
15
  "created": 1497881783,
16
16
  "plan": {
17
17
  "interval": "month",
18
- "name": "Member's Club",
18
+ "product": "pr_00000000000000",
19
19
  "amount": 100,
20
20
  "currency": "usd",
21
21
  "id": "fkx0AFo_00000000000000",
@@ -33,7 +33,7 @@
33
33
  "created": 1497881788,
34
34
  "plan": {
35
35
  "interval": "month",
36
- "name": "Vistor's Club",
36
+ "product": "pr_00000000000001",
37
37
  "amount": 200,
38
38
  "currency": "eur",
39
39
  "id": "fkx0AFo_00000000000001",
@@ -64,7 +64,7 @@
64
64
  "previous_attributes": {
65
65
  "plan": {
66
66
  "interval": "month",
67
- "name": "Old plan",
67
+ "product": "pr_00000000000002",
68
68
  "amount": 100,
69
69
  "currency": "usd",
70
70
  "id": "OLD_PLAN_ID",
@@ -30,7 +30,6 @@
30
30
  "quantity": 1,
31
31
  "plan": {
32
32
  "interval": "month",
33
- "name": "Member's Club",
34
33
  "amount": 100,
35
34
  "currency": "usd",
36
35
  "id": "fkx0AFo",
@@ -38,6 +37,7 @@
38
37
  "livemode": false,
39
38
  "interval_count": 1,
40
39
  "trial_period_days": null,
40
+ "product": "pr_00000000000000",
41
41
  "metadata": {}
42
42
  },
43
43
  "description": null,
@@ -64,7 +64,7 @@
64
64
  "quantity": 1,
65
65
  "plan": {
66
66
  "interval": "month",
67
- "name": "Platinum",
67
+ "product": "pr_00000000000000",
68
68
  "created": 1300000000,
69
69
  "amount": 20000,
70
70
  "currency": "usd",
@@ -30,7 +30,7 @@
30
30
  "quantity": 1,
31
31
  "plan": {
32
32
  "interval": "month",
33
- "name": "Member's Club",
33
+ "product": "pr_00000000000000",
34
34
  "amount": 100,
35
35
  "currency": "usd",
36
36
  "id": "fkx0AFo",
@@ -7,7 +7,7 @@
7
7
  "data": {
8
8
  "object": {
9
9
  "interval": "month",
10
- "name": "Member's Club",
10
+ "product": "pr_00000000000000",
11
11
  "amount": 100,
12
12
  "currency": "usd",
13
13
  "id": "fkx0AFo_00000000000000",
@@ -7,7 +7,7 @@
7
7
  "data": {
8
8
  "object": {
9
9
  "interval": "month",
10
- "name": "Member's Club",
10
+ "product": "pr_00000000000000",
11
11
  "amount": 100,
12
12
  "currency": "usd",
13
13
  "id": "fkx0AFo_00000000000000",
@@ -7,7 +7,7 @@
7
7
  "data": {
8
8
  "object": {
9
9
  "interval": "month",
10
- "name": "Member's Club",
10
+ "product": "pr_00000000000000",
11
11
  "amount": 100,
12
12
  "currency": "usd",
13
13
  "id": "fkx0AFo_00000000000000",
@@ -66,4 +66,35 @@ describe StripeMock::Instance do
66
66
  end
67
67
  expect(customer.currency).to eq("jpy")
68
68
  end
69
+
70
+ context 'when creating sources with metadata' do
71
+ let(:customer) { Stripe::Customer.create(email: 'test@email.com') }
72
+ let(:metadata) { { test_key: 'test_value' } }
73
+
74
+ context 'for credit card' do
75
+ let(:credit_card) do
76
+ customer.sources.create(
77
+ source: stripe_helper.generate_card_token,
78
+ metadata: metadata
79
+ )
80
+ end
81
+
82
+ it('should save metadata') do
83
+ expect(credit_card.metadata.test_key).to eq metadata[:test_key]
84
+ end
85
+ end
86
+
87
+ context 'for bank account' do
88
+ let(:bank_account) do
89
+ customer.sources.create(
90
+ source: stripe_helper.generate_bank_token,
91
+ metadata: metadata
92
+ )
93
+ end
94
+
95
+ it('should save metadata') do
96
+ expect(bank_account.metadata.test_key).to eq metadata[:test_key]
97
+ end
98
+ end
99
+ end
69
100
  end
@@ -57,6 +57,33 @@ shared_examples 'Account API' do
57
57
  account.save
58
58
  }.to raise_error
59
59
  end
60
+
61
+ context 'with tos acceptance date' do
62
+ let(:error_message) { "ToS acceptance date is not valid. Dates are expected to be integers, measured in seconds, not in the future, and after 2009" }
63
+
64
+ it 'raises error when tos date is before 2009' do
65
+ date = Date.new(2008,1,1).strftime("%s").to_i
66
+
67
+ account = Stripe::Account.retrieve
68
+ account.tos_acceptance.date = date
69
+
70
+ expect {
71
+ account.save
72
+ }.to raise_error Stripe::InvalidRequestError, error_message
73
+ end
74
+
75
+ it 'raises error when tos date is in the future' do
76
+ year = Time.now.year + 5
77
+ date = Date.new(year,1,1).strftime("%s").to_i
78
+
79
+ account = Stripe::Account.retrieve
80
+ account.tos_acceptance.date = date
81
+
82
+ expect {
83
+ account.save
84
+ }.to raise_error Stripe::InvalidRequestError, error_message
85
+ end
86
+ end
60
87
  end
61
88
 
62
89
  it 'deauthorizes the stripe account', live: false do
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'EphemeralKey API' do
4
+ describe 'Create a new key' do
5
+ let(:customer) { Stripe::Customer.create email: 'test@example.com' }
6
+ let(:version) { '2016-07-06' }
7
+
8
+ it 'creates a new key' do
9
+ key = Stripe::EphemeralKey.create(
10
+ { customer: customer.id },
11
+ { stripe_version: version }
12
+ )
13
+
14
+ expect(key[:associated_objects][0][:id]).to eq customer.id
15
+ end
16
+ end
17
+ end
@@ -360,7 +360,7 @@ shared_examples 'Invoice API' do
360
360
  expect(line.amount).to eq 150_00
361
361
  # line period is for the NEXT subscription cycle
362
362
  expect(line.period.start).to be_within(1).of subscription.current_period_end
363
- expect(line.period.end).to be_within(1).of (Time.at(subscription.current_period_end).to_datetime >> 1).to_time.to_i # +1 month
363
+ expect(Time.at(line.period.end).month).to be_within(1).of (Time.at(subscription.current_period_end).to_datetime >> 1).month # +1 month
364
364
  end
365
365
  end
366
366
 
@@ -8,7 +8,8 @@ shared_examples 'Customer Subscriptions' do
8
8
 
9
9
  context "creating a new subscription" do
10
10
  it "adds a new subscription to customer with none using items", :live => true do
11
- plan = stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999, currency: 'usd')
11
+ plan = stripe_helper.create_plan(id: 'silver', product: { name: 'Silver Plan' },
12
+ amount: 4999, currency: 'usd')
12
13
  customer = Stripe::Customer.create(source: gen_card_tk)
13
14
 
14
15
  expect(customer.subscriptions.data).to be_empty
@@ -37,7 +38,8 @@ shared_examples 'Customer Subscriptions' do
37
38
  end
38
39
 
39
40
  it "adds a new subscription to customer with none", :live => true do
40
- plan = stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999, currency: 'usd')
41
+ plan = stripe_helper.create_plan(id: 'silver', product: { name: 'Silver Plan' },
42
+ amount: 4999, currency: 'usd')
41
43
  customer = Stripe::Customer.create(source: gen_card_tk)
42
44
 
43
45
  expect(customer.subscriptions.data).to be_empty
@@ -66,7 +68,7 @@ shared_examples 'Customer Subscriptions' do
66
68
  end
67
69
 
68
70
  it 'when customer object provided' do
69
- plan = stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999, currency: 'usd')
71
+ plan = stripe_helper.create_plan(id: 'silver', product: { name: 'Silver Plan' }, amount: 4999, currency: 'usd')
70
72
  customer = Stripe::Customer.create(source: gen_card_tk)
71
73
 
72
74
  expect(customer.subscriptions.data).to be_empty
@@ -100,13 +102,15 @@ shared_examples 'Customer Subscriptions' do
100
102
  customer = Stripe::Customer.create(source: gen_card_tk)
101
103
  expect(customer.subscriptions.count).to eq(0)
102
104
 
103
- plan = stripe_helper.create_plan(id: :silver, name: 'Silver Plan', amount: 4999, currency: 'usd')
105
+ plan = stripe_helper.create_plan(id: :silver, product: { name: 'Silver Plan' },
106
+ amount: 4999, currency: 'usd')
104
107
  sub = Stripe::Subscription.create({ plan: 'silver', customer: customer.id })
105
108
  customer = Stripe::Customer.retrieve(customer.id)
106
109
  expect(sub.plan.to_hash).to eq(plan.to_hash)
107
110
  expect(customer.subscriptions.count).to eq(1)
108
111
 
109
- plan = stripe_helper.create_plan(id: 'gold', name: 'Gold Plan', amount: 14999, currency: 'usd')
112
+ plan = stripe_helper.create_plan(id: 'gold', product: { name: 'Gold Plan' },
113
+ amount: 14999, currency: 'usd')
110
114
  sub = Stripe::Subscription.create({ plan: 'gold', customer: customer.id })
111
115
  customer = Stripe::Customer.retrieve(customer.id)
112
116
  expect(sub.plan.to_hash).to eq(plan.to_hash)
@@ -114,7 +118,8 @@ shared_examples 'Customer Subscriptions' do
114
118
  end
115
119
 
116
120
  it 'creates a charge for the customer', live: true do
117
- stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999)
121
+ stripe_helper.create_plan(id: 'silver', product: { name: 'Silver Plan' },
122
+ amount: 4999)
118
123
 
119
124
  customer = Stripe::Customer.create(source: gen_card_tk)
120
125
  Stripe::Subscription.create({ plan: 'silver', customer: customer.id, metadata: { foo: "bar", example: "yes" } })
@@ -125,7 +130,8 @@ shared_examples 'Customer Subscriptions' do
125
130
  end
126
131
 
127
132
  it 'contains coupon object', live: true do
128
- plan = stripe_helper.create_plan(id: 'plan_with_coupon', name: 'One More Test Plan', amount: 777)
133
+ plan = stripe_helper.create_plan(id: 'plan_with_coupon', product: { name: 'One More Test Plan' },
134
+ amount: 777)
129
135
  coupon = stripe_helper.create_coupon(id: 'free_coupon', duration: 'repeating', duration_in_months: 3)
130
136
  customer = Stripe::Customer.create(source: gen_card_tk)
131
137
  Stripe::Subscription.create(plan: plan.id, customer: customer.id, coupon: coupon.id)
@@ -139,7 +145,8 @@ shared_examples 'Customer Subscriptions' do
139
145
  end
140
146
 
141
147
  it 'when coupon is not exist', live: true do
142
- plan = stripe_helper.create_plan(id: 'plan_with_coupon', name: 'One More Test Plan', amount: 777)
148
+ plan = stripe_helper.create_plan(id: 'plan_with_coupon', product: { name: 'One More Test Plan' },
149
+ amount: 777)
143
150
  customer = Stripe::Customer.create(source: gen_card_tk)
144
151
 
145
152
  expect { Stripe::Subscription.create(plan: plan.id, customer: customer.id, coupon: 'none') }.to raise_error {|e|
@@ -153,7 +160,9 @@ shared_examples 'Customer Subscriptions' do
153
160
  Stripe::Plan.create(
154
161
  :amount => 2500,
155
162
  :interval => 'month',
156
- :name => 'Test plan',
163
+ :product => {
164
+ :name => 'Test plan'
165
+ },
157
166
  :currency => 'usd',
158
167
  :id => 'silver',
159
168
  :statement_description => "testPlan"
@@ -169,7 +178,8 @@ shared_examples 'Customer Subscriptions' do
169
178
 
170
179
  it "correctly sets created when it's not provided as a parameter", live: true do
171
180
  customer = Stripe::Customer.create(source: gen_card_tk)
172
- plan = stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999, currency: 'usd')
181
+ plan = stripe_helper.create_plan(id: 'silver', product: { name: 'Silver Plan' },
182
+ amount: 4999, currency: 'usd')
173
183
  subscription = Stripe::Subscription.create({ plan: 'silver', customer: customer.id })
174
184
 
175
185
  expect(subscription.created).to eq(subscription.current_period_start)
@@ -177,7 +187,8 @@ shared_examples 'Customer Subscriptions' do
177
187
 
178
188
  it "correctly sets created when it's provided as a parameter" do
179
189
  customer = Stripe::Customer.create(source: gen_card_tk)
180
- plan = stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999, currency: 'usd')
190
+ plan = stripe_helper.create_plan(id: 'silver', product: { name: 'Silver Plan' },
191
+ amount: 4999, currency: 'usd')
181
192
  subscription = Stripe::Subscription.create({ plan: 'silver', customer: customer.id, created: 1473576318 })
182
193
 
183
194
  expect(subscription.created).to eq(1473576318)
@@ -436,6 +447,8 @@ shared_examples 'Customer Subscriptions' do
436
447
  expect(subscription.plan).to eq nil
437
448
  expect(subscription.items.data[0].plan.id).to eq plan.id
438
449
  expect(subscription.items.data[1].plan.id).to eq plan2.id
450
+ expect(subscription.items.data[0].quantity).to eq 1
451
+ expect(subscription.items.data[1].quantity).to eq 2
439
452
  end
440
453
 
441
454
  it 'when plan defined inside items for trials with no card', live: true do
@@ -569,7 +582,8 @@ shared_examples 'Customer Subscriptions' do
569
582
  end
570
583
 
571
584
  it 'when adds coupon', live: true do
572
- plan = stripe_helper.create_plan(id: 'plan_with_coupon2', name: 'One More Test Plan', amount: 777)
585
+ plan = stripe_helper.create_plan(id: 'plan_with_coupon2', product: { name: 'One More Test Plan' },
586
+ amount: 777)
573
587
  coupon = stripe_helper.create_coupon
574
588
  customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
575
589
  subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
@@ -583,7 +597,8 @@ shared_examples 'Customer Subscriptions' do
583
597
  end
584
598
 
585
599
  it 'when add not exist coupon' do
586
- plan = stripe_helper.create_plan(id: 'plan_with_coupon3', name: 'One More Test Plan', amount: 777)
600
+ plan = stripe_helper.create_plan(id: 'plan_with_coupon3', product: { name: 'One More Test Plan' },
601
+ amount: 777)
587
602
  customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
588
603
  subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
589
604
 
@@ -598,7 +613,8 @@ shared_examples 'Customer Subscriptions' do
598
613
  end
599
614
 
600
615
  it 'when coupon is removed' do
601
- plan = stripe_helper.create_plan(id: 'plan_with_coupon3', name: 'One More Test Plan', amount: 777)
616
+ plan = stripe_helper.create_plan(id: 'plan_with_coupon3', product: { name: 'One More Test Plan' },
617
+ amount: 777)
602
618
  customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
603
619
  coupon = stripe_helper.create_coupon
604
620
  subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
@@ -962,10 +978,13 @@ shared_examples 'Customer Subscriptions' do
962
978
 
963
979
  it "creates a stripe customer and subscribes them to a plan with meta data", :live => true do
964
980
 
965
- stripe_helper.create_plan(
981
+ stripe_helper.
982
+ create_plan(
966
983
  :amount => 500,
967
984
  :interval => 'month',
968
- :name => 'Sample Plan',
985
+ :product => {
986
+ :name => 'Sample Plan'
987
+ },
969
988
  :currency => 'usd',
970
989
  :id => 'Sample5'
971
990
  )
@@ -2,24 +2,40 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples 'Transfer API' do
4
4
 
5
- it "creates a stripe transfer", skip: 'Stripe has deprecated Recipients' do
6
- recipient = Stripe::Recipient.create(type: "corporation", name: "MyCo")
7
- transfer = Stripe::Transfer.create(amount: "100", currency: "usd", recipient: recipient.id)
5
+ it "creates a stripe transfer" do
6
+ destination = Stripe::Account.create(email: "#{SecureRandom.uuid}@example.com", id: "acct_12345")
7
+ transfer = Stripe::Transfer.create(amount: 100, currency: "usd", destination: destination.id)
8
8
 
9
9
  expect(transfer.id).to match /^test_tr/
10
- expect(transfer.amount).to eq('100')
10
+ expect(transfer.amount).to eq(100)
11
+ expect(transfer.amount_reversed).to eq(0)
12
+ expect(transfer.balance_transaction).to eq('txn_2dyYXXP90MN26R')
13
+ expect(transfer.created).to eq(1304114826)
11
14
  expect(transfer.currency).to eq('usd')
12
- expect(transfer.recipient).to eq recipient.id
15
+ expect(transfer.description).to eq('Transfer description')
16
+ expect(transfer.destination).to eq('acct_12345')
17
+ expect(transfer.destination_payment).to eq("py_164xRvKbnvuxQXGuVFV2pZo1")
18
+ expect(transfer.livemode).to eq(false)
19
+ expect(transfer.metadata).to eq(Stripe::StripeObject.new)
20
+ expect(transfer.reversals).to eq(Stripe::ListObject.construct_from({
21
+ object: "list",
22
+ data: [],
23
+ total_count: 0,
24
+ has_more: false,
25
+ url: "/v1/transfers/#{transfer.id}/reversals"
26
+ }))
13
27
  expect(transfer.reversed).to eq(false)
14
- expect(transfer.metadata).to eq({})
28
+ expect(transfer.source_transaction).to eq("ch_164xRv2eZvKYlo2Clu1sIJWB")
29
+ expect(transfer.source_type).to eq("card")
30
+ expect(transfer.transfer_group).to eq("group_ch_164xRv2eZvKYlo2Clu1sIJWB")
15
31
  end
16
32
 
17
- describe "listing transfers", skip: 'Stripe has deprecated Recipients' do
18
- let(:recipient) { Stripe::Recipient.create(type: "corporation", name: "MyCo") }
33
+ describe "listing transfers" do
34
+ let(:destination) { Stripe::Account.create(email: "#{SecureRandom.uuid}@example.com", business_name: "MyCo") }
19
35
 
20
36
  before do
21
37
  3.times do
22
- Stripe::Transfer.create(amount: "100", currency: "usd", recipient: recipient.id)
38
+ Stripe::Transfer.create(amount: "100", currency: "usd", destination: destination.id)
23
39
  end
24
40
  end
25
41
 
@@ -31,27 +47,48 @@ shared_examples 'Transfer API' do
31
47
  expect(Stripe::Transfer.all(limit: 2).count).to eq(2)
32
48
  end
33
49
 
34
- it "filters the search to a specific recipient" do
35
- r2 = Stripe::Recipient.create(type: "corporation", name: "MyCo")
36
- Stripe::Transfer.create(amount: "100", currency: "usd", recipient: r2.id)
50
+ it "filters the search to a specific destination" do
51
+ d2 = Stripe::Account.create(email: "#{SecureRandom.uuid}@example.com", business_name: "MyCo")
52
+ Stripe::Transfer.create(amount: "100", currency: "usd", destination: d2.id)
37
53
 
38
- expect(Stripe::Transfer.all(recipient: r2.id).count).to eq(1)
54
+ expect(Stripe::Transfer.all(destination: d2.id).count).to eq(1)
55
+ end
56
+
57
+ it "disallows unknown parameters" do
58
+ expect { Stripe::Transfer.all(recipient: "foo") }.to raise_error {|e|
59
+ expect(e).to be_a Stripe::InvalidRequestError
60
+ expect(e.param).to eq("recipient")
61
+ expect(e.message).to eq("Received unknown parameter: recipient")
62
+ expect(e.http_status).to eq(400)
63
+ }
39
64
  end
40
65
  end
41
66
 
42
67
 
43
68
  it "retrieves a stripe transfer" do
44
- original = Stripe::Transfer.create(amount: "100", currency: "usd")
69
+ original = Stripe::Transfer.create(amount: "100", currency: "usd")
45
70
  transfer = Stripe::Transfer.retrieve(original.id)
46
71
 
47
72
  expect(transfer.id).to eq(original.id)
73
+ expect(transfer.object).to eq(original.object)
48
74
  expect(transfer.amount).to eq(original.amount)
75
+ expect(transfer.amount_reversed).to eq(original.amount_reversed)
76
+ expect(transfer.balance_transaction).to eq(original.balance_transaction)
77
+ expect(transfer.created).to eq(original.created)
49
78
  expect(transfer.currency).to eq(original.currency)
50
- expect(transfer.recipient).to eq(original.recipient)
79
+ expect(transfer.description).to eq(original.description)
80
+ expect(transfer.destination).to eq(original.destination)
81
+ expect(transfer.destination_payment).to eq(original.destination_payment)
82
+ expect(transfer.livemode).to eq(original.livemode)
51
83
  expect(transfer.metadata).to eq(original.metadata)
84
+ expect(transfer.reversals).to eq(original.reversals)
85
+ expect(transfer.reversed).to eq(original.reversed)
86
+ expect(transfer.source_transaction).to eq(original.source_transaction)
87
+ expect(transfer.source_type).to eq(original.source_type)
88
+ expect(transfer.transfer_group).to eq(original.transfer_group)
52
89
  end
53
90
 
54
- it "canceles a stripe transfer " do
91
+ it "cancels a stripe transfer" do
55
92
  original = Stripe::Transfer.create(amount: "100", currency: "usd")
56
93
  res, api_key = Stripe::StripeClient.active_client.execute_request(:post, "/v1/transfers/#{original.id}/cancel", api_key: 'api_key')
57
94
 
@@ -66,29 +103,23 @@ shared_examples 'Transfer API' do
66
103
  }
67
104
  end
68
105
 
69
- it 'when amount is not integer', live: true, skip: 'Stripe has deprecated Recipients' do
70
- rec = Stripe::Recipient.create({
71
- type: 'individual',
72
- name: 'Alex Smith',
73
- })
106
+ it "when amount is not integer", live: true do
107
+ dest = Stripe::Account.create(type: "standard", email: "#{SecureRandom.uuid}@example.com", business_name: "Alex Smith")
74
108
  expect { Stripe::Transfer.create(amount: '400.2',
75
- currency: 'usd',
76
- recipient: rec.id,
77
- description: 'Transfer for test@example.com') }.to raise_error { |e|
109
+ currency: 'usd',
110
+ destination: dest.id,
111
+ description: 'Transfer for test@example.com') }.to raise_error { |e|
78
112
  expect(e).to be_a Stripe::InvalidRequestError
79
113
  expect(e.param).to eq('amount')
80
114
  expect(e.http_status).to eq(400)
81
115
  }
82
116
  end
83
117
 
84
- it 'when amount is negative', live: true, skip: 'Stripe has deprecated Recipients' do
85
- rec = Stripe::Recipient.create({
86
- type: 'individual',
87
- name: 'Alex Smith',
88
- })
118
+ it "when amount is negative", live: true do
119
+ dest = Stripe::Account.create(type: "standard", email: "#{SecureRandom.uuid}@example.com", business_name: "Alex Smith")
89
120
  expect { Stripe::Transfer.create(amount: '-400',
90
121
  currency: 'usd',
91
- recipient: rec.id,
122
+ destination: dest.id,
92
123
  description: 'Transfer for test@example.com') }.to raise_error { |e|
93
124
  expect(e).to be_a Stripe::InvalidRequestError
94
125
  expect(e.param).to eq('amount')
@@ -29,6 +29,7 @@ def it_behaves_like_stripe(&block)
29
29
  it_behaves_like 'Customer Subscriptions', &block
30
30
  it_behaves_like 'Webhook Events API', &block
31
31
  it_behaves_like 'Country Spec API', &block
32
+ it_behaves_like 'EphemeralKey API', &block
32
33
 
33
34
  # Integration tests
34
35
  it_behaves_like 'Multiple Customer Cards'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.4
4
+ version: 2.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-04 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stripe
@@ -144,6 +144,7 @@ files:
144
144
  - lib/stripe_mock/request_handlers/coupons.rb
145
145
  - lib/stripe_mock/request_handlers/customers.rb
146
146
  - lib/stripe_mock/request_handlers/disputes.rb
147
+ - lib/stripe_mock/request_handlers/ephemeral_key.rb
147
148
  - lib/stripe_mock/request_handlers/events.rb
148
149
  - lib/stripe_mock/request_handlers/external_accounts.rb
149
150
  - lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb
@@ -238,6 +239,7 @@ files:
238
239
  - spec/shared_stripe_examples/coupon_examples.rb
239
240
  - spec/shared_stripe_examples/customer_examples.rb
240
241
  - spec/shared_stripe_examples/dispute_examples.rb
242
+ - spec/shared_stripe_examples/ephemeral_key_examples.rb
241
243
  - spec/shared_stripe_examples/error_mock_examples.rb
242
244
  - spec/shared_stripe_examples/external_account_examples.rb
243
245
  - spec/shared_stripe_examples/extra_features_examples.rb
@@ -305,6 +307,7 @@ test_files:
305
307
  - spec/shared_stripe_examples/coupon_examples.rb
306
308
  - spec/shared_stripe_examples/customer_examples.rb
307
309
  - spec/shared_stripe_examples/dispute_examples.rb
310
+ - spec/shared_stripe_examples/ephemeral_key_examples.rb
308
311
  - spec/shared_stripe_examples/error_mock_examples.rb
309
312
  - spec/shared_stripe_examples/external_account_examples.rb
310
313
  - spec/shared_stripe_examples/extra_features_examples.rb