stripe-ruby-mock 2.4.0 → 2.5.8

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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/.env +2 -0
  3. data/.travis.yml +8 -4
  4. data/README.md +12 -5
  5. data/lib/stripe_mock/api/account_balance.rb +14 -0
  6. data/lib/stripe_mock/api/client.rb +4 -4
  7. data/lib/stripe_mock/api/conversion_rate.rb +14 -0
  8. data/lib/stripe_mock/api/errors.rb +25 -14
  9. data/lib/stripe_mock/api/instance.rb +6 -6
  10. data/lib/stripe_mock/api/webhooks.rb +5 -1
  11. data/lib/stripe_mock/client.rb +18 -2
  12. data/lib/stripe_mock/data/list.rb +14 -2
  13. data/lib/stripe_mock/data.rb +217 -56
  14. data/lib/stripe_mock/instance.rb +93 -8
  15. data/lib/stripe_mock/request_handlers/accounts.rb +34 -2
  16. data/lib/stripe_mock/request_handlers/balance.rb +17 -0
  17. data/lib/stripe_mock/request_handlers/balance_transactions.rb +18 -2
  18. data/lib/stripe_mock/request_handlers/charges.rb +25 -17
  19. data/lib/stripe_mock/request_handlers/coupons.rb +5 -4
  20. data/lib/stripe_mock/request_handlers/customers.rb +26 -8
  21. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
  22. data/lib/stripe_mock/request_handlers/external_accounts.rb +55 -0
  23. data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +1 -1
  24. data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +9 -7
  25. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +10 -6
  26. data/lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb +49 -0
  27. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +55 -15
  28. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -2
  29. data/lib/stripe_mock/request_handlers/invoices.rb +93 -14
  30. data/lib/stripe_mock/request_handlers/orders.rb +5 -5
  31. data/lib/stripe_mock/request_handlers/payouts.rb +32 -0
  32. data/lib/stripe_mock/request_handlers/plans.rb +1 -0
  33. data/lib/stripe_mock/request_handlers/products.rb +43 -0
  34. data/lib/stripe_mock/request_handlers/refunds.rb +10 -7
  35. data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
  36. data/lib/stripe_mock/request_handlers/subscriptions.rb +95 -34
  37. data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
  38. data/lib/stripe_mock/request_handlers/tokens.rb +9 -3
  39. data/lib/stripe_mock/request_handlers/transfers.rb +11 -5
  40. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +10 -1
  41. data/lib/stripe_mock/server.rb +14 -1
  42. data/lib/stripe_mock/test_strategies/base.rb +7 -5
  43. data/lib/stripe_mock/test_strategies/live.rb +5 -0
  44. data/lib/stripe_mock/test_strategies/mock.rb +8 -0
  45. data/lib/stripe_mock/util.rb +8 -2
  46. data/lib/stripe_mock/version.rb +1 -1
  47. data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
  48. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
  49. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
  50. data/lib/stripe_mock/webhook_fixtures/charge.updated.json +58 -0
  51. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +40 -10
  52. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +39 -10
  53. data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +39 -10
  54. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +40 -11
  55. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +3 -2
  56. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +1 -1
  57. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +92 -85
  58. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +3 -2
  59. data/lib/stripe_mock/webhook_fixtures/plan.created.json +1 -1
  60. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +1 -1
  61. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +1 -1
  62. data/lib/stripe_mock.rb +13 -0
  63. data/spec/instance_spec.rb +54 -4
  64. data/spec/integration_examples/prepare_error_examples.rb +6 -6
  65. data/spec/list_spec.rb +16 -3
  66. data/spec/readme_spec.rb +2 -0
  67. data/spec/server_spec.rb +6 -2
  68. data/spec/shared_stripe_examples/account_examples.rb +35 -0
  69. data/spec/shared_stripe_examples/balance_examples.rb +11 -0
  70. data/spec/shared_stripe_examples/balance_transaction_examples.rb +28 -0
  71. data/spec/shared_stripe_examples/bank_examples.rb +28 -1
  72. data/spec/shared_stripe_examples/card_examples.rb +10 -3
  73. data/spec/shared_stripe_examples/charge_examples.rb +73 -17
  74. data/spec/shared_stripe_examples/coupon_examples.rb +8 -2
  75. data/spec/shared_stripe_examples/customer_examples.rb +54 -2
  76. data/spec/shared_stripe_examples/dispute_examples.rb +19 -8
  77. data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
  78. data/spec/shared_stripe_examples/error_mock_examples.rb +3 -3
  79. data/spec/shared_stripe_examples/external_account_examples.rb +170 -0
  80. data/spec/shared_stripe_examples/extra_features_examples.rb +2 -0
  81. data/spec/shared_stripe_examples/invoice_examples.rb +314 -51
  82. data/spec/shared_stripe_examples/payout_examples.rb +68 -0
  83. data/spec/shared_stripe_examples/plan_examples.rb +37 -5
  84. data/spec/shared_stripe_examples/product_example.rb +65 -0
  85. data/spec/shared_stripe_examples/recipient_examples.rb +7 -7
  86. data/spec/shared_stripe_examples/refund_examples.rb +17 -11
  87. data/spec/shared_stripe_examples/subscription_examples.rb +463 -33
  88. data/spec/shared_stripe_examples/subscription_items_examples.rb +75 -0
  89. data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
  90. data/spec/shared_stripe_examples/transfer_examples.rb +72 -23
  91. data/spec/shared_stripe_examples/webhook_event_examples.rb +74 -5
  92. data/spec/spec_helper.rb +7 -6
  93. data/spec/stripe_mock_spec.rb +16 -3
  94. data/spec/support/stripe_examples.rb +7 -1
  95. data/spec/util_spec.rb +35 -1
  96. data/stripe-ruby-mock.gemspec +1 -1
  97. metadata +34 -7
  98. data/ChangeLog.rdoc +0 -4
@@ -3,10 +3,11 @@
3
3
  "livemode": false,
4
4
  "id": "evt_00000000000000",
5
5
  "type": "invoice.created",
6
+ "status": "paid",
6
7
  "object": "event",
7
8
  "data": {
8
9
  "object": {
9
- "date": 1380674206,
10
+ "created": 1380674206,
10
11
  "id": "in_00000000000000",
11
12
  "period_start": 1378082075,
12
13
  "period_end": 1380674075,
@@ -30,7 +31,6 @@
30
31
  "quantity": 1,
31
32
  "plan": {
32
33
  "interval": "month",
33
- "name": "Member's Club",
34
34
  "amount": 100,
35
35
  "currency": "usd",
36
36
  "id": "fkx0AFo",
@@ -38,6 +38,7 @@
38
38
  "livemode": false,
39
39
  "interval_count": 1,
40
40
  "trial_period_days": null,
41
+ "product": "pr_00000000000000",
41
42
  "metadata": {}
42
43
  },
43
44
  "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",
@@ -6,100 +6,107 @@
6
6
  "object": "event",
7
7
  "data": {
8
8
  "object": {
9
- "date": 1394018368,
10
9
  "id": "in_00000000000000",
11
- "period_start": 1394018368,
12
- "period_end": 1394018368,
10
+ "object": "invoice",
11
+ "amount_due": 999,
12
+ "application_fee": null,
13
+ "attempt_count": 1,
14
+ "attempted": true,
15
+ "charge": "ch_18EcOcLrgDIZ7iq8TaNlErVv",
16
+ "closed": true,
17
+ "currency": "eur",
18
+ "customer": "cus_00000000000000",
19
+ "created": 1464084258,
20
+ "description": null,
21
+ "discount": null,
22
+ "ending_balance": 0,
23
+ "forgiven": false,
13
24
  "lines": {
14
- "object": "list",
15
- "count": 3,
16
- "url": "/v1/invoices/in_00000000000000/lines",
17
- "data": [
18
- {
19
- "id": "ii_00000000000000",
20
- "object": "line_item",
21
- "type": "invoiceitem",
22
- "livemode": false,
23
- "amount": 19000,
24
- "currency": "usd",
25
- "proration": true,
26
- "period": {
27
- "start": 1393765661,
28
- "end": 1393765661
29
- },
30
- "quantity": null,
31
- "plan": null,
32
- "description": "Remaining time on Platinum after 02 Mar 2014",
33
- "metadata": {}
25
+ "data": [{
26
+ "id": "sub_00000000000000",
27
+ "object": "line_item",
28
+ "amount": 50,
29
+ "currency": "eur",
30
+ "description": null,
31
+ "discountable": true,
32
+ "livemode": true,
33
+ "metadata": {},
34
+ "period": {
35
+ "start": 1500637196,
36
+ "end": 1532173196
34
37
  },
35
- {
36
- "id": "ii_00000000000001",
37
- "object": "line_item",
38
- "type": "invoiceitem",
38
+ "plan": {
39
+ "id": "platinum",
40
+ "object": "plan",
41
+ "amount": 500,
42
+ "created": 1499943145,
43
+ "currency": "eur",
44
+ "interval": "month",
45
+ "interval_count": 1,
39
46
  "livemode": false,
40
- "amount": -9000,
41
- "currency": "usd",
42
- "proration": true,
43
- "period": {
44
- "start": 1393765661,
45
- "end": 1393765661
46
- },
47
- "quantity": null,
48
- "plan": null,
49
- "description": "Unused time on Gold after 05 Mar 2014",
50
- "metadata": {}
47
+ "metadata": {},
48
+ "name": "New Plan Test",
49
+ "statement_descriptor": null,
50
+ "trial_period_days": null
51
+ },
52
+ "proration": false,
53
+ "quantity": 1,
54
+ "subscription": null,
55
+ "subscription_item": "si_18ZfWyLrgDIZ7iq8fSlSNGIV",
56
+ "type": "subscription"
57
+ },
58
+ {
59
+ "id": "sub_00000000000000",
60
+ "object": "line_item",
61
+ "amount": 50,
62
+ "currency": "eur",
63
+ "description": null,
64
+ "discountable": true,
65
+ "livemode": true,
66
+ "metadata": {},
67
+ "period": {
68
+ "start": 1500637196,
69
+ "end": 1532173196
51
70
  },
52
- {
53
- "id": "su_00000000000000",
54
- "object": "line_item",
55
- "type": "subscription",
71
+ "plan": {
72
+ "id": "gold",
73
+ "object": "plan",
74
+ "amount": 300,
75
+ "created": 1499943155,
76
+ "currency": "eur",
77
+ "interval": "month",
78
+ "interval_count": 1,
56
79
  "livemode": false,
57
- "amount": 20000,
58
- "currency": "usd",
59
- "proration": false,
60
- "period": {
61
- "start": 1383759053,
62
- "end": 1386351053
63
- },
64
- "quantity": 1,
65
- "plan": {
66
- "interval": "month",
67
- "name": "Platinum",
68
- "created": 1300000000,
69
- "amount": 20000,
70
- "currency": "usd",
71
- "id": "platinum",
72
- "object": "plan",
73
- "livemode": false,
74
- "interval_count": 1,
75
- "trial_period_days": null,
76
- "metadata": {}
77
- },
78
- "description": null,
79
- "metadata": null
80
- }
81
- ]
80
+ "metadata": {},
81
+ "name": "New gold Plan Test",
82
+ "statement_descriptor": null,
83
+ "trial_period_days": null
84
+ },
85
+ "proration": false,
86
+ "quantity": 1,
87
+ "subscription": null,
88
+ "subscription_item": "si_18ZfWyLrgDIZ7iq8fSlSNGIV",
89
+ "type": "subscription"
90
+ }],
91
+ "total_count": 1,
92
+ "object": "list",
93
+ "url": "/v1/invoices/in_18EcOcLrgDIZ7iq8zsDkunZ0/lines"
82
94
  },
83
- "subtotal": 30000,
84
- "total": 30000,
85
- "customer": "cus_00000000000000",
86
- "object": "invoice",
87
- "attempted": true,
88
- "closed": true,
89
- "paid": true,
90
95
  "livemode": false,
91
- "attempt_count": 1,
92
- "amount_due": 0,
93
- "currency": "usd",
94
- "starting_balance": 0,
95
- "ending_balance": 0,
96
- "next_payment_attempt": null,
97
- "charge": "ch_00000000000000",
98
- "discount": null,
99
- "application_fee": null,
100
- "subscription": "su_00000000000000",
101
96
  "metadata": {},
102
- "description": null
97
+ "next_payment_attempt": null,
98
+ "paid": true,
99
+ "period_end": 1464084258,
100
+ "period_start": 1464084258,
101
+ "receipt_number": null,
102
+ "starting_balance": 0,
103
+ "statement_descriptor": null,
104
+ "subscription": "sub_00000000000000",
105
+ "subtotal": 999,
106
+ "tax": null,
107
+ "tax_percent": null,
108
+ "total": 999,
109
+ "webhooks_delivered_at": 1464084258
103
110
  }
104
111
  }
105
112
  }
@@ -3,10 +3,11 @@
3
3
  "livemode": false,
4
4
  "id": "evt_00000000000000",
5
5
  "type": "invoice.updated",
6
+ "status": "paid",
6
7
  "object": "event",
7
8
  "data": {
8
9
  "object": {
9
- "date": 1380674206,
10
+ "created": 1380674206,
10
11
  "id": "in_00000000000000",
11
12
  "period_start": 1378082075,
12
13
  "period_end": 1380674075,
@@ -30,7 +31,7 @@
30
31
  "quantity": 1,
31
32
  "plan": {
32
33
  "interval": "month",
33
- "name": "Member's Club",
34
+ "product": "pr_00000000000000",
34
35
  "amount": 100,
35
36
  "currency": "usd",
36
37
  "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",
data/lib/stripe_mock.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ostruct'
2
2
  require 'multi_json'
3
3
  require 'dante'
4
+ require 'time'
4
5
 
5
6
  require 'stripe'
6
7
 
@@ -26,6 +27,8 @@ require 'stripe_mock/api/client'
26
27
  require 'stripe_mock/api/server'
27
28
 
28
29
  require 'stripe_mock/api/bank_tokens'
30
+ require 'stripe_mock/api/account_balance'
31
+ require 'stripe_mock/api/conversion_rate'
29
32
  require 'stripe_mock/api/card_tokens'
30
33
  require 'stripe_mock/api/debug'
31
34
  require 'stripe_mock/api/errors'
@@ -35,6 +38,7 @@ require 'stripe_mock/api/test_helpers'
35
38
  require 'stripe_mock/api/webhooks'
36
39
 
37
40
  require 'stripe_mock/request_handlers/helpers/bank_account_helpers.rb'
41
+ require 'stripe_mock/request_handlers/helpers/external_account_helpers.rb'
38
42
  require 'stripe_mock/request_handlers/helpers/card_helpers.rb'
39
43
  require 'stripe_mock/request_handlers/helpers/charge_helpers.rb'
40
44
  require 'stripe_mock/request_handlers/helpers/coupon_helpers.rb'
@@ -44,6 +48,8 @@ require 'stripe_mock/request_handlers/helpers/token_helpers.rb'
44
48
  require 'stripe_mock/request_handlers/validators/param_validators.rb'
45
49
 
46
50
  require 'stripe_mock/request_handlers/accounts.rb'
51
+ require 'stripe_mock/request_handlers/external_accounts.rb'
52
+ require 'stripe_mock/request_handlers/balance.rb'
47
53
  require 'stripe_mock/request_handlers/balance_transactions.rb'
48
54
  require 'stripe_mock/request_handlers/charges.rb'
49
55
  require 'stripe_mock/request_handlers/cards.rb'
@@ -59,9 +65,14 @@ require 'stripe_mock/request_handlers/plans.rb'
59
65
  require 'stripe_mock/request_handlers/recipients.rb'
60
66
  require 'stripe_mock/request_handlers/refunds.rb'
61
67
  require 'stripe_mock/request_handlers/transfers.rb'
68
+ require 'stripe_mock/request_handlers/payouts.rb'
62
69
  require 'stripe_mock/request_handlers/subscriptions.rb'
70
+ require 'stripe_mock/request_handlers/subscription_items.rb'
63
71
  require 'stripe_mock/request_handlers/tokens.rb'
64
72
  require 'stripe_mock/request_handlers/country_spec.rb'
73
+ require 'stripe_mock/request_handlers/ephemeral_key.rb'
74
+ require 'stripe_mock/request_handlers/products.rb'
75
+ require 'stripe_mock/request_handlers/tax_rates.rb'
65
76
  require 'stripe_mock/instance'
66
77
 
67
78
  require 'stripe_mock/test_strategies/base.rb'
@@ -70,11 +81,13 @@ require 'stripe_mock/test_strategies/live.rb'
70
81
 
71
82
  module StripeMock
72
83
 
84
+ @default_currency = 'usd'
73
85
  lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
74
86
  @webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
75
87
  @webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
76
88
 
77
89
  class << self
90
+ attr_accessor :default_currency
78
91
  attr_accessor :webhook_fixture_path
79
92
  end
80
93
  end
@@ -17,9 +17,9 @@ describe StripeMock::Instance do
17
17
  "id" => "str_abcde",
18
18
  :name => "String Plan"
19
19
  )
20
- res, api_key = StripeMock.instance.mock_request('post', '/v1/plans', 'api_key', string_params)
21
- expect(res[:id]).to eq('str_abcde')
22
- expect(res[:name]).to eq('String Plan')
20
+ res, api_key = StripeMock.instance.mock_request('post', '/v1/plans', api_key: 'api_key', params: string_params)
21
+ expect(res.data[:id]).to eq('str_abcde')
22
+ expect(res.data[:name]).to eq('String Plan')
23
23
  end
24
24
 
25
25
  it "exits gracefully on an unrecognized handler url" do
@@ -28,7 +28,7 @@ describe StripeMock::Instance do
28
28
  "name" => "PLAN"
29
29
  }
30
30
 
31
- expect { res, api_key = StripeMock.instance.mock_request('post', '/v1/unrecongnized_method', 'api_key', dummy_params) }.to_not raise_error
31
+ expect { res, api_key = StripeMock.instance.mock_request('post', '/v1/unrecongnized_method', api_key: 'api_key', params: dummy_params) }.to_not raise_error
32
32
  end
33
33
 
34
34
  it "can toggle debug" do
@@ -47,4 +47,54 @@ describe StripeMock::Instance do
47
47
  StripeMock.start
48
48
  expect(StripeMock.instance.debug).to eq(false)
49
49
  end
50
+
51
+ it "can set a conversion rate" do
52
+ StripeMock.set_conversion_rate(1.25)
53
+ expect(StripeMock.instance.conversion_rate).to eq(1.25)
54
+ end
55
+
56
+ it "allows non-usd default currency" do
57
+ old_default_currency = StripeMock.default_currency
58
+ customer = begin
59
+ StripeMock.default_currency = "jpy"
60
+ Stripe::Customer.create({
61
+ email: 'johnny@appleseed.com',
62
+ source: stripe_helper.generate_card_token
63
+ })
64
+ ensure
65
+ StripeMock.default_currency = old_default_currency
66
+ end
67
+ expect(customer.currency).to eq("jpy")
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
50
100
  end
@@ -26,13 +26,13 @@ shared_examples 'Card Error Prep' do
26
26
  )
27
27
  rescue Stripe::CardError => e
28
28
  body = e.json_body
29
- err = body[:error]
30
-
31
29
  expect(body).to be_a(Hash)
32
- expect(err[:type]).to eq 'card_error'
33
- expect(err[:param]).to eq 'number'
34
- expect(err[:code]).to eq 'invalid_number'
35
- expect(err[:message]).to eq 'The card number is not a valid credit card number.'
30
+ error = body[:error]
31
+
32
+ expect(error[:type]).to eq 'card_error'
33
+ expect(error[:param]).to eq 'number'
34
+ expect(error[:code]).to eq 'invalid_number'
35
+ expect(error[:message]).to eq 'The card number is not a valid credit card number.'
36
36
  end
37
37
  end
38
38
  end
data/spec/list_spec.rb CHANGED
@@ -34,6 +34,20 @@ describe StripeMock::Data::List do
34
34
  expect(list.url).to eq("/v1/customers")
35
35
  end
36
36
 
37
+ it "returns in descending order if created available" do
38
+ charge_newer = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token, created: 5)
39
+ charge_older = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token, created: 4)
40
+ list = StripeMock::Data::List.new([charge_older, charge_newer])
41
+ hash = list.to_h
42
+
43
+ expect(hash).to eq(
44
+ object: "list",
45
+ data: [charge_newer, charge_older],
46
+ url: "/v1/charges",
47
+ has_more: false
48
+ )
49
+ end
50
+
37
51
  it "eventually gets turned into a hash" do
38
52
  charge1 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
39
53
  charge2 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
@@ -43,7 +57,7 @@ describe StripeMock::Data::List do
43
57
 
44
58
  expect(hash).to eq(
45
59
  object: "list",
46
- data: [charge1, charge2, charge3],
60
+ data: [charge3, charge2, charge1],
47
61
  url: "/v1/charges",
48
62
  has_more: false
49
63
  )
@@ -111,9 +125,8 @@ describe StripeMock::Data::List do
111
125
  data[89] = new_charge
112
126
  list = StripeMock::Data::List.new(data, starting_after: new_charge.id)
113
127
  hash = list.to_h
114
-
115
128
  expect(hash[:data].size).to eq(10)
116
- expect(hash[:data]).to eq(data[90, 10])
129
+ expect(hash[:data]).to eq(data[79, 10].reverse)
117
130
  end
118
131
 
119
132
  it "raises an error if starting_after cursor is not found" do
data/spec/readme_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'stripe_mock'
1
2
 
2
3
  describe 'README examples' do
3
4
  let(:stripe_helper) { StripeMock.create_test_helper }
@@ -24,6 +25,7 @@ describe 'README examples' do
24
25
  expect(e).to be_a Stripe::CardError
25
26
  expect(e.http_status).to eq(402)
26
27
  expect(e.code).to eq('card_declined')
28
+ expect(e.json_body[:error][:decline_code]).to eq('do_not_honor')
27
29
  }
28
30
  end
29
31
 
data/spec/server_spec.rb CHANGED
@@ -52,8 +52,8 @@ describe 'StripeMock Server', :mock_server => true do
52
52
 
53
53
  it "returns a response with symbolized hash keys" do
54
54
  stripe_helper.create_plan(id: 'x')
55
- response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', 'xxx')
56
- response.keys.each {|k| expect(k).to be_a(Symbol) }
55
+ response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
56
+ response.data.keys.each {|k| expect(k).to be_a(Symbol) }
57
57
  end
58
58
 
59
59
 
@@ -132,4 +132,8 @@ describe 'StripeMock Server', :mock_server => true do
132
132
  end
133
133
  end
134
134
 
135
+ it "can set a conversion rate" do
136
+ StripeMock.set_conversion_rate(1.2)
137
+ expect(StripeMock.client.get_conversion_rate).to eq(1.2)
138
+ end
135
139
  end
@@ -49,6 +49,41 @@ shared_examples 'Account API' do
49
49
 
50
50
  expect(account.support_phone).to eq '1234567'
51
51
  end
52
+
53
+ it 'raises when sending an empty tos date' do
54
+ account = Stripe::Account.retrieve
55
+ account.tos_acceptance.date = nil
56
+ expect {
57
+ account.save
58
+ }.to raise_error
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
52
87
  end
53
88
 
54
89
  it 'deauthorizes the stripe account', live: false do
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Balance API' do
4
+
5
+ it "retrieves a stripe balance" do
6
+ StripeMock.set_account_balance(2000)
7
+ balance = Stripe::Balance.retrieve()
8
+ expect(balance.available[0].amount).to eq(2000)
9
+ end
10
+
11
+ end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples 'Balance Transaction API' do
4
4
 
5
+ let(:stripe_helper) { StripeMock.create_test_helper }
6
+
5
7
  it "returns an error if balance transaction does not exist" do
6
8
  txn_id = 'txn_xxxxxxxxxxxxxxxxxxxxxxxx'
7
9
 
@@ -32,4 +34,30 @@ shared_examples 'Balance Transaction API' do
32
34
 
33
35
  end
34
36
 
37
+ it 'retrieves balance transactions for an automated transfer' do
38
+ transfer_id = Stripe::Transfer.create({ amount: 2730, currency: "usd" })
39
+
40
+ # verify transfer currently has no balance transactions
41
+ transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id})
42
+ expect(transfer_transactions.count).to eq(0)
43
+
44
+ # verify we can create a new balance transaction associated with the transfer
45
+ new_txn_id = stripe_helper.upsert_stripe_object(:balance_transaction, {amount: 12300, transfer: transfer_id})
46
+ new_txn = Stripe::BalanceTransaction.retrieve(new_txn_id)
47
+ expect(new_txn).to be_a(Stripe::BalanceTransaction)
48
+ expect(new_txn.amount).to eq(12300)
49
+ # although transfer was specified as an attribute on the balance_transaction, it should not be returned in the object
50
+ expect{new_txn.transfer}.to raise_error(NoMethodError)
51
+
52
+ # verify we can update an existing balance transaction to associate with the transfer
53
+ existing_txn_id = 'txn_05RsQX2eZvKYlo2C0FRTGSSA'
54
+ existing_txn = Stripe::BalanceTransaction.retrieve(existing_txn_id)
55
+ stripe_helper.upsert_stripe_object(:balance_transaction, {id: existing_txn_id, transfer: transfer_id})
56
+
57
+ # now verify that only these balance transactions are retrieved with the transfer
58
+ transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id})
59
+ expect(transfer_transactions.count).to eq(2)
60
+ expect(transfer_transactions.map &:id).to include(new_txn_id, existing_txn_id)
61
+ end
62
+
35
63
  end
@@ -40,7 +40,7 @@ shared_examples 'Bank API' do
40
40
  expect(bank.last4).to eq("6789")
41
41
  end
42
42
 
43
- it "creates a single bank with a generated bank token", :live => true do
43
+ it "creates a single bank with a generated bank token" do
44
44
  customer = Stripe::Customer.create
45
45
  expect(customer.sources.count).to eq 0
46
46
 
@@ -199,4 +199,31 @@ shared_examples 'Bank API' do
199
199
  end
200
200
  end
201
201
 
202
+ describe 'Stripe::Token creation from bank account' do
203
+ it 'generates token from bank account informations' do
204
+ token = Stripe::Token.create({
205
+ bank_account: {
206
+ account_number: "4222222222222222",
207
+ routing_number: "123456",
208
+ bank_name: "Fake bank"
209
+ }
210
+ })
211
+
212
+ cus = Stripe::Customer.create(source: token.id)
213
+ bank_account = cus.sources.data.first
214
+ expect(bank_account.bank_name).to eq('Fake bank')
215
+ end
216
+
217
+ it 'generates token from existing bank account token' do
218
+ bank_token = StripeMock.generate_bank_token(bank_name: 'Fake bank')
219
+ cus = Stripe::Customer.create(source: bank_token)
220
+ token = Stripe::Token.create({ customer: cus.id, bank_account: cus.sources.first.id })
221
+ cus.sources.create(source: token.id)
222
+ cus = Stripe::Customer.retrieve(cus.id)
223
+ expect(cus.sources.data.count).to eq 2
224
+ cus.sources.data.each do |source|
225
+ expect(source.bank_name).to eq('Fake bank')
226
+ end
227
+ end
228
+ end
202
229
  end