stripe-ruby-mock 1.10.1.4 → 1.10.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  In your gemfile:
10
10
 
11
- gem 'stripe-ruby-mock', '~> 1.10.1.4'
11
+ gem 'stripe-ruby-mock', '~> 1.10.1.5'
12
12
 
13
13
  ## Features
14
14
 
@@ -20,6 +20,12 @@ module StripeMock
20
20
  url: "/v1/customers/#{cus_id}/cards",
21
21
  data: cards
22
22
  },
23
+ subscriptions: {
24
+ object: "list",
25
+ count: 0,
26
+ url: "/v1/customers/#{cus_id}/subscriptions",
27
+ data: []
28
+ },
23
29
  default_card: nil
24
30
  }.merge(params)
25
31
  end
@@ -259,15 +265,6 @@ module StripeMock
259
265
  }
260
266
  end
261
267
 
262
- def self.mock_subscriptions_array(params={})
263
- {
264
- :data => [],
265
- :count => 0,
266
- :object => "list",
267
- :url => '/v1/customers/test_customer/subscriptions',
268
- }.merge(params)
269
- end
270
-
271
268
  def self.mock_plan(params={})
272
269
  {
273
270
  interval: "month",
@@ -13,12 +13,12 @@ module StripeMock
13
13
  def new_customer(route, method_url, params, headers)
14
14
  params[:id] ||= new_id('cus')
15
15
  cards = []
16
+
16
17
  if params[:card]
17
18
  cards << get_card_by_token(params.delete(:card))
18
19
  params[:default_card] = cards.first[:id]
19
20
  end
20
21
 
21
- params[:subscriptions] = Data.mock_subscriptions_array(url: "/v1/customers/#{params[:id]}/subscriptions")
22
22
  customers[ params[:id] ] = Data.mock_customer(cards, params)
23
23
 
24
24
  if params[:plan]
@@ -18,7 +18,6 @@ module StripeMock
18
18
 
19
19
  subscription = Data.mock_subscription params
20
20
 
21
- cus[:subscriptions] = Data.mock_subscriptions_array(url: "/v1/customers/#{cus[:id]}/subscriptions") unless cus[:subscriptions]
22
21
  cus[:subscriptions][:count] = (cus[:subscriptions][:count] ? cus[:subscriptions][:count]+1 : 1 )
23
22
  cus[:subscriptions][:data] << subscription
24
23
  subscription
@@ -45,11 +45,7 @@ module StripeMock
45
45
  customer = customers[$1]
46
46
  assert_existance :customer, $1, customer
47
47
 
48
- subscription_list = Data.mock_subscriptions_array url: "/v1/customers/#{customer[:id]}/subscriptions", count: customer[:subscriptions][:data].length
49
- customer.subscriptions.each do |subscription|
50
- subscription_list[:data] << subscription
51
- end
52
- subscription_list
48
+ customer[:subscriptions]
53
49
  end
54
50
 
55
51
  def update_subscription(route, method_url, params, headers)
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.10.1.4"
3
+ VERSION = "1.10.1.5"
4
4
  end
@@ -11,9 +11,10 @@
11
11
  "period_start": 1378082075,
12
12
  "period_end": 1380674075,
13
13
  "lines": {
14
- "invoiceitems": [],
15
- "prorations": [],
16
- "subscriptions": [
14
+ "count": 1,
15
+ "object": "list",
16
+ "url": "/v1/invoices/in_00000000000000/lines",
17
+ "data": [
17
18
  {
18
19
  "id": "su_2hksGtIPylSBg2",
19
20
  "object": "line_item",
@@ -36,9 +37,11 @@
36
37
  "object": "plan",
37
38
  "livemode": false,
38
39
  "interval_count": 1,
39
- "trial_period_days": null
40
+ "trial_period_days": null,
41
+ "metadata": {}
40
42
  },
41
- "description": null
43
+ "description": null,
44
+ "metadata": null
42
45
  }
43
46
  ]
44
47
  },
@@ -58,7 +61,10 @@
58
61
  "next_payment_attempt": null,
59
62
  "charge": "ch_00000000000000",
60
63
  "discount": null,
61
- "application_fee": null
64
+ "application_fee": null,
65
+ "subscription": "sub_00000000000000",
66
+ "metadata": {},
67
+ "description": null
62
68
  }
63
69
  }
64
70
  }
@@ -11,39 +11,77 @@
11
11
  "period_start": 1378082075,
12
12
  "period_end": 1380674075,
13
13
  "lines": {
14
- "invoiceitems": [],
15
- "prorations": [],
16
- "subscriptions": [
14
+ "object": "list",
15
+ "count": 3,
16
+ "url": "/v1/invoices/in_00000000000000/lines",
17
+ "data": [
17
18
  {
18
- "id": "su_2hkslKrnt23NBz",
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": {}
34
+ },
35
+ {
36
+ "id": "ii_00000000000001",
37
+ "object": "line_item",
38
+ "type": "invoiceitem",
39
+ "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": {}
51
+ },
52
+ {
53
+ "id": "su_00000000000000",
19
54
  "object": "line_item",
20
55
  "type": "subscription",
21
- "livemode": true,
22
- "amount": 100,
56
+ "livemode": false,
57
+ "amount": 20000,
23
58
  "currency": "usd",
24
59
  "proration": false,
25
60
  "period": {
26
- "start": 1383759056,
27
- "end": 1386351056
61
+ "start": 1383759053,
62
+ "end": 1386351053
28
63
  },
29
64
  "quantity": 1,
30
65
  "plan": {
31
66
  "interval": "month",
32
- "name": "Member's Club",
33
- "amount": 100,
67
+ "name": "Platinum",
68
+ "created": 1300000000,
69
+ "amount": 20000,
34
70
  "currency": "usd",
35
- "id": "fkx0AFo",
71
+ "id": "platinum",
36
72
  "object": "plan",
37
73
  "livemode": false,
38
74
  "interval_count": 1,
39
- "trial_period_days": null
75
+ "trial_period_days": null,
76
+ "metadata": {}
40
77
  },
41
- "description": null
78
+ "description": null,
79
+ "metadata": null
42
80
  }
43
81
  ]
44
82
  },
45
- "subtotal": 1000,
46
- "total": 1000,
83
+ "subtotal": 30000,
84
+ "total": 30000,
47
85
  "customer": "cus_00000000000000",
48
86
  "object": "invoice",
49
87
  "attempted": true,
@@ -51,14 +89,17 @@
51
89
  "paid": false,
52
90
  "livemode": false,
53
91
  "attempt_count": 1,
54
- "amount_due": 1000,
92
+ "amount_due": 30000,
55
93
  "currency": "usd",
56
94
  "starting_balance": 0,
57
95
  "ending_balance": 0,
58
- "next_payment_attempt": null,
96
+ "next_payment_attempt": 1380760475,
59
97
  "charge": "ch_00000000000000",
60
98
  "discount": null,
61
- "application_fee": null
99
+ "application_fee": null,
100
+ "subscription": "su_00000000000000",
101
+ "metadata": {},
102
+ "description": null
62
103
  }
63
104
  }
64
105
  }
@@ -6,20 +6,55 @@
6
6
  "object": "event",
7
7
  "data": {
8
8
  "object": {
9
- "date": 1380674206,
9
+ "date": 1394018368,
10
10
  "id": "in_00000000000000",
11
- "period_start": 1378082075,
12
- "period_end": 1380674075,
11
+ "period_start": 1394018368,
12
+ "period_end": 1394018368,
13
13
  "lines": {
14
- "invoiceitems": [],
15
- "prorations": [],
16
- "subscriptions": [
14
+ "object": "list",
15
+ "count": 3,
16
+ "url": "/v1/invoices/in_00000000000000/lines",
17
+ "data": [
17
18
  {
18
- "id": "su_2hkscimMTuAjFP",
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": {}
34
+ },
35
+ {
36
+ "id": "ii_00000000000001",
37
+ "object": "line_item",
38
+ "type": "invoiceitem",
39
+ "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": {}
51
+ },
52
+ {
53
+ "id": "su_00000000000000",
19
54
  "object": "line_item",
20
55
  "type": "subscription",
21
- "livemode": true,
22
- "amount": 100,
56
+ "livemode": false,
57
+ "amount": 20000,
23
58
  "currency": "usd",
24
59
  "proration": false,
25
60
  "period": {
@@ -29,21 +64,24 @@
29
64
  "quantity": 1,
30
65
  "plan": {
31
66
  "interval": "month",
32
- "name": "Member's Club",
33
- "amount": 100,
67
+ "name": "Platinum",
68
+ "created": 1300000000,
69
+ "amount": 20000,
34
70
  "currency": "usd",
35
- "id": "fkx0AFo",
71
+ "id": "platinum",
36
72
  "object": "plan",
37
73
  "livemode": false,
38
74
  "interval_count": 1,
39
- "trial_period_days": null
75
+ "trial_period_days": null,
76
+ "metadata": {}
40
77
  },
41
- "description": null
78
+ "description": null,
79
+ "metadata": null
42
80
  }
43
81
  ]
44
82
  },
45
- "subtotal": 1000,
46
- "total": 1000,
83
+ "subtotal": 30000,
84
+ "total": 30000,
47
85
  "customer": "cus_00000000000000",
48
86
  "object": "invoice",
49
87
  "attempted": true,
@@ -51,14 +89,17 @@
51
89
  "paid": true,
52
90
  "livemode": false,
53
91
  "attempt_count": 1,
54
- "amount_due": 1000,
92
+ "amount_due": 0,
55
93
  "currency": "usd",
56
94
  "starting_balance": 0,
57
95
  "ending_balance": 0,
58
96
  "next_payment_attempt": null,
59
- "charge": "_00000000000000",
97
+ "charge": "ch_00000000000000",
60
98
  "discount": null,
61
- "application_fee": null
99
+ "application_fee": null,
100
+ "subscription": "su_00000000000000",
101
+ "metadata": {},
102
+ "description": null
62
103
  }
63
104
  }
64
105
  }
@@ -11,11 +11,12 @@
11
11
  "period_start": 1378082075,
12
12
  "period_end": 1380674075,
13
13
  "lines": {
14
- "invoiceitems": [],
15
- "prorations": [],
16
- "subscriptions": [
14
+ "count": 1,
15
+ "object": "list",
16
+ "url": "/v1/invoices/in_00000000000000/lines",
17
+ "data": [
17
18
  {
18
- "id": "su_2hkskhhOSfPr47",
19
+ "id": "su_00000000000000",
19
20
  "object": "line_item",
20
21
  "type": "subscription",
21
22
  "livemode": true,
@@ -36,9 +37,11 @@
36
37
  "object": "plan",
37
38
  "livemode": false,
38
39
  "interval_count": 1,
39
- "trial_period_days": null
40
+ "trial_period_days": null,
41
+ "metadata": {}
40
42
  },
41
- "description": null
43
+ "description": null,
44
+ "metadata": null
42
45
  }
43
46
  ]
44
47
  },
@@ -58,7 +61,10 @@
58
61
  "next_payment_attempt": null,
59
62
  "charge": "ch_00000000000000",
60
63
  "discount": null,
61
- "application_fee": null
64
+ "application_fee": null,
65
+ "subscription": "sub_00000000000000",
66
+ "metadata": {},
67
+ "description": null
62
68
  },
63
69
  "previous_attributes": {
64
70
  "lines": []
@@ -329,7 +329,7 @@ shared_examples 'Customer Subscriptions' do
329
329
 
330
330
  customer = Stripe::Customer.retrieve('test_customer_sub')
331
331
 
332
- list = customer.subscriptions
332
+ list = customer.subscriptions.all
333
333
 
334
334
  expect(list.object).to eq("list")
335
335
  expect(list.count).to eq(2)
@@ -341,6 +341,17 @@ shared_examples 'Customer Subscriptions' do
341
341
  expect(list.data.last.object).to eq("subscription")
342
342
  expect(list.data.last.plan.to_hash).to eq(paid.to_hash)
343
343
  end
344
+
345
+ it "retrieves an empty list if there's no subscriptions" do
346
+ Stripe::Customer.create(id: 'no_subs')
347
+ customer = Stripe::Customer.retrieve('no_subs')
348
+
349
+ list = customer.subscriptions.all
350
+
351
+ expect(list.object).to eq("list")
352
+ expect(list.count).to eq(0)
353
+ expect(list.data.length).to eq(0)
354
+ end
344
355
  end
345
356
 
346
357
  end
@@ -81,18 +81,18 @@ shared_examples 'Webhook Events API' do
81
81
  it "takes a hash and deep merges arrays in the data object" do
82
82
  event = StripeMock.mock_webhook_event('invoice.created', {
83
83
  :lines => {
84
- :subscriptions => [
84
+ :data => [
85
85
  { :amount => 555,
86
86
  :plan => { :id => 'wh_test' }
87
87
  }
88
88
  ]
89
89
  }
90
90
  })
91
- expect(event.data.object.lines.subscriptions.first.amount).to eq(555)
92
- expect(event.data.object.lines.subscriptions.first.plan.id).to eq('wh_test')
91
+ expect(event.data.object.lines.data.first.amount).to eq(555)
92
+ expect(event.data.object.lines.data.first.plan.id).to eq('wh_test')
93
93
  # Ensure data from invoice.created.json is still present
94
- expect(event.data.object.lines.subscriptions.first.type).to eq('subscription')
95
- expect(event.data.object.lines.subscriptions.first.plan.currency).to eq('usd')
94
+ expect(event.data.object.lines.data.first.type).to eq('subscription')
95
+ expect(event.data.object.lines.data.first.plan.currency).to eq('usd')
96
96
  end
97
97
 
98
98
  it "can generate all events" do
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.10.1.4
4
+ version: 1.10.1.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: 2014-03-14 00:00:00.000000000 Z
12
+ date: 2014-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe