stripe-ruby-mock 2.0.1 → 2.0.2
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 +4 -4
- data/README.md +1 -1
- data/lib/stripe_mock.rb +3 -1
- data/lib/stripe_mock/data.rb +14 -5
- data/lib/stripe_mock/data/list.rb +64 -0
- data/lib/stripe_mock/instance.rb +1 -1
- data/lib/stripe_mock/request_handlers/cards.rb +21 -38
- data/lib/stripe_mock/request_handlers/charges.rb +4 -4
- data/lib/stripe_mock/request_handlers/coupons.rb +3 -3
- data/lib/stripe_mock/request_handlers/customers.rb +5 -5
- data/lib/stripe_mock/request_handlers/events.rb +1 -1
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +36 -1
- data/lib/stripe_mock/request_handlers/invoice_items.rb +4 -4
- data/lib/stripe_mock/request_handlers/invoices.rb +7 -7
- data/lib/stripe_mock/request_handlers/plans.rb +4 -4
- data/lib/stripe_mock/request_handlers/recipients.rb +2 -2
- data/lib/stripe_mock/request_handlers/subscriptions.rb +10 -10
- data/lib/stripe_mock/request_handlers/tokens.rb +4 -4
- data/lib/stripe_mock/test_strategies/base.rb +2 -3
- data/lib/stripe_mock/util.rb +11 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.card.created.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.card.deleted.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.card.updated.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
- data/spec/list_spec.rb +123 -0
- data/spec/shared_stripe_examples/card_examples.rb +87 -9
- data/spec/shared_stripe_examples/charge_examples.rb +12 -6
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +1 -1
- data/spec/shared_stripe_examples/invoice_examples.rb +8 -2
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/plan_examples.rb +1 -1
- data/spec/util_spec.rb +69 -35
- metadata +5 -2
@@ -20,13 +20,13 @@ module StripeMock
|
|
20
20
|
|
21
21
|
def update_invoice(route, method_url, params, headers)
|
22
22
|
route =~ method_url
|
23
|
-
|
23
|
+
assert_existence :invoice, $1, invoices[$1]
|
24
24
|
invoices[$1].merge!(params)
|
25
25
|
end
|
26
26
|
|
27
27
|
def list_invoices(route, method_url, params, headers)
|
28
28
|
params[:offset] ||= 0
|
29
|
-
params[:
|
29
|
+
params[:limit] ||= 10
|
30
30
|
|
31
31
|
result = invoices.clone
|
32
32
|
|
@@ -34,23 +34,23 @@ module StripeMock
|
|
34
34
|
result.delete_if { |k,v| v[:customer] != params[:customer] }
|
35
35
|
end
|
36
36
|
|
37
|
-
result.values
|
37
|
+
Data.mock_list_object(result.values, params)
|
38
38
|
end
|
39
39
|
|
40
40
|
def get_invoice(route, method_url, params, headers)
|
41
41
|
route =~ method_url
|
42
|
-
|
42
|
+
assert_existence :invoice, $1, invoices[$1]
|
43
43
|
end
|
44
44
|
|
45
45
|
def get_invoice_line_items(route, method_url, params, headers)
|
46
46
|
route =~ method_url
|
47
|
-
|
47
|
+
assert_existence :invoice, $1, invoices[$1]
|
48
48
|
invoices[$1][:lines]
|
49
49
|
end
|
50
50
|
|
51
51
|
def pay_invoice(route, method_url, params, headers)
|
52
52
|
route =~ method_url
|
53
|
-
|
53
|
+
assert_existence :invoice, $1, invoices[$1]
|
54
54
|
invoices[$1].merge!(:paid => true, :attempted => true, :charge => 'ch_1fD6uiR9FAA2zc')
|
55
55
|
end
|
56
56
|
|
@@ -59,7 +59,7 @@ module StripeMock
|
|
59
59
|
raise Stripe::InvalidRequestError.new('Missing required param: customer', nil, 400) if params[:customer].nil?
|
60
60
|
|
61
61
|
customer = customers[params[:customer]]
|
62
|
-
|
62
|
+
assert_existence :customer, params[:customer], customer
|
63
63
|
|
64
64
|
raise Stripe::InvalidRequestError.new("No upcoming invoices for customer: #{customer[:id]}", nil, 404) if customer[:subscriptions][:data].length == 0
|
65
65
|
|
@@ -17,22 +17,22 @@ module StripeMock
|
|
17
17
|
|
18
18
|
def update_plan(route, method_url, params, headers)
|
19
19
|
route =~ method_url
|
20
|
-
|
20
|
+
assert_existence :plan, $1, plans[$1]
|
21
21
|
plans[$1].merge!(params)
|
22
22
|
end
|
23
23
|
|
24
24
|
def get_plan(route, method_url, params, headers)
|
25
25
|
route =~ method_url
|
26
|
-
|
26
|
+
assert_existence :plan, $1, plans[$1]
|
27
27
|
end
|
28
28
|
|
29
29
|
def delete_plan(route, method_url, params, headers)
|
30
30
|
route =~ method_url
|
31
|
-
|
31
|
+
assert_existence :plan, $1, plans.delete($1)
|
32
32
|
end
|
33
33
|
|
34
34
|
def list_plans(route, method_url, params, headers)
|
35
|
-
plans.values
|
35
|
+
Data.mock_list_object(plans.values)
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -27,7 +27,7 @@ module StripeMock
|
|
27
27
|
|
28
28
|
def update_recipient(route, method_url, params, headers)
|
29
29
|
route =~ method_url
|
30
|
-
recipient =
|
30
|
+
recipient = assert_existence :recipient, $1, recipients[$1]
|
31
31
|
recipient.merge!(params)
|
32
32
|
|
33
33
|
if params[:card]
|
@@ -41,7 +41,7 @@ module StripeMock
|
|
41
41
|
|
42
42
|
def get_recipient(route, method_url, params, headers)
|
43
43
|
route =~ method_url
|
44
|
-
|
44
|
+
assert_existence :recipient, $1, recipients[$1]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -12,10 +12,10 @@ module StripeMock
|
|
12
12
|
|
13
13
|
def create_subscription(route, method_url, params, headers)
|
14
14
|
route =~ method_url
|
15
|
-
customer =
|
15
|
+
customer = assert_existence :customer, $1, customers[$1]
|
16
16
|
|
17
17
|
plan_id = params[:plan]
|
18
|
-
plan =
|
18
|
+
plan = assert_existence :plan, plan_id, plans[plan_id]
|
19
19
|
|
20
20
|
if params[:card]
|
21
21
|
new_card = get_card_by_token(params.delete(:card))
|
@@ -36,23 +36,23 @@ module StripeMock
|
|
36
36
|
def retrieve_subscription(route, method_url, params, headers)
|
37
37
|
route =~ method_url
|
38
38
|
|
39
|
-
customer =
|
40
|
-
|
39
|
+
customer = assert_existence :customer, $1, customers[$1]
|
40
|
+
assert_existence :subscription, $2, get_customer_subscription(customer, $2)
|
41
41
|
end
|
42
42
|
|
43
43
|
def retrieve_subscriptions(route, method_url, params, headers)
|
44
44
|
route =~ method_url
|
45
45
|
|
46
|
-
customer =
|
46
|
+
customer = assert_existence :customer, $1, customers[$1]
|
47
47
|
customer[:subscriptions]
|
48
48
|
end
|
49
49
|
|
50
50
|
def update_subscription(route, method_url, params, headers)
|
51
51
|
route =~ method_url
|
52
|
-
customer =
|
52
|
+
customer = assert_existence :customer, $1, customers[$1]
|
53
53
|
|
54
54
|
subscription = get_customer_subscription(customer, $2)
|
55
|
-
|
55
|
+
assert_existence :subscription, $2, subscription
|
56
56
|
|
57
57
|
if params[:card]
|
58
58
|
new_card = get_card_by_token(params.delete(:card))
|
@@ -64,7 +64,7 @@ module StripeMock
|
|
64
64
|
plan_name = params[:plan] || subscription[:plan][:id]
|
65
65
|
plan = plans[plan_name]
|
66
66
|
|
67
|
-
|
67
|
+
assert_existence :plan, plan_name, plan
|
68
68
|
params[:plan] = plan if params[:plan]
|
69
69
|
verify_card_present(customer, plan)
|
70
70
|
|
@@ -84,10 +84,10 @@ module StripeMock
|
|
84
84
|
|
85
85
|
def cancel_subscription(route, method_url, params, headers)
|
86
86
|
route =~ method_url
|
87
|
-
customer =
|
87
|
+
customer = assert_existence :customer, $1, customers[$1]
|
88
88
|
|
89
89
|
subscription = get_customer_subscription(customer, $2)
|
90
|
-
|
90
|
+
assert_existence :subscription, $2, subscription
|
91
91
|
|
92
92
|
cancel_params = { canceled_at: Time.now.utc.to_i }
|
93
93
|
cancelled_at_period_end = (params[:at_period_end] == true)
|
@@ -15,18 +15,18 @@ module StripeMock
|
|
15
15
|
cus_id = params[:customer]
|
16
16
|
|
17
17
|
if cus_id && params[:card]
|
18
|
-
customer =
|
18
|
+
customer = assert_existence :customer, cus_id, customers[cus_id]
|
19
19
|
|
20
20
|
# params[:card] is an id; grab it from the db
|
21
21
|
customer_card = get_card(customer, params[:card])
|
22
|
-
|
22
|
+
assert_existence :card, params[:card], customer_card
|
23
23
|
elsif params[:card]
|
24
24
|
# params[:card] is a hash of cc info; "Sanitize" the card number
|
25
25
|
params[:card][:fingerprint] = StripeMock::Util.fingerprint(params[:card][:number])
|
26
26
|
params[:card][:last4] = params[:card][:number][-4,4]
|
27
27
|
customer_card = params[:card]
|
28
28
|
else
|
29
|
-
customer =
|
29
|
+
customer = assert_existence :customer, cus_id, customers[cus_id]
|
30
30
|
customer_card = get_card(customer, customer[:default_card])
|
31
31
|
end
|
32
32
|
|
@@ -40,7 +40,7 @@ module StripeMock
|
|
40
40
|
route =~ method_url
|
41
41
|
# A Stripe token can be either a bank token or a card token
|
42
42
|
bank_or_card = @bank_tokens[$1] || @card_tokens[$1]
|
43
|
-
|
43
|
+
assert_existence :token, $1, bank_or_card
|
44
44
|
|
45
45
|
if bank_or_card[:object] == 'card'
|
46
46
|
Data.mock_token(:id => $1, :card => bank_or_card)
|
@@ -13,9 +13,8 @@ module StripeMock
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def generate_card_token(card_params={})
|
16
|
-
|
17
|
-
|
18
|
-
}.merge(card_params)
|
16
|
+
card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => 2018, :cvc => "999" }
|
17
|
+
card = StripeMock::Util.card_merge(card_data, card_params)
|
19
18
|
card[:fingerprint] = StripeMock::Util.fingerprint(card[:number])
|
20
19
|
|
21
20
|
stripe_token = Stripe::Token.create(:card => card)
|
data/lib/stripe_mock/util.rb
CHANGED
@@ -23,5 +23,16 @@ module StripeMock
|
|
23
23
|
Digest::SHA1.base64digest(source).gsub(/[^a-z]/i, '')[0..15]
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.card_merge(old_param, new_param)
|
27
|
+
if new_param[:number] ||= old_param[:number]
|
28
|
+
if new_param[:last4]
|
29
|
+
new_param[:number] = new_param[:number][0..-5] + new_param[:last4]
|
30
|
+
else
|
31
|
+
new_param[:last4] = new_param[:number][-4..-1]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
old_param.merge(new_param)
|
35
|
+
end
|
36
|
+
|
26
37
|
end
|
27
38
|
end
|
data/lib/stripe_mock/version.rb
CHANGED
data/spec/list_spec.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe StripeMock::Data::List do
|
4
|
+
before :all do
|
5
|
+
StripeMock.start
|
6
|
+
end
|
7
|
+
|
8
|
+
after :all do
|
9
|
+
StripeMock.stop
|
10
|
+
end
|
11
|
+
|
12
|
+
it "contains data" do
|
13
|
+
obj = double
|
14
|
+
obj2 = double
|
15
|
+
obj3 = double
|
16
|
+
list = StripeMock::Data::List.new([obj, obj2, obj3])
|
17
|
+
|
18
|
+
expect(list.data).to eq([obj, obj2, obj3])
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can accept a single object" do
|
22
|
+
list = StripeMock::Data::List.new(double)
|
23
|
+
|
24
|
+
expect(list.data).to be_kind_of(Array)
|
25
|
+
expect(list.data.size).to eq(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "infers object type for url" do
|
29
|
+
customer = Stripe::Customer.create
|
30
|
+
list = StripeMock::Data::List.new([customer])
|
31
|
+
|
32
|
+
expect(list.url).to eq("/v1/customers")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "eventually gets turned into a hash" do
|
36
|
+
charge1 = Stripe::Charge.create
|
37
|
+
charge2 = Stripe::Charge.create
|
38
|
+
charge3 = Stripe::Charge.create
|
39
|
+
list = StripeMock::Data::List.new([charge1, charge2, charge3])
|
40
|
+
hash = list.to_h
|
41
|
+
|
42
|
+
expect(hash).to eq(
|
43
|
+
object: "list",
|
44
|
+
data: [charge1, charge2, charge3],
|
45
|
+
url: "/v1/charges",
|
46
|
+
has_more: false
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "delegates other methods to hash keys" do
|
51
|
+
list = StripeMock::Data::List.new([double, double, double])
|
52
|
+
|
53
|
+
expect(list).to respond_to(:data)
|
54
|
+
expect(list.data).to be_kind_of(Array)
|
55
|
+
expect(list.object).to eq("list")
|
56
|
+
expect(list.has_more).to eq(false)
|
57
|
+
expect(list.url).to eq("/v1/doubles")
|
58
|
+
expect { list.foobar }.to raise_error(NoMethodError)
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a limit" do
|
62
|
+
it "accepts a limit which is reflected in the data returned" do
|
63
|
+
list = StripeMock::Data::List.new([double] * 25)
|
64
|
+
|
65
|
+
expect(list.to_h[:data].size).to eq(10)
|
66
|
+
|
67
|
+
list = StripeMock::Data::List.new([double] * 25, limit: 15)
|
68
|
+
|
69
|
+
expect(list.limit).to eq(15)
|
70
|
+
expect(list.to_h[:data].size).to eq(15)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "defaults to a limit of 10" do
|
74
|
+
list = StripeMock::Data::List.new([])
|
75
|
+
|
76
|
+
expect(list.limit).to eq(10)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "won't accept a limit of > 100" do
|
80
|
+
list = StripeMock::Data::List.new([], limit: 105)
|
81
|
+
|
82
|
+
expect(list.limit).to eq(100)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "won't accept a limit of < 1" do
|
86
|
+
list = StripeMock::Data::List.new([], limit: 0)
|
87
|
+
|
88
|
+
expect(list.limit).to eq(1)
|
89
|
+
|
90
|
+
list = StripeMock::Data::List.new([], limit: -4)
|
91
|
+
|
92
|
+
expect(list.limit).to eq(1)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "pagination" do
|
97
|
+
it "has a has_more field when it has more" do
|
98
|
+
list = StripeMock::Data::List.new([Stripe::Charge.create] * 256)
|
99
|
+
|
100
|
+
expect(list).to have_more
|
101
|
+
end
|
102
|
+
|
103
|
+
it "accepts a starting_after parameter" do
|
104
|
+
data = []
|
105
|
+
255.times { data << Stripe::Charge.create }
|
106
|
+
new_charge = Stripe::Charge.create
|
107
|
+
data[89] = new_charge
|
108
|
+
list = StripeMock::Data::List.new(data, starting_after: new_charge.id)
|
109
|
+
hash = list.to_h
|
110
|
+
|
111
|
+
expect(hash[:data].size).to eq(10)
|
112
|
+
expect(hash[:data]).to eq(data[90, 10])
|
113
|
+
end
|
114
|
+
|
115
|
+
it "raises an error if starting_after cursor is not found" do
|
116
|
+
data = []
|
117
|
+
255.times { data << Stripe::Charge.create }
|
118
|
+
list = StripeMock::Data::List.new(data, starting_after: "test_ch_unknown")
|
119
|
+
|
120
|
+
expect { list.to_h }.to raise_error
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples 'Card API' do
|
4
|
+
|
4
5
|
it 'creates/returns a card when using customer.cards.create given a card token' do
|
5
6
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
6
|
-
card_token =
|
7
|
+
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
7
8
|
card = customer.cards.create(card: card_token)
|
8
9
|
|
9
10
|
expect(card.customer).to eq('test_customer_sub')
|
@@ -20,6 +21,25 @@ shared_examples 'Card API' do
|
|
20
21
|
expect(card.exp_year).to eq(2099)
|
21
22
|
end
|
22
23
|
|
24
|
+
it 'creates/returns a card when using recipient.cards.create given a card token' do
|
25
|
+
recipient = Stripe::Recipient.create(id: 'test_recipient_sub')
|
26
|
+
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
27
|
+
card = recipient.cards.create(card: card_token)
|
28
|
+
|
29
|
+
expect(card.recipient).to eq('test_recipient_sub')
|
30
|
+
expect(card.last4).to eq("1123")
|
31
|
+
expect(card.exp_month).to eq(11)
|
32
|
+
expect(card.exp_year).to eq(2099)
|
33
|
+
|
34
|
+
recipient = Stripe::Recipient.retrieve('test_recipient_sub')
|
35
|
+
expect(recipient.cards.count).to eq(1)
|
36
|
+
card = recipient.cards.data.first
|
37
|
+
expect(card.recipient).to eq('test_recipient_sub')
|
38
|
+
expect(card.last4).to eq("1123")
|
39
|
+
expect(card.exp_month).to eq(11)
|
40
|
+
expect(card.exp_year).to eq(2099)
|
41
|
+
end
|
42
|
+
|
23
43
|
it 'creates/returns a card when using customer.cards.create given card params' do
|
24
44
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
25
45
|
card = customer.cards.create(card: {
|
@@ -43,6 +63,28 @@ shared_examples 'Card API' do
|
|
43
63
|
expect(card.exp_year).to eq(3031)
|
44
64
|
end
|
45
65
|
|
66
|
+
it 'creates/returns a card when using recipient.cards.create given card params' do
|
67
|
+
recipient = Stripe::Recipient.create(id: 'test_recipient_sub')
|
68
|
+
card = recipient.cards.create(card: {
|
69
|
+
number: '4000056655665556',
|
70
|
+
exp_month: '11',
|
71
|
+
exp_year: '3031',
|
72
|
+
cvc: '123'
|
73
|
+
})
|
74
|
+
|
75
|
+
expect(card.recipient).to eq('test_recipient_sub')
|
76
|
+
expect(card.last4).to eq("5556")
|
77
|
+
expect(card.exp_month).to eq(11)
|
78
|
+
expect(card.exp_year).to eq(3031)
|
79
|
+
|
80
|
+
recipient = Stripe::Recipient.retrieve('test_recipient_sub')
|
81
|
+
expect(recipient.cards.count).to eq(1)
|
82
|
+
card = recipient.cards.data.first
|
83
|
+
expect(card.recipient).to eq('test_recipient_sub')
|
84
|
+
expect(card.last4).to eq("5556")
|
85
|
+
expect(card.exp_month).to eq(11)
|
86
|
+
expect(card.exp_year).to eq(3031)
|
87
|
+
end
|
46
88
|
|
47
89
|
it "creates a single card with a generated card token", :live => true do
|
48
90
|
customer = Stripe::Customer.create
|
@@ -59,7 +101,7 @@ shared_examples 'Card API' do
|
|
59
101
|
|
60
102
|
it 'create does not change the customers default card if already set' do
|
61
103
|
customer = Stripe::Customer.create(id: 'test_customer_sub', default_card: "test_cc_original")
|
62
|
-
card_token =
|
104
|
+
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
63
105
|
card = customer.cards.create(card: card_token)
|
64
106
|
|
65
107
|
customer = Stripe::Customer.retrieve('test_customer_sub')
|
@@ -68,16 +110,16 @@ shared_examples 'Card API' do
|
|
68
110
|
|
69
111
|
it 'create updates the customers default card if not set' do
|
70
112
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
71
|
-
card_token =
|
113
|
+
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
72
114
|
card = customer.cards.create(card: card_token)
|
73
115
|
|
74
116
|
customer = Stripe::Customer.retrieve('test_customer_sub')
|
75
117
|
expect(customer.default_card).to_not be_nil
|
76
118
|
end
|
77
119
|
|
78
|
-
|
120
|
+
describe "retrieval and deletion with customers" do
|
79
121
|
let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
|
80
|
-
let!(:card_token) {
|
122
|
+
let!(:card_token) { stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
81
123
|
let!(:card) { customer.cards.create(card: card_token) }
|
82
124
|
|
83
125
|
it "retrieves a customers card" do
|
@@ -109,7 +151,7 @@ shared_examples 'Card API' do
|
|
109
151
|
end
|
110
152
|
|
111
153
|
context "deletion when the user has two cards" do
|
112
|
-
let!(:card_token_2) {
|
154
|
+
let!(:card_token_2) { stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
113
155
|
let!(:card_2) { customer.cards.create(card: card_token_2) }
|
114
156
|
|
115
157
|
it "has just one card anymore" do
|
@@ -127,6 +169,42 @@ shared_examples 'Card API' do
|
|
127
169
|
end
|
128
170
|
end
|
129
171
|
|
172
|
+
describe "retrieval and deletion with recipients", :live => true do
|
173
|
+
let!(:recipient) { Stripe::Recipient.create(name: 'Test Recipient', type: 'individual') }
|
174
|
+
let!(:card_token) { stripe_helper.generate_card_token(number: "4000056655665556") }
|
175
|
+
let!(:card) { recipient.cards.create(card: card_token) }
|
176
|
+
|
177
|
+
it "deletes a recipient card" do
|
178
|
+
card.delete
|
179
|
+
retrieved_cus = Stripe::Recipient.retrieve(recipient.id)
|
180
|
+
expect(retrieved_cus.cards.data).to be_empty
|
181
|
+
end
|
182
|
+
|
183
|
+
it "deletes a recipient card then set the default_card to nil" do
|
184
|
+
card.delete
|
185
|
+
retrieved_cus = Stripe::Recipient.retrieve(recipient.id)
|
186
|
+
expect(retrieved_cus.default_card).to be_nil
|
187
|
+
end
|
188
|
+
|
189
|
+
context "deletion when the recipient has two cards" do
|
190
|
+
let!(:card_token_2) { stripe_helper.generate_card_token(number: "5200828282828210") }
|
191
|
+
let!(:card_2) { recipient.cards.create(card: card_token_2) }
|
192
|
+
|
193
|
+
it "has just one card anymore" do
|
194
|
+
card.delete
|
195
|
+
retrieved_rec = Stripe::Recipient.retrieve(recipient.id)
|
196
|
+
expect(retrieved_rec.cards.data.count).to eq 1
|
197
|
+
expect(retrieved_rec.cards.data.first.id).to eq card_2.id
|
198
|
+
end
|
199
|
+
|
200
|
+
it "sets the default_card id to the last card remaining id" do
|
201
|
+
card.delete
|
202
|
+
retrieved_rec = Stripe::Recipient.retrieve(recipient.id)
|
203
|
+
expect(retrieved_rec.default_card).to eq card_2.id
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
130
208
|
describe "Errors", :live => true do
|
131
209
|
it "throws an error when the customer does not have the retrieving card id" do
|
132
210
|
customer = Stripe::Customer.create
|
@@ -142,7 +220,7 @@ shared_examples 'Card API' do
|
|
142
220
|
|
143
221
|
context "update card" do
|
144
222
|
let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
|
145
|
-
let!(:card_token) {
|
223
|
+
let!(:card_token) { stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
146
224
|
let!(:card) { customer.cards.create(card: card_token) }
|
147
225
|
|
148
226
|
it "updates the card" do
|
@@ -165,9 +243,9 @@ shared_examples 'Card API' do
|
|
165
243
|
it "retrieves a list of multiple cards" do
|
166
244
|
customer = Stripe::Customer.create(id: 'test_customer_card')
|
167
245
|
|
168
|
-
card_token =
|
246
|
+
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
169
247
|
card1 = customer.cards.create(card: card_token)
|
170
|
-
card_token =
|
248
|
+
card_token = stripe_helper.generate_card_token(last4: "1124", exp_month: 12, exp_year: 2098)
|
171
249
|
card2 = customer.cards.create(card: card_token)
|
172
250
|
|
173
251
|
customer = Stripe::Customer.retrieve('test_customer_card')
|