stripe 1.18.0 → 1.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +11 -1
- data/History.txt +98 -0
- data/README.rdoc +19 -10
- data/VERSION +1 -1
- data/lib/stripe/account.rb +46 -4
- data/lib/stripe/api_operations/create.rb +3 -10
- data/lib/stripe/api_operations/delete.rb +4 -4
- data/lib/stripe/api_operations/list.rb +17 -9
- data/lib/stripe/api_operations/request.rb +41 -0
- data/lib/stripe/api_operations/update.rb +41 -40
- data/lib/stripe/api_resource.rb +7 -4
- data/lib/stripe/application_fee.rb +3 -4
- data/lib/stripe/application_fee_refund.rb +1 -1
- data/lib/stripe/balance_transaction.rb +1 -1
- data/lib/stripe/bank_account.rb +19 -0
- data/lib/stripe/bitcoin_receiver.rb +12 -2
- data/lib/stripe/bitcoin_transaction.rb +5 -0
- data/lib/stripe/card.rb +6 -4
- data/lib/stripe/charge.rb +14 -22
- data/lib/stripe/coupon.rb +2 -2
- data/lib/stripe/customer.rb +24 -26
- data/lib/stripe/dispute.rb +16 -0
- data/lib/stripe/errors/card_error.rb +3 -2
- data/lib/stripe/errors/invalid_request_error.rb +3 -2
- data/lib/stripe/errors/rate_limit_error.rb +4 -0
- data/lib/stripe/errors/stripe_error.rb +8 -2
- data/lib/stripe/event.rb +1 -1
- data/lib/stripe/file_upload.rb +12 -22
- data/lib/stripe/invoice.rb +8 -8
- data/lib/stripe/invoice_item.rb +2 -2
- data/lib/stripe/list_object.rb +77 -13
- data/lib/stripe/order.rb +19 -0
- data/lib/stripe/plan.rb +2 -2
- data/lib/stripe/product.rb +16 -0
- data/lib/stripe/recipient.rb +2 -2
- data/lib/stripe/refund.rb +2 -9
- data/lib/stripe/reversal.rb +14 -0
- data/lib/stripe/singleton_api_resource.rb +2 -2
- data/lib/stripe/sku.rb +8 -0
- data/lib/stripe/stripe_object.rb +232 -46
- data/lib/stripe/subscription.rb +3 -3
- data/lib/stripe/token.rb +1 -1
- data/lib/stripe/transfer.rb +3 -3
- data/lib/stripe/util.rb +64 -21
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +102 -67
- data/stripe.gemspec +0 -2
- data/test/stripe/account_test.rb +135 -6
- data/test/stripe/api_resource_test.rb +326 -42
- data/test/stripe/application_fee_refund_test.rb +6 -6
- data/test/stripe/application_fee_test.rb +3 -3
- data/test/stripe/balance_test.rb +11 -0
- data/test/stripe/bitcoin_receiver_test.rb +30 -7
- data/test/stripe/bitcoin_transaction_test.rb +29 -0
- data/test/stripe/charge_refund_test.rb +55 -0
- data/test/stripe/charge_test.rb +32 -13
- data/test/stripe/coupon_test.rb +3 -3
- data/test/stripe/customer_card_test.rb +20 -14
- data/test/stripe/customer_test.rb +15 -15
- data/test/stripe/dispute_test.rb +45 -0
- data/test/stripe/file_upload_test.rb +17 -6
- data/test/stripe/invoice_test.rb +18 -4
- data/test/stripe/list_object_test.rb +126 -2
- data/test/stripe/metadata_test.rb +28 -13
- data/test/stripe/order_test.rb +52 -0
- data/test/stripe/product_test.rb +41 -0
- data/test/stripe/recipient_card_test.rb +9 -9
- data/test/stripe/refund_test.rb +23 -15
- data/test/stripe/reversal_test.rb +47 -0
- data/test/stripe/sku_test.rb +24 -0
- data/test/stripe/stripe_object_test.rb +67 -6
- data/test/stripe/subscription_test.rb +13 -13
- data/test/stripe/transfer_test.rb +4 -4
- data/test/stripe/util_test.rb +45 -29
- data/test/stripe_test.rb +16 -0
- data/test/test_data.rb +273 -66
- metadata +47 -76
- data/lib/stripe/certificate_blacklist.rb +0 -55
- data/test/stripe/certificate_blacklist_test.rb +0 -18
@@ -2,8 +2,125 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class ListObjectTest < Test::Unit::TestCase
|
5
|
+
should "provide .empty_list" do
|
6
|
+
list = Stripe::ListObject.empty_list
|
7
|
+
assert list.empty?
|
8
|
+
end
|
9
|
+
|
10
|
+
should "provide #count via enumerable" do
|
11
|
+
list = Stripe::ListObject.construct_from(make_charge_array)
|
12
|
+
assert_equal 3, list.count
|
13
|
+
end
|
14
|
+
|
15
|
+
should "provide #each" do
|
16
|
+
arr = [
|
17
|
+
{ :id => 1 },
|
18
|
+
{ :id => 2 },
|
19
|
+
{ :id => 3 },
|
20
|
+
]
|
21
|
+
expected = Util.convert_to_stripe_object(arr, {})
|
22
|
+
list = Stripe::ListObject.construct_from({ :data => arr })
|
23
|
+
assert_equal expected, list.each.to_a
|
24
|
+
end
|
25
|
+
|
26
|
+
should "provide #auto_paging_each" do
|
27
|
+
arr = [
|
28
|
+
{ :id => 1 },
|
29
|
+
{ :id => 2 },
|
30
|
+
{ :id => 3 },
|
31
|
+
]
|
32
|
+
expected = Util.convert_to_stripe_object(arr, {})
|
33
|
+
|
34
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
35
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
36
|
+
returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
37
|
+
|
38
|
+
assert_equal expected, list.auto_paging_each.to_a
|
39
|
+
end
|
40
|
+
|
41
|
+
should "provide #auto_paging_each that responds to a block" do
|
42
|
+
arr = [
|
43
|
+
{ :id => 1 },
|
44
|
+
{ :id => 2 },
|
45
|
+
{ :id => 3 },
|
46
|
+
]
|
47
|
+
expected = Util.convert_to_stripe_object(arr, {})
|
48
|
+
|
49
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
50
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
51
|
+
returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
52
|
+
|
53
|
+
actual = []
|
54
|
+
list.auto_paging_each do |obj|
|
55
|
+
actual << obj
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_equal expected, actual
|
59
|
+
end
|
60
|
+
|
61
|
+
should "provide #empty?" do
|
62
|
+
list = Stripe::ListObject.construct_from({ :data => [] })
|
63
|
+
assert list.empty?
|
64
|
+
list = Stripe::ListObject.construct_from({ :data => [{}] })
|
65
|
+
refute list.empty?
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# next_page
|
70
|
+
#
|
71
|
+
|
72
|
+
should "fetch a next page through #next_page" do
|
73
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
74
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
75
|
+
returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
76
|
+
next_list = list.next_page
|
77
|
+
refute next_list.empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
should "fetch a next page through #next_page and respect limit" do
|
81
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
82
|
+
list.limit = 3
|
83
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?limit=3&starting_after=1", nil, nil).
|
84
|
+
returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
85
|
+
next_list = list.next_page
|
86
|
+
assert_equal 3, next_list.limit
|
87
|
+
end
|
88
|
+
|
89
|
+
should "fetch an empty page through #next_page" do
|
90
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => false })
|
91
|
+
next_list = list.next_page
|
92
|
+
assert_equal Stripe::ListObject.empty_list, next_list
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# previous_page
|
97
|
+
#
|
98
|
+
|
99
|
+
should "fetch a next page through #previous_page" do
|
100
|
+
list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
|
101
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2", nil, nil).
|
102
|
+
returns(make_response({ :data => [{ :id => 1 }] }))
|
103
|
+
next_list = list.previous_page
|
104
|
+
refute next_list.empty?
|
105
|
+
end
|
106
|
+
|
107
|
+
should "fetch a next page through #previous_page and respect limit" do
|
108
|
+
list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
|
109
|
+
list.limit = 3
|
110
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2&limit=3", nil, nil).
|
111
|
+
returns(make_response({ :data => [{ :id => 1 }] }))
|
112
|
+
next_list = list.previous_page
|
113
|
+
assert_equal 3, next_list.limit
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# backward compatibility
|
118
|
+
#
|
119
|
+
|
120
|
+
# note that the name #all is deprecated, as is using it fetch the next page
|
121
|
+
# in a list
|
5
122
|
should "be able to retrieve full lists given a listobject" do
|
6
|
-
@mock.expects(:get).twice.returns(
|
123
|
+
@mock.expects(:get).twice.returns(make_response(make_charge_array))
|
7
124
|
c = Stripe::Charge.all
|
8
125
|
assert c.kind_of?(Stripe::ListObject)
|
9
126
|
assert_equal('/v1/charges', c.url)
|
@@ -13,4 +130,11 @@ module Stripe
|
|
13
130
|
assert all.data.kind_of?(Array)
|
14
131
|
end
|
15
132
|
end
|
16
|
-
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# A helper class with a URL that allows us to try out pagination.
|
136
|
+
class TestListObject < Stripe::ListObject
|
137
|
+
def url
|
138
|
+
"/things"
|
139
|
+
end
|
140
|
+
end
|
@@ -6,24 +6,39 @@ module Stripe
|
|
6
6
|
@metadata_supported = {
|
7
7
|
:charge => {
|
8
8
|
:new => Stripe::Charge.method(:new),
|
9
|
-
:test => method(:
|
10
|
-
:url => "/v1/charges/#{
|
9
|
+
:test => method(:make_charge),
|
10
|
+
:url => "/v1/charges/#{make_charge()[:id]}"
|
11
11
|
},
|
12
12
|
:customer => {
|
13
13
|
:new => Stripe::Customer.method(:new),
|
14
|
-
:test => method(:
|
15
|
-
:url => "/v1/customers/#{
|
14
|
+
:test => method(:make_customer),
|
15
|
+
:url => "/v1/customers/#{make_customer()[:id]}"
|
16
16
|
},
|
17
17
|
:recipient => {
|
18
18
|
:new => Stripe::Recipient.method(:new),
|
19
|
-
:test => method(:
|
20
|
-
:url => "/v1/recipients/#{
|
19
|
+
:test => method(:make_recipient),
|
20
|
+
:url => "/v1/recipients/#{make_recipient()[:id]}"
|
21
21
|
},
|
22
22
|
:transfer => {
|
23
23
|
:new => Stripe::Transfer.method(:new),
|
24
|
-
:test => method(:
|
25
|
-
:url => "/v1/transfers/#{
|
26
|
-
}
|
24
|
+
:test => method(:make_transfer),
|
25
|
+
:url => "/v1/transfers/#{make_transfer()[:id]}"
|
26
|
+
},
|
27
|
+
:product => {
|
28
|
+
:new => Stripe::Product.method(:new),
|
29
|
+
:test => method(:make_product),
|
30
|
+
:url => "/v1/products/#{make_product()[:id]}"
|
31
|
+
},
|
32
|
+
:order => {
|
33
|
+
:new => Stripe::Order.method(:new),
|
34
|
+
:test => method(:make_order),
|
35
|
+
:url => "/v1/orders/#{make_order()[:id]}"
|
36
|
+
},
|
37
|
+
:sku => {
|
38
|
+
:new => Stripe::SKU.method(:new),
|
39
|
+
:test => method(:make_sku),
|
40
|
+
:url => "/v1/skus/#{make_sku()[:id]}"
|
41
|
+
},
|
27
42
|
}
|
28
43
|
|
29
44
|
@base_url = 'https://api.stripe.com'
|
@@ -45,7 +60,7 @@ module Stripe
|
|
45
60
|
|
46
61
|
if is_greater_than_ruby_1_9?
|
47
62
|
check_metadata({:metadata => {:initial => 'true'}},
|
48
|
-
'metadata[
|
63
|
+
'metadata[initial]=&metadata[uuid]=6735',
|
49
64
|
update_actions)
|
50
65
|
end
|
51
66
|
end
|
@@ -78,7 +93,7 @@ module Stripe
|
|
78
93
|
obj.metadata['uuid'] = '6735'
|
79
94
|
end
|
80
95
|
params = {:metadata => {'type' => 'summer', 'uuid' => '6735'}}
|
81
|
-
curl_args = Stripe.
|
96
|
+
curl_args = Stripe::Util.encode_parameters(params)
|
82
97
|
check_metadata({:metadata => {'type' => 'christmas'}},
|
83
98
|
curl_args,
|
84
99
|
update_actions)
|
@@ -92,11 +107,11 @@ module Stripe
|
|
92
107
|
url = @base_url + methods[:url]
|
93
108
|
|
94
109
|
initial_test_obj = test.call(initial_params)
|
95
|
-
@mock.expects(:get).once.returns(
|
110
|
+
@mock.expects(:get).once.returns(make_response(initial_test_obj))
|
96
111
|
|
97
112
|
final_test_obj = test.call()
|
98
113
|
@mock.expects(:post).once.
|
99
|
-
returns(
|
114
|
+
returns(make_response(final_test_obj)).
|
100
115
|
with(url, nil, curl_args)
|
101
116
|
|
102
117
|
obj = neu.call("test")
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class OrderTest < Test::Unit::TestCase
|
5
|
+
should "orders should be listable" do
|
6
|
+
@mock.expects(:get).once.returns(make_response(make_order_array))
|
7
|
+
orders = Stripe::Order.list
|
8
|
+
assert orders.data.kind_of?(Array)
|
9
|
+
orders.each do |order|
|
10
|
+
assert order.kind_of?(Stripe::Order)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
should "orders should not be deletable" do
|
15
|
+
assert_raises NoMethodError do
|
16
|
+
@mock.expects(:get).once.returns(make_response(make_order))
|
17
|
+
p = Stripe::Order.retrieve("test_order")
|
18
|
+
p.delete
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "orders should be updateable" do
|
23
|
+
@mock.expects(:get).once.returns(make_response(make_order))
|
24
|
+
@mock.expects(:post).once.returns(make_response(make_order))
|
25
|
+
p = Stripe::Order.new("test_order")
|
26
|
+
p.refresh
|
27
|
+
p.status = "fulfilled"
|
28
|
+
p.save
|
29
|
+
end
|
30
|
+
|
31
|
+
should "orders should allow metadata updates" do
|
32
|
+
@mock.expects(:get).once.returns(make_response(make_order))
|
33
|
+
@mock.expects(:post).once.returns(make_response(make_order))
|
34
|
+
p = Stripe::Order.new("test_order")
|
35
|
+
p.refresh
|
36
|
+
p.metadata['key'] = 'value'
|
37
|
+
p.save
|
38
|
+
end
|
39
|
+
|
40
|
+
should "pay should pay an order" do
|
41
|
+
@mock.expects(:get).once.
|
42
|
+
returns(make_response(make_order(:id => 'or_test_order')))
|
43
|
+
order = Stripe::Order.retrieve('or_test_order')
|
44
|
+
|
45
|
+
@mock.expects(:post).once.
|
46
|
+
with('https://api.stripe.com/v1/orders/or_test_order/pay', nil, 'token=test_token').
|
47
|
+
returns(make_response(make_paid_order))
|
48
|
+
order.pay(:token => 'test_token')
|
49
|
+
assert_equal "paid", order.status
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class ProductTest < Test::Unit::TestCase
|
5
|
+
should "products should be listable" do
|
6
|
+
@mock.expects(:get).once.returns(make_response(make_product_array))
|
7
|
+
products = Stripe::Product.list
|
8
|
+
assert products.data.kind_of?(Array)
|
9
|
+
products.each do |product|
|
10
|
+
assert product.kind_of?(Stripe::Product)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
should "products should not be deletable" do
|
15
|
+
assert_raises NoMethodError do
|
16
|
+
@mock.expects(:get).once.returns(make_response(make_product))
|
17
|
+
p = Stripe::Product.retrieve("test_product")
|
18
|
+
p.delete
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "products should be updateable" do
|
23
|
+
@mock.expects(:get).once.returns(make_response(make_product))
|
24
|
+
@mock.expects(:post).once.returns(make_response(make_product))
|
25
|
+
p = Stripe::Product.new("test_product")
|
26
|
+
p.refresh
|
27
|
+
p.description = "New product description"
|
28
|
+
p.save
|
29
|
+
end
|
30
|
+
|
31
|
+
should "products should allow metadata updates" do
|
32
|
+
@mock.expects(:get).once.returns(make_response(make_product))
|
33
|
+
@mock.expects(:post).once.returns(make_response(make_product))
|
34
|
+
p = Stripe::Product.new("test_product")
|
35
|
+
p.refresh
|
36
|
+
p.metadata['key'] = 'value'
|
37
|
+
p.save
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -5,21 +5,21 @@ module Stripe
|
|
5
5
|
RECIPIENT_CARD_URL = '/v1/recipients/test_recipient/cards/test_card'
|
6
6
|
|
7
7
|
def recipient
|
8
|
-
@mock.expects(:get).once.returns(
|
8
|
+
@mock.expects(:get).once.returns(make_response(make_recipient))
|
9
9
|
Stripe::Recipient.retrieve('test_recipient')
|
10
10
|
end
|
11
11
|
|
12
12
|
should "recipient cards should be listable" do
|
13
13
|
c = recipient
|
14
|
-
@mock.expects(:get).once.returns(
|
15
|
-
cards = c.cards.
|
14
|
+
@mock.expects(:get).once.returns(make_response(make_recipient_card_array(recipient.id)))
|
15
|
+
cards = c.cards.list.data
|
16
16
|
assert cards.kind_of? Array
|
17
17
|
assert cards[0].kind_of? Stripe::Card
|
18
18
|
end
|
19
19
|
|
20
20
|
should "recipient cards should have the correct url" do
|
21
21
|
c = recipient
|
22
|
-
@mock.expects(:get).once.returns(
|
22
|
+
@mock.expects(:get).once.returns(make_response(make_card(
|
23
23
|
:id => 'test_card',
|
24
24
|
:recipient => 'test_recipient'
|
25
25
|
)))
|
@@ -29,8 +29,8 @@ module Stripe
|
|
29
29
|
|
30
30
|
should "recipient cards should be deletable" do
|
31
31
|
c = recipient
|
32
|
-
@mock.expects(:get).once.returns(
|
33
|
-
@mock.expects(:delete).once.returns(
|
32
|
+
@mock.expects(:get).once.returns(make_response(make_card))
|
33
|
+
@mock.expects(:delete).once.returns(make_response(make_card(:deleted => true)))
|
34
34
|
card = c.cards.retrieve('card')
|
35
35
|
card.delete
|
36
36
|
assert card.deleted
|
@@ -38,8 +38,8 @@ module Stripe
|
|
38
38
|
|
39
39
|
should "recipient cards should be updateable" do
|
40
40
|
c = recipient
|
41
|
-
@mock.expects(:get).once.returns(
|
42
|
-
@mock.expects(:post).once.returns(
|
41
|
+
@mock.expects(:get).once.returns(make_response(make_card(:exp_year => "2000")))
|
42
|
+
@mock.expects(:post).once.returns(make_response(make_card(:exp_year => "2100")))
|
43
43
|
card = c.cards.retrieve('card')
|
44
44
|
assert_equal "2000", card.exp_year
|
45
45
|
card.exp_year = "2100"
|
@@ -49,7 +49,7 @@ module Stripe
|
|
49
49
|
|
50
50
|
should "create should return a new recipient card" do
|
51
51
|
c = recipient
|
52
|
-
@mock.expects(:post).once.returns(
|
52
|
+
@mock.expects(:post).once.returns(make_response(make_card(:id => "test_card")))
|
53
53
|
card = c.cards.create(:card => "tok_41YJ05ijAaWaFS")
|
54
54
|
assert_equal "test_card", card.id
|
55
55
|
end
|
data/test/stripe/refund_test.rb
CHANGED
@@ -3,44 +3,52 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
3
3
|
module Stripe
|
4
4
|
class RefundTest < Test::Unit::TestCase
|
5
5
|
should "refunds should be listable" do
|
6
|
-
@mock.expects(:get).
|
6
|
+
@mock.expects(:get).
|
7
|
+
with("#{Stripe.api_base}/v1/refunds", nil, nil).
|
8
|
+
once.returns(make_response(make_refund_array))
|
7
9
|
|
8
|
-
|
10
|
+
refunds = Stripe::Refund.list
|
9
11
|
|
10
|
-
assert
|
12
|
+
assert refunds.first.kind_of?(Stripe::Refund)
|
11
13
|
end
|
12
14
|
|
13
15
|
should "refunds should be refreshable" do
|
14
|
-
@mock.expects(:get).
|
16
|
+
@mock.expects(:get).
|
17
|
+
with("#{Stripe.api_base}/v1/refunds/test_refund", nil, nil).
|
18
|
+
twice.returns(make_response(make_refund(:id => 'test_refund')),
|
19
|
+
make_response(make_refund(:id => 'refreshed_refund')))
|
15
20
|
|
16
|
-
|
17
|
-
refund = charge.refunds.first
|
21
|
+
refund = Stripe::Refund.retrieve('test_refund')
|
18
22
|
refund.refresh
|
19
23
|
|
20
24
|
assert_equal 'refreshed_refund', refund.id
|
21
25
|
end
|
22
26
|
|
23
27
|
should "refunds should be updateable" do
|
24
|
-
@mock.expects(:get).
|
25
|
-
|
28
|
+
@mock.expects(:get).
|
29
|
+
with("#{Stripe.api_base}/v1/refunds/get_refund", nil, nil).
|
30
|
+
once.returns(make_response(make_refund(:id => 'save_refund')))
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
@mock.expects(:post).
|
33
|
+
with("#{Stripe.api_base}/v1/refunds/save_refund", nil, 'metadata[key]=value').
|
34
|
+
once.returns(make_response(make_refund(:metadata => {'key' => 'value'})))
|
35
|
+
|
36
|
+
refund = Stripe::Refund.retrieve('get_refund')
|
29
37
|
|
30
38
|
assert_equal nil, refund.metadata['key']
|
31
39
|
|
32
|
-
refund.metadata['key'] = '
|
40
|
+
refund.metadata['key'] = 'value'
|
33
41
|
refund.save
|
34
42
|
|
35
43
|
assert_equal 'value', refund.metadata['key']
|
36
44
|
end
|
37
45
|
|
38
46
|
should "create should return a new refund" do
|
39
|
-
@mock.expects(:
|
40
|
-
|
47
|
+
@mock.expects(:post).
|
48
|
+
with("#{Stripe.api_base}/v1/refunds", nil, 'charge=test_charge').
|
49
|
+
once.returns(make_response(make_refund(:id => 'test_new_refund')))
|
41
50
|
|
42
|
-
|
43
|
-
refund = charge.refunds.create(:amount => 20)
|
51
|
+
refund = Stripe::Refund.create(:charge => 'test_charge')
|
44
52
|
assert_equal 'test_new_refund', refund.id
|
45
53
|
end
|
46
54
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class ReversalTest < Test::Unit::TestCase
|
5
|
+
should "reversals should be listable" do
|
6
|
+
@mock.expects(:get).once.returns(make_response(make_transfer))
|
7
|
+
|
8
|
+
transfer = Stripe::Transfer.retrieve('test_transfer')
|
9
|
+
|
10
|
+
assert transfer.reversals.first.kind_of?(Stripe::Reversal)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "reversals should be refreshable" do
|
14
|
+
@mock.expects(:get).twice.returns(make_response(make_transfer), make_response(make_reversal(:id => 'refreshed_reversal')))
|
15
|
+
|
16
|
+
transfer = Stripe::Transfer.retrieve('test_transfer')
|
17
|
+
reversal = transfer.reversals.first
|
18
|
+
reversal.refresh
|
19
|
+
|
20
|
+
assert_equal 'refreshed_reversal', reversal.id
|
21
|
+
end
|
22
|
+
|
23
|
+
should "reversals should be updateable" do
|
24
|
+
@mock.expects(:get).once.returns(make_response(make_transfer))
|
25
|
+
@mock.expects(:post).once.returns(make_response(make_reversal(:metadata => {'key' => 'value'})))
|
26
|
+
|
27
|
+
transfer = Stripe::Transfer.retrieve('test_transfer')
|
28
|
+
reversal = transfer.reversals.first
|
29
|
+
|
30
|
+
assert_equal nil, reversal.metadata['key']
|
31
|
+
|
32
|
+
reversal.metadata['key'] = 'value'
|
33
|
+
reversal.save
|
34
|
+
|
35
|
+
assert_equal 'value', reversal.metadata['key']
|
36
|
+
end
|
37
|
+
|
38
|
+
should "create should return a new reversal" do
|
39
|
+
@mock.expects(:get).once.returns(make_response(make_transfer))
|
40
|
+
@mock.expects(:post).once.returns(make_response(make_reversal(:id => 'test_new_reversal')))
|
41
|
+
|
42
|
+
transfer = Stripe::Transfer.retrieve('test_transfer')
|
43
|
+
reversals = transfer.reversals.create(:amount => 20)
|
44
|
+
assert_equal 'test_new_reversal', reversals.id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class SKUTest < Test::Unit::TestCase
|
5
|
+
should "SKUs should be listable" do
|
6
|
+
@mock.expects(:get).once.
|
7
|
+
returns(make_response(make_sku_array("test_product")))
|
8
|
+
skus = Stripe::SKU.list
|
9
|
+
assert skus.data.kind_of? Array
|
10
|
+
skus.each do |sku|
|
11
|
+
assert sku.kind_of?(Stripe::SKU)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
should "SKUs should not be deletable" do
|
16
|
+
assert_raises NoMethodError do
|
17
|
+
@mock.expects(:get).once.returns(make_response(make_sku))
|
18
|
+
p = Stripe::SKU.retrieve("test_product")
|
19
|
+
p.delete
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -2,26 +2,87 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class StripeObjectTest < Test::Unit::TestCase
|
5
|
-
should "implement
|
5
|
+
should "implement #==" do
|
6
|
+
obj1 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "bar" })
|
7
|
+
obj2 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "bar" })
|
8
|
+
obj3 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "rab" })
|
9
|
+
|
10
|
+
assert obj1 == obj2
|
11
|
+
refute obj1 == obj3
|
12
|
+
end
|
13
|
+
|
14
|
+
should "implement #deleted?" do
|
15
|
+
obj = Stripe::StripeObject.construct_from({})
|
16
|
+
refute obj.deleted?
|
17
|
+
|
18
|
+
obj = Stripe::StripeObject.construct_from({ :deleted => false })
|
19
|
+
refute obj.deleted?
|
20
|
+
|
21
|
+
obj = Stripe::StripeObject.construct_from({ :deleted => true })
|
22
|
+
assert obj.deleted?
|
23
|
+
end
|
24
|
+
|
25
|
+
should "implement #respond_to" do
|
6
26
|
obj = Stripe::StripeObject.construct_from({ :id => 1, :foo => 'bar' })
|
7
27
|
assert obj.respond_to?(:id)
|
8
28
|
assert obj.respond_to?(:foo)
|
9
29
|
assert !obj.respond_to?(:baz)
|
10
30
|
end
|
11
31
|
|
32
|
+
should "marshal be insensitive to strings vs. symbols when constructin" do
|
33
|
+
obj = Stripe::StripeObject.construct_from({ :id => 1, 'name' => 'Stripe' })
|
34
|
+
assert_equal 1, obj[:id]
|
35
|
+
assert_equal 'Stripe', obj[:name]
|
36
|
+
end
|
37
|
+
|
12
38
|
should "marshal a stripe object correctly" do
|
13
|
-
obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' }, 'apikey')
|
39
|
+
obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' }, {:api_key => 'apikey'})
|
14
40
|
m = Marshal.load(Marshal.dump(obj))
|
15
41
|
assert_equal 1, m.id
|
16
42
|
assert_equal 'Stripe', m.name
|
17
|
-
|
43
|
+
expected_hash = {:api_key => 'apikey'}
|
44
|
+
assert_equal expected_hash, m.instance_variable_get('@opts')
|
18
45
|
end
|
19
46
|
|
20
47
|
should "recursively call to_hash on its values" do
|
21
|
-
|
22
|
-
|
23
|
-
|
48
|
+
nested_hash = { :id => 7, :foo => 'bar' }
|
49
|
+
nested = Stripe::StripeObject.construct_from(nested_hash)
|
50
|
+
obj = Stripe::StripeObject.construct_from({ :id => 1, :nested => nested, :list => [nested] })
|
51
|
+
expected_hash = { :id => 1, :nested => nested_hash, :list => [nested_hash] }
|
24
52
|
assert_equal expected_hash, obj.to_hash
|
25
53
|
end
|
54
|
+
|
55
|
+
should "assign question mark accessors for booleans" do
|
56
|
+
obj = Stripe::StripeObject.construct_from({ :id => 1, :bool => true, :not_bool => 'bar' })
|
57
|
+
assert obj.respond_to?(:bool?)
|
58
|
+
assert obj.bool?
|
59
|
+
refute obj.respond_to?(:not_bool?)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "mass assign values with #update_attributes" do
|
63
|
+
obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' })
|
64
|
+
obj.update_attributes(:name => 'STRIPE')
|
65
|
+
assert_equal "STRIPE", obj.name
|
66
|
+
|
67
|
+
# unfortunately, we even assign unknown properties to duplicate the
|
68
|
+
# behavior that we currently have via magic accessors with
|
69
|
+
# method_missing
|
70
|
+
obj.update_attributes(:unknown => 'foo')
|
71
|
+
assert_equal "foo", obj.unknown
|
72
|
+
end
|
73
|
+
|
74
|
+
should "warn that #refresh_from is deprecated" do
|
75
|
+
old_stderr = $stderr
|
76
|
+
$stderr = StringIO.new
|
77
|
+
begin
|
78
|
+
obj = Stripe::StripeObject.construct_from({})
|
79
|
+
obj.refresh_from({}, {})
|
80
|
+
message = "NOTE: Stripe::StripeObject#refresh_from is " +
|
81
|
+
"deprecated; use #update_attributes instead"
|
82
|
+
assert_match Regexp.new(message), $stderr.string
|
83
|
+
ensure
|
84
|
+
$stderr = old_stderr
|
85
|
+
end
|
86
|
+
end
|
26
87
|
end
|
27
88
|
end
|