stripe-ruby-mock 2.0.5 → 2.1.0
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.
- checksums.yaml +7 -0
- data/README.md +13 -3
- data/lib/stripe_mock.rb +1 -0
- data/lib/stripe_mock/data.rb +19 -10
- data/lib/stripe_mock/instance.rb +1 -0
- data/lib/stripe_mock/request_handlers/cards.rb +0 -37
- data/lib/stripe_mock/request_handlers/charges.rb +4 -4
- data/lib/stripe_mock/request_handlers/customers.rb +9 -9
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +21 -11
- data/lib/stripe_mock/request_handlers/sources.rb +46 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +7 -7
- data/lib/stripe_mock/request_handlers/tokens.rb +4 -4
- data/lib/stripe_mock/version.rb +1 -1
- data/spec/integration_examples/charge_token_examples.rb +12 -12
- data/spec/integration_examples/customer_card_examples.rb +10 -10
- data/spec/readme_spec.rb +2 -2
- data/spec/shared_stripe_examples/card_examples.rb +36 -36
- data/spec/shared_stripe_examples/card_token_examples.rb +13 -13
- data/spec/shared_stripe_examples/charge_examples.rb +13 -12
- data/spec/shared_stripe_examples/customer_examples.rb +30 -30
- data/spec/shared_stripe_examples/invoice_examples.rb +1 -1
- data/spec/shared_stripe_examples/subscription_examples.rb +23 -23
- data/spec/shared_stripe_examples/transfer_examples.rb +1 -0
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +18 -31
data/lib/stripe_mock/version.rb
CHANGED
@@ -6,12 +6,12 @@ shared_examples 'Charging with Tokens' do
|
|
6
6
|
|
7
7
|
before do
|
8
8
|
@cus = Stripe::Customer.create(
|
9
|
-
:
|
9
|
+
:source => stripe_helper.generate_card_token({ :number => '4242424242424242', :brand => 'Visa' })
|
10
10
|
)
|
11
11
|
|
12
12
|
@card_token = Stripe::Token.create({
|
13
13
|
:customer => @cus.id,
|
14
|
-
:
|
14
|
+
:source => @cus.sources.first.id
|
15
15
|
}, ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
|
16
16
|
end
|
17
17
|
|
@@ -19,20 +19,20 @@ shared_examples 'Charging with Tokens' do
|
|
19
19
|
charge = Stripe::Charge.create({
|
20
20
|
:amount => 1099,
|
21
21
|
:currency => 'usd',
|
22
|
-
:
|
22
|
+
:source => @card_token.id
|
23
23
|
}, ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
|
24
24
|
|
25
|
-
expect(charge.
|
26
|
-
expect(charge.
|
27
|
-
expect(charge.
|
28
|
-
expect(charge.
|
25
|
+
expect(charge.source.id).to_not eq @cus.sources.first.id
|
26
|
+
expect(charge.source.fingerprint).to eq @cus.sources.first.fingerprint
|
27
|
+
expect(charge.source.last4).to eq '4242'
|
28
|
+
expect(charge.source.brand).to eq 'Visa'
|
29
29
|
|
30
30
|
retrieved_charge = Stripe::Charge.retrieve(charge.id)
|
31
31
|
|
32
|
-
expect(retrieved_charge.
|
33
|
-
expect(retrieved_charge.
|
34
|
-
expect(retrieved_charge.
|
35
|
-
expect(retrieved_charge.
|
32
|
+
expect(retrieved_charge.source.id).to_not eq @cus.sources.first.id
|
33
|
+
expect(retrieved_charge.source.fingerprint).to eq @cus.sources.first.fingerprint
|
34
|
+
expect(retrieved_charge.source.last4).to eq '4242'
|
35
|
+
expect(retrieved_charge.source.brand).to eq 'Visa'
|
36
36
|
end
|
37
37
|
|
38
38
|
it "throws an error when the card is not an id", :oauth => true do
|
@@ -40,7 +40,7 @@ shared_examples 'Charging with Tokens' do
|
|
40
40
|
charge = Stripe::Charge.create({
|
41
41
|
:amount => 1099,
|
42
42
|
:currency => 'usd',
|
43
|
-
:
|
43
|
+
:source => @card_token
|
44
44
|
}, ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
|
45
45
|
}.to raise_error(Stripe::InvalidRequestError, /Invalid token id/)
|
46
46
|
end
|
@@ -5,23 +5,23 @@ shared_examples "Multiple Customer Cards" do
|
|
5
5
|
tok1 = Stripe::Token.retrieve stripe_helper.generate_card_token :number => "4242424242424242"
|
6
6
|
tok2 = Stripe::Token.retrieve stripe_helper.generate_card_token :number => "4012888888881881"
|
7
7
|
|
8
|
-
cus = Stripe::Customer.create(:email => 'alice@bob.com', :
|
9
|
-
default_card = cus.
|
10
|
-
cus.
|
8
|
+
cus = Stripe::Customer.create(:email => 'alice@bob.com', :source => tok1.id)
|
9
|
+
default_card = cus.sources.first
|
10
|
+
cus.sources.create(:source => tok2.id)
|
11
11
|
|
12
12
|
cus = Stripe::Customer.retrieve(cus.id)
|
13
|
-
expect(cus.
|
14
|
-
expect(cus.
|
13
|
+
expect(cus.sources.count).to eq(2)
|
14
|
+
expect(cus.default_source).to eq default_card.id
|
15
15
|
end
|
16
16
|
|
17
17
|
it "gives the same two card numbers the same fingerprints", :live => true do
|
18
18
|
tok1 = Stripe::Token.retrieve stripe_helper.generate_card_token :number => "4242424242424242"
|
19
19
|
tok2 = Stripe::Token.retrieve stripe_helper.generate_card_token :number => "4242424242424242"
|
20
20
|
|
21
|
-
cus = Stripe::Customer.create(:email => 'alice@bob.com', :
|
21
|
+
cus = Stripe::Customer.create(:email => 'alice@bob.com', :source => tok1.id)
|
22
22
|
|
23
23
|
cus = Stripe::Customer.retrieve(cus.id)
|
24
|
-
card = cus.
|
24
|
+
card = cus.sources.find do |existing_card|
|
25
25
|
existing_card.fingerprint == tok2.card.fingerprint
|
26
26
|
end
|
27
27
|
expect(card).to_not be_nil
|
@@ -31,12 +31,12 @@ shared_examples "Multiple Customer Cards" do
|
|
31
31
|
tok1 = Stripe::Token.retrieve stripe_helper.generate_card_token :number => "4242424242424242"
|
32
32
|
tok2 = Stripe::Token.retrieve stripe_helper.generate_card_token :number => "4012888888881881"
|
33
33
|
|
34
|
-
cus = Stripe::Customer.create(:email => 'alice@bob.com', :
|
34
|
+
cus = Stripe::Customer.create(:email => 'alice@bob.com', :source => tok1.id)
|
35
35
|
|
36
36
|
cus = Stripe::Customer.retrieve(cus.id)
|
37
|
-
|
37
|
+
source = cus.sources.find do |existing_card|
|
38
38
|
existing_card.fingerprint == tok2.card.fingerprint
|
39
39
|
end
|
40
|
-
expect(
|
40
|
+
expect(source).to be_nil
|
41
41
|
end
|
42
42
|
end
|
data/spec/readme_spec.rb
CHANGED
@@ -64,8 +64,8 @@ describe 'README examples' do
|
|
64
64
|
it "generates a stripe card token" do
|
65
65
|
card_token = StripeMock.generate_card_token(last4: "9191", exp_year: 1984)
|
66
66
|
|
67
|
-
cus = Stripe::Customer.create(
|
68
|
-
card = cus.
|
67
|
+
cus = Stripe::Customer.create(source: card_token)
|
68
|
+
card = cus.sources.data.first
|
69
69
|
expect(card.last4).to eq("9191")
|
70
70
|
expect(card.exp_year).to eq(1984)
|
71
71
|
end
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples 'Card API' do
|
4
4
|
|
5
|
-
it 'creates/returns a card when using customer.
|
5
|
+
it 'creates/returns a card when using customer.sources.create given a card token' do
|
6
6
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
7
7
|
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
8
|
-
card = customer.
|
8
|
+
card = customer.sources.create(source: card_token)
|
9
9
|
|
10
10
|
expect(card.customer).to eq('test_customer_sub')
|
11
11
|
expect(card.last4).to eq("1123")
|
@@ -13,8 +13,8 @@ shared_examples 'Card API' do
|
|
13
13
|
expect(card.exp_year).to eq(2099)
|
14
14
|
|
15
15
|
customer = Stripe::Customer.retrieve('test_customer_sub')
|
16
|
-
expect(customer.
|
17
|
-
card = customer.
|
16
|
+
expect(customer.sources.count).to eq(1)
|
17
|
+
card = customer.sources.data.first
|
18
18
|
expect(card.customer).to eq('test_customer_sub')
|
19
19
|
expect(card.last4).to eq("1123")
|
20
20
|
expect(card.exp_month).to eq(11)
|
@@ -40,9 +40,9 @@ shared_examples 'Card API' do
|
|
40
40
|
expect(card.exp_year).to eq(2099)
|
41
41
|
end
|
42
42
|
|
43
|
-
it 'creates/returns a card when using customer.
|
43
|
+
it 'creates/returns a card when using customer.sources.create given card params' do
|
44
44
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
45
|
-
card = customer.
|
45
|
+
card = customer.sources.create(card: {
|
46
46
|
number: '4242424242424242',
|
47
47
|
exp_month: '11',
|
48
48
|
exp_year: '3031',
|
@@ -55,8 +55,8 @@ shared_examples 'Card API' do
|
|
55
55
|
expect(card.exp_year).to eq(3031)
|
56
56
|
|
57
57
|
customer = Stripe::Customer.retrieve('test_customer_sub')
|
58
|
-
expect(customer.
|
59
|
-
card = customer.
|
58
|
+
expect(customer.sources.count).to eq(1)
|
59
|
+
card = customer.sources.data.first
|
60
60
|
expect(card.customer).to eq('test_customer_sub')
|
61
61
|
expect(card.last4).to eq("4242")
|
62
62
|
expect(card.exp_month).to eq(11)
|
@@ -88,88 +88,88 @@ shared_examples 'Card API' do
|
|
88
88
|
|
89
89
|
it "creates a single card with a generated card token", :live => true do
|
90
90
|
customer = Stripe::Customer.create
|
91
|
-
expect(customer.
|
91
|
+
expect(customer.sources.count).to eq 0
|
92
92
|
|
93
|
-
customer.
|
93
|
+
customer.sources.create :source => stripe_helper.generate_card_token
|
94
94
|
# Yes, stripe-ruby does not actually add the new card to the customer instance
|
95
|
-
expect(customer.
|
95
|
+
expect(customer.sources.count).to eq 0
|
96
96
|
|
97
97
|
customer2 = Stripe::Customer.retrieve(customer.id)
|
98
|
-
expect(customer2.
|
99
|
-
expect(customer2.
|
98
|
+
expect(customer2.sources.count).to eq 1
|
99
|
+
expect(customer2.default_source).to eq customer2.sources.first.id
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'create does not change the customers default card if already set' do
|
103
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub',
|
103
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', default_source: "test_cc_original")
|
104
104
|
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
105
|
-
card = customer.
|
105
|
+
card = customer.sources.create(source: card_token)
|
106
106
|
|
107
107
|
customer = Stripe::Customer.retrieve('test_customer_sub')
|
108
|
-
expect(customer.
|
108
|
+
expect(customer.default_source).to eq("test_cc_original")
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'create updates the customers default card if not set' do
|
112
112
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
113
113
|
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
114
|
-
card = customer.
|
114
|
+
card = customer.sources.create(source: card_token)
|
115
115
|
|
116
116
|
customer = Stripe::Customer.retrieve('test_customer_sub')
|
117
|
-
expect(customer.
|
117
|
+
expect(customer.default_source).to_not be_nil
|
118
118
|
end
|
119
119
|
|
120
120
|
describe "retrieval and deletion with customers" do
|
121
121
|
let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
|
122
122
|
let!(:card_token) { stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
123
|
-
let!(:card) { customer.
|
123
|
+
let!(:card) { customer.sources.create(source: card_token) }
|
124
124
|
|
125
125
|
it "can retrieve all customer's cards" do
|
126
|
-
retrieved = customer.
|
126
|
+
retrieved = customer.sources.all
|
127
127
|
expect(retrieved.count).to eq(1)
|
128
128
|
end
|
129
129
|
|
130
130
|
it "retrieves a customers card" do
|
131
|
-
retrieved = customer.
|
131
|
+
retrieved = customer.sources.retrieve(card.id)
|
132
132
|
expect(retrieved.to_s).to eq(card.to_s)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "retrieves a customer's card after re-fetching the customer" do
|
136
|
-
retrieved = Stripe::Customer.retrieve(customer.id).
|
136
|
+
retrieved = Stripe::Customer.retrieve(customer.id).sources.retrieve(card.id)
|
137
137
|
expect(retrieved.id).to eq card.id
|
138
138
|
end
|
139
139
|
|
140
140
|
it "deletes a customers card" do
|
141
141
|
card.delete
|
142
142
|
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
143
|
-
expect(retrieved_cus.
|
143
|
+
expect(retrieved_cus.sources.data).to be_empty
|
144
144
|
end
|
145
145
|
|
146
146
|
it "deletes a customers card then set the default_card to nil" do
|
147
147
|
card.delete
|
148
148
|
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
149
|
-
expect(retrieved_cus.
|
149
|
+
expect(retrieved_cus.default_source).to be_nil
|
150
150
|
end
|
151
151
|
|
152
152
|
it "updates the default card if deleted" do
|
153
153
|
card.delete
|
154
154
|
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
155
|
-
expect(retrieved_cus.
|
155
|
+
expect(retrieved_cus.default_source).to be_nil
|
156
156
|
end
|
157
157
|
|
158
158
|
context "deletion when the user has two cards" do
|
159
159
|
let!(:card_token_2) { stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
160
|
-
let!(:card_2) { customer.
|
160
|
+
let!(:card_2) { customer.sources.create(source: card_token_2) }
|
161
161
|
|
162
162
|
it "has just one card anymore" do
|
163
163
|
card.delete
|
164
164
|
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
165
|
-
expect(retrieved_cus.
|
166
|
-
expect(retrieved_cus.
|
165
|
+
expect(retrieved_cus.sources.data.count).to eq 1
|
166
|
+
expect(retrieved_cus.sources.data.first.id).to eq card_2.id
|
167
167
|
end
|
168
168
|
|
169
169
|
it "sets the default_card id to the last card remaining id" do
|
170
170
|
card.delete
|
171
171
|
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
172
|
-
expect(retrieved_cus.
|
172
|
+
expect(retrieved_cus.default_source).to eq card_2.id
|
173
173
|
end
|
174
174
|
end
|
175
175
|
end
|
@@ -219,7 +219,7 @@ shared_examples 'Card API' do
|
|
219
219
|
it "throws an error when the customer does not have the retrieving card id" do
|
220
220
|
customer = Stripe::Customer.create
|
221
221
|
card_id = "card_123"
|
222
|
-
expect { customer.
|
222
|
+
expect { customer.sources.retrieve(card_id) }.to raise_error {|e|
|
223
223
|
expect(e).to be_a Stripe::InvalidRequestError
|
224
224
|
expect(e.message).to include "Customer", customer.id, "does not have", card_id
|
225
225
|
expect(e.param).to eq 'card'
|
@@ -231,7 +231,7 @@ shared_examples 'Card API' do
|
|
231
231
|
context "update card" do
|
232
232
|
let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
|
233
233
|
let!(:card_token) { stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
234
|
-
let!(:card) { customer.
|
234
|
+
let!(:card) { customer.sources.create(source: card_token) }
|
235
235
|
|
236
236
|
it "updates the card" do
|
237
237
|
exp_month = 10
|
@@ -241,7 +241,7 @@ shared_examples 'Card API' do
|
|
241
241
|
card.exp_year = exp_year
|
242
242
|
card.save
|
243
243
|
|
244
|
-
retrieved = customer.
|
244
|
+
retrieved = customer.sources.retrieve(card.id)
|
245
245
|
|
246
246
|
expect(retrieved.exp_month).to eq(exp_month)
|
247
247
|
expect(retrieved.exp_year).to eq(exp_year)
|
@@ -254,13 +254,13 @@ shared_examples 'Card API' do
|
|
254
254
|
customer = Stripe::Customer.create(id: 'test_customer_card')
|
255
255
|
|
256
256
|
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
257
|
-
card1 = customer.
|
257
|
+
card1 = customer.sources.create(source: card_token)
|
258
258
|
card_token = stripe_helper.generate_card_token(last4: "1124", exp_month: 12, exp_year: 2098)
|
259
|
-
card2 = customer.
|
259
|
+
card2 = customer.sources.create(source: card_token)
|
260
260
|
|
261
261
|
customer = Stripe::Customer.retrieve('test_customer_card')
|
262
262
|
|
263
|
-
list = customer.
|
263
|
+
list = customer.sources.all
|
264
264
|
|
265
265
|
expect(list.object).to eq("list")
|
266
266
|
expect(list.count).to eq(2)
|
@@ -277,7 +277,7 @@ shared_examples 'Card API' do
|
|
277
277
|
Stripe::Customer.create(id: 'no_cards')
|
278
278
|
customer = Stripe::Customer.retrieve('no_cards')
|
279
279
|
|
280
|
-
list = customer.
|
280
|
+
list = customer.sources.all
|
281
281
|
|
282
282
|
expect(list.object).to eq("list")
|
283
283
|
expect(list.count).to eq(0)
|
@@ -7,8 +7,8 @@ shared_examples 'Card Token Mocking' do
|
|
7
7
|
it "generates and reads a card token for create charge" do
|
8
8
|
card_token = StripeMock.generate_card_token(last4: "2244", exp_month: 33, exp_year: 2255)
|
9
9
|
|
10
|
-
charge = Stripe::Charge.create(amount: 500,
|
11
|
-
card = charge.
|
10
|
+
charge = Stripe::Charge.create(amount: 500, source: card_token)
|
11
|
+
card = charge.source
|
12
12
|
expect(card.last4).to eq("2244")
|
13
13
|
expect(card.exp_month).to eq(33)
|
14
14
|
expect(card.exp_year).to eq(2255)
|
@@ -17,8 +17,8 @@ shared_examples 'Card Token Mocking' do
|
|
17
17
|
it "generates and reads a card token for create customer" do
|
18
18
|
card_token = StripeMock.generate_card_token(last4: "9191", exp_month: 99, exp_year: 3005)
|
19
19
|
|
20
|
-
cus = Stripe::Customer.create(
|
21
|
-
card = cus.
|
20
|
+
cus = Stripe::Customer.create(source: card_token)
|
21
|
+
card = cus.sources.data.first
|
22
22
|
expect(card.last4).to eq("9191")
|
23
23
|
expect(card.exp_month).to eq(99)
|
24
24
|
expect(card.exp_year).to eq(3005)
|
@@ -27,11 +27,11 @@ shared_examples 'Card Token Mocking' do
|
|
27
27
|
it "generates and reads a card token for update customer" do
|
28
28
|
card_token = StripeMock.generate_card_token(last4: "1133", exp_month: 11, exp_year: 2099)
|
29
29
|
|
30
|
-
cus = Stripe::Customer.create
|
31
|
-
cus.
|
30
|
+
cus = Stripe::Customer.create
|
31
|
+
cus.source = card_token
|
32
32
|
cus.save
|
33
33
|
|
34
|
-
card = cus.
|
34
|
+
card = cus.sources.data.first
|
35
35
|
expect(card.last4).to eq("1133")
|
36
36
|
expect(card.exp_month).to eq(11)
|
37
37
|
expect(card.exp_year).to eq(2099)
|
@@ -60,8 +60,8 @@ shared_examples 'Card Token Mocking' do
|
|
60
60
|
}
|
61
61
|
})
|
62
62
|
|
63
|
-
cus = Stripe::Customer.create(
|
64
|
-
card = cus.
|
63
|
+
cus = Stripe::Customer.create(source: card_token.id)
|
64
|
+
card = cus.sources.data.first
|
65
65
|
expect(card.last4).to eq("2222")
|
66
66
|
expect(card.exp_month).to eq(9)
|
67
67
|
expect(card.exp_year).to eq(2017)
|
@@ -76,11 +76,11 @@ shared_examples 'Card Token Mocking' do
|
|
76
76
|
}
|
77
77
|
})
|
78
78
|
|
79
|
-
cus = Stripe::Customer.create
|
80
|
-
cus.
|
79
|
+
cus = Stripe::Customer.create
|
80
|
+
cus.source = card_token.id
|
81
81
|
cus.save
|
82
82
|
|
83
|
-
card = cus.
|
83
|
+
card = cus.sources.data.first
|
84
84
|
expect(card.last4).to eq("4444")
|
85
85
|
expect(card.exp_month).to eq(11)
|
86
86
|
expect(card.exp_year).to eq(2019)
|
@@ -96,7 +96,7 @@ shared_examples 'Card Token Mocking' do
|
|
96
96
|
})
|
97
97
|
|
98
98
|
cus = Stripe::Customer.create()
|
99
|
-
cus.
|
99
|
+
cus.source = card_token.id
|
100
100
|
cus.save
|
101
101
|
|
102
102
|
card_token = Stripe::Token.create({
|
@@ -7,7 +7,7 @@ shared_examples 'Charge API' do
|
|
7
7
|
charge = Stripe::Charge.create(
|
8
8
|
amount: 99,
|
9
9
|
currency: 'usd',
|
10
|
-
|
10
|
+
source: 'bogus_card_token'
|
11
11
|
)
|
12
12
|
}.to raise_error(Stripe::InvalidRequestError, /token/i)
|
13
13
|
end
|
@@ -16,7 +16,7 @@ shared_examples 'Charge API' do
|
|
16
16
|
charge = Stripe::Charge.create(
|
17
17
|
amount: 999,
|
18
18
|
currency: 'USD',
|
19
|
-
|
19
|
+
source: stripe_helper.generate_card_token,
|
20
20
|
description: 'card charge'
|
21
21
|
)
|
22
22
|
|
@@ -24,26 +24,27 @@ shared_examples 'Charge API' do
|
|
24
24
|
expect(charge.amount).to eq(999)
|
25
25
|
expect(charge.description).to eq('card charge')
|
26
26
|
expect(charge.captured).to eq(true)
|
27
|
+
expect(charge.status).to eq('succeeded')
|
27
28
|
end
|
28
29
|
|
29
30
|
|
30
31
|
it "creates a stripe charge item with a customer and card id" do
|
31
32
|
customer = Stripe::Customer.create({
|
32
33
|
email: 'johnny@appleseed.com',
|
33
|
-
|
34
|
+
source: stripe_helper.generate_card_token(number: '4012888888881881'),
|
34
35
|
description: "a description"
|
35
36
|
})
|
36
37
|
|
37
|
-
expect(customer.
|
38
|
-
expect(customer.
|
39
|
-
expect(customer.
|
38
|
+
expect(customer.sources.data.length).to eq(1)
|
39
|
+
expect(customer.sources.data[0].id).not_to be_nil
|
40
|
+
expect(customer.sources.data[0].last4).to eq('1881')
|
40
41
|
|
41
|
-
card = customer.
|
42
|
+
card = customer.sources.data[0]
|
42
43
|
charge = Stripe::Charge.create(
|
43
44
|
amount: 999,
|
44
45
|
currency: 'USD',
|
45
46
|
customer: customer.id,
|
46
|
-
|
47
|
+
source: card.id,
|
47
48
|
description: 'a charge with a specific card'
|
48
49
|
)
|
49
50
|
|
@@ -51,7 +52,7 @@ shared_examples 'Charge API' do
|
|
51
52
|
expect(charge.amount).to eq(999)
|
52
53
|
expect(charge.description).to eq('a charge with a specific card')
|
53
54
|
expect(charge.captured).to eq(true)
|
54
|
-
expect(charge.
|
55
|
+
expect(charge.source.last4).to eq('1881')
|
55
56
|
end
|
56
57
|
|
57
58
|
|
@@ -59,12 +60,12 @@ shared_examples 'Charge API' do
|
|
59
60
|
charge = Stripe::Charge.create({
|
60
61
|
amount: 333,
|
61
62
|
currency: 'USD',
|
62
|
-
|
63
|
+
source: stripe_helper.generate_card_token
|
63
64
|
})
|
64
65
|
charge2 = Stripe::Charge.create({
|
65
66
|
amount: 777,
|
66
67
|
currency: 'USD',
|
67
|
-
|
68
|
+
source: stripe_helper.generate_card_token
|
68
69
|
})
|
69
70
|
data = test_data_source(:charges)
|
70
71
|
expect(data[charge.id]).to_not be_nil
|
@@ -78,7 +79,7 @@ shared_examples 'Charge API' do
|
|
78
79
|
original = Stripe::Charge.create({
|
79
80
|
amount: 777,
|
80
81
|
currency: 'USD',
|
81
|
-
|
82
|
+
source: stripe_helper.generate_card_token
|
82
83
|
})
|
83
84
|
charge = Stripe::Charge.retrieve(original.id)
|
84
85
|
|